POSTEncode
Turn text or bytes into Base64. Standard or URL-safe alphabet, with or without padding, optionally wrapped.
POST
https://api.base64hub.com/v1/encodeRequest
Send JSON with the text in input. The text is encoded as UTF-8.
curl -s https://api.base64hub.com/v1/encode \
-H 'Content-Type: application/json' \
-d '{"input": "Hello, hub!"}'
const res = await fetch("https://api.base64hub.com/v1/encode", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input: "Hello, hub!" }),
});
const { output } = await res.json();
console.log(output); // SGVsbG8sIGh1YiE=
import json
import urllib.request
req = urllib.request.Request(
"https://api.base64hub.com/v1/encode",
data=json.dumps({"input": "Hello, hub!"}).encode(),
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(req) as res:
print(json.load(res)["output"]) # SGVsbG8sIGh1YiE=
b64 "Hello, hub!"
# SGVsbG8sIGh1YiE=
Body parameters
| Name | Type | Description |
|---|---|---|
input required | string | Text to encode. It is converted to UTF-8 bytes first. |
variant optional | "standard" or "url" | Alphabet. url uses - and _ instead of + and /. Default "standard". |
padding optional | boolean | Keep the trailing =. Default true. |
wrap optional | integer, 0 to 1000 | Insert \n after every N output characters, none at the end. 76 is MIME. Default 0, no wrapping. |
Any other field is rejected with 400 invalid_body.
Raw bytes
To encode a file or any binary data, send the bytes as application/octet-stream. Options then go in the query string: variant=url, padding=false, wrap=76.
printf '\xfb\xff\xbf' | curl -s \
'https://api.base64hub.com/v1/encode?variant=url&padding=false' \
-H 'Content-Type: application/octet-stream' \
--data-binary @-
const bytes = new Uint8Array([0xfb, 0xff, 0xbf]);
const res = await fetch(
"https://api.base64hub.com/v1/encode?variant=url&padding=false",
{ method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: bytes },
);
console.log((await res.json()).output); // -_-_
import json
import urllib.request
req = urllib.request.Request(
"https://api.base64hub.com/v1/encode?variant=url&padding=false",
data=b"\xfb\xff\xbf",
headers={"Content-Type": "application/octet-stream"},
)
with urllib.request.urlopen(req) as res:
print(json.load(res)["output"]) # -_-_
printf '\xfb\xff\xbf' | b64 --url --no-pad
# -_-_
The body limit is 1 MB. For bigger files use the CLI, which streams.
Response
200 OK · application/json
{
"output": "SGVsbG8sIGh1YiE=",
"variant": "standard",
"padding": true,
"bytes_in": 11,
"bytes_out": 16
}
| Field | Type | Description |
|---|---|---|
output | string | The Base64 text. |
variant | string | The alphabet used, standard or url. |
padding | boolean | Whether = padding was kept. |
bytes_in | integer | Number of input bytes after UTF-8 conversion. |
bytes_out | integer | Length of output, line breaks included. |
With {"input": "foobar", "wrap": 4} the output is "Zm9v\nYmFy" and bytes_out is 9: eight Base64 characters and one line break. The response above is formatted for reading; the API sends it on one line.
Errors
| Status | Code | Cause |
|---|---|---|
| 400 | invalid_body | Not valid JSON, input missing or not a string, a bad variant, padding or wrap, an unknown field or query parameter, or query options sent with a JSON body. |
| 413 | too_large | The body is over 1 MB. |
| 415 | unsupported_media_type | Content-Type is not application/json or application/octet-stream. |
| 429 | none | Rate limit reached; see limits. |
The API overview lists every error.
Updated Nov 22, 2026