Skip to main content

base64_encode

Encode a UTF-8 string to Base64 using the standard alphabet (RFC 4648 §4). The standard alphabet uses + and /. Output always includes = padding to make the length a multiple of 4.

For output safe to use in URLs or filenames, use base64_encode_url_safe instead.

Parameters​

ParameterTypeRequiredDescription
inputstringYesThe UTF-8 string to encode.

Response​

FieldTypeDescription
outputstringThe Base64-encoded string.

Examples​

Encode a plain ASCII string​

{
"input": "hello world"
}

Result:

{
"output": "aGVsbG8gd29ybGQ="
}

Encode a string that produces + and / in the output​

Input bytes ~>? include values whose 6-bit groups cross the + (62) and / (63) boundaries of the standard alphabet. Use base64_encode_url_safe if the output will appear in a URL or filename:

{
"input": "~>?"
}

Result:

{
"output": "fj4/"
}

Errors​

Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).

CodeWhenDelivered as
invalid_argumentsThe input field is missing or not a string.protocol error (invalid_params)
internal_errorAn unexpected server error.protocol error (internal_error)

Notes​

  • The input must be valid UTF-8. Binary data cannot be encoded directly.
  • Output always includes = padding — the output length is always a multiple of 4 characters.
  • The standard alphabet uses + and /. If the encoded output will be placed in a URL or filename, use base64_encode_url_safe to avoid the need for percent-encoding.