POSTValidate
Check whether a string is Base64 before you use it. The answer includes the alphabet, the padding and the decoded size, or the reason it is not valid.
POST
https://api.base64hub.com/v1/validateRequest
The input is the same as for Decode: JSON with input, or the Base64 as a text/plain body.
curl -s https://api.base64hub.com/v1/validate \
-H 'Content-Type: text/plain' \
-d '-_-_'
const res = await fetch("https://api.base64hub.com/v1/validate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input: "-_-_" }),
});
const v = await res.json();
console.log(v.valid, v.variant, v.bytes); // true url 3
import json
import urllib.request
req = urllib.request.Request(
"https://api.base64hub.com/v1/validate",
data=json.dumps({"input": "-_-_"}).encode(),
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(req) as res:
v = json.load(res)
print(v["valid"], v["variant"], v["bytes"]) # True url 3
b64 --validate -- -_-_
# valid (url, 3 bytes)
Body parameters
| Name | Type | Description |
|---|---|---|
input required | string | The text to check. |
Response
Validate always answers 200 for a well-formed request. Valid input:
200 OK · application/json
{
"valid": true,
"variant": "url",
"padded": true,
"bytes": 3
}
Invalid input, here Zm9vY:
200 OK · application/json
{
"valid": false,
"error": {
"code": "invalid_base64",
"message": "invalid length: 5 characters leave a single character in the last group"
}
}
| Field | Type | Description |
|---|---|---|
valid | boolean | true exactly when Decode would succeed. |
variant | string | standard if + or / occurs, url if - or _ occurs, mixed if both, either if neither. |
padded | boolean | Whether the cleaned input, = included, is a multiple of 4 characters long. |
bytes | integer | Size of the decoded data. |
error | object | Only when valid is false: code is invalid_base64, message describes the problem and its position. |
either is common: SGVsbG8sIGh1YiE= contains none of the four special characters, so it is valid in both alphabets. padded: false does not make input invalid; SGVsbG8sIGh1YiE is valid with padded: false and 11 bytes.
Errors
Errors with a non-200 status are about the request, not the Base64:
| Status | Code | Cause |
|---|---|---|
| 400 | invalid_body | Not valid JSON, input missing or not a string, an unknown field, a query parameter, or a body that is not UTF-8. |
| 413 | too_large | The body is over 1 MB. |
| 415 | unsupported_media_type | Content-Type is not application/json or text/plain. |
| 429 | none | Rate limit reached; see limits. |
Updated Nov 22, 2026