Documentation
Images & PDFs
How to send images and PDFs to A4F API Services.
A4F API Services primarily focuses on providing affordable and unified access to a wide range of text-based Large Language Models. While some underlying providers offer multimodal capabilities (like image understanding), direct support for rich media inputs such as images and PDFs through the standard A4F API /v1/chat/completions
endpoint is currently limited and depends heavily on the chosen provider and model.
Context is Key
Image Inputs
Requests with images to multimodal models are typically sent via the standard A4F /v1/chat/completions
API, using a multi-part messages
parameter as per OpenAI's specification. The image content can be either a URL or a base64-encoded image.
Limited Provider Support for Direct Image Input
messages
array.- - Provider-5 might offer some vision capabilities for specific models (check model list).
- - Provider-4 may occasionally support images for certain models.
Note that multiple images can be sent in separate content array entries. The number of images you can send in a single request varies per provider and per model. Due to how the content is parsed, we recommend sending the text prompt first, then the images. If the images must come first, we recommend putting it in the system prompt.
Using Image URLs
Here's how to send an image using a URL:
Using Base64 Encoded Images
For locally stored images, you can send them using base64 encoding. Here's how to do it:
Supported image content types (ensure your base64 data URL matches):
image/png
image/jpeg
image/webp
image/gif
(non-animated)
PDF Support
No Direct PDF Upload/Processing via Standard API
/v1/chat/completions
API in the way some specialized platforms (like OpenRouter's example with file
content type or plugins
) might offer.Our focus is on providing cost-effective access to text generation models. Handling arbitrary file types like PDFs directly within API requests significantly increases backend complexity and operational costs, which is not aligned with A4F's current service model and pricing for text-based interactions.
Recommendation: To work with PDF content, your application should first extract the text from the PDF using a library or service of your choice (e.g., PyMuPDF/fitz, pdfminer.six in Python, or an external OCR service for image-based PDFs). Then, send this extracted text to A4F as part of your prompt.
Processing Extracted PDF Text
If you have extracted text from a PDF, you can send it to A4F as part of your prompt. Here's a conceptual example:
Note that multiple PDF text segments (e.g., page by page, or chunked content) can be sent in separate messages or combined, depending on token limits and your prompting strategy.
Response Format
The API will return a response in the following format (OpenAI compatible):
Was this page helpful?