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
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | The UTF-8 string to encode. |
Response
| Field | Type | Description |
|---|---|---|
output | string | The 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).
| Code | When | Delivered as |
|---|---|---|
invalid_arguments | The input field is missing or not a string. | protocol error (invalid_params) |
internal_error | An 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, usebase64_encode_url_safeto avoid the need for percent-encoding.