Skip to main content

Base64 Image

All AIGEN image-based APIs accept images as Base64-encoded strings in the request body. The Base64 string must contain only the encoded data — without the data: URI prefix.

Supported Formats

FormatExtensionsNotes
JPEG.jpg, .jpegMost common, recommended
PNG.pngSupports transparency
PDF.pdfMulti-page supported on select endpoints

Removing the Data URI Prefix

When converting an image to Base64 (e.g., from a file input in a browser), the result often includes a prefix like data:image/jpeg;base64,. You must remove this prefix before sending to the API.

// Browser file input
const file = document.querySelector("input[type=file]").files[0];
const reader = new FileReader();

reader.onload = () => {
// Remove the "data:image/...;base64," prefix
const base64 = reader.result.split(",")[1];
console.log(base64); // Ready to send to API
};

reader.readAsDataURL(file);

Image Size Guidelines

  • Minimum resolution: 112 x 112 pixels (varies by endpoint)
  • Maximum file size: Varies by endpoint
  • Best practice: Use images between 300 DPI and 600 DPI for optimal OCR accuracy
tip

For higher accuracy, ensure the document fills most of the image frame and is well-lit without glare or shadows.

Dev Tool

Use AIGEN's online tool to quickly encode/decode Base64 images:

AIGEN Dev Tool - Base64 Encoder/Decoder