File and Image Inputs

A guide to sending PDFs and images via Base64 or URLs in API requests.

Overview

FastRouter allows you to pass images and PDFs as part of your messages, following the OpenAI-compatible API format. This unlocks powerful use cases such as document Q&A, image captioning, and multimodal chat—across supported providers and models.


Supported File Types

  • PDFs: Base64-encoded

  • Images: Base64-encoded or URLs (jpg, png, etc.)


Supported Models

  • PDFs: Select models that support "File" as an input modality from the FastRouter model catalog (e.g., models like openai/gpt-4.1-nano for document analysis).

  • Images: Select models that support "Image" as an input modality from the FastRouter model catalog (e.g., multimodal models like x-ai/grok-4 for vision tasks).


Sending PDFs as Input

You can attach PDFs as file inputs in your messages array, either by encoding the file in base64 or by providing a direct web URL.

Example: Sending a PDF using Base64 Encoding

Use this for local files. Example filename: "example.pdf".

Notes

  • The file_data field is a Data URL: data:application/pdf;base64,{base64_pdf}.

  • You can ask a question about the document in the "text" part.

  • FastRouter will handle the document upload transparently.


Sending Image Inputs

You may send images as part of your chat for multimodal models. Images are passed as entries of type "image_url", either as web URLs or as base64-encoded data URLs.

Example: Sending an Image via URL

Example image URL used.

Python Code Snippet:

Example: Sending a Base64-Encoded Image

Use this for local images. Example filename: "image.jpg".

Python Code Snippet:


Tips & Best Practices

  • Order Content: Always send your text prompt first, followed by file/image content, for best results.

  • Multiple Files/Images: You can include more than one file/image by adding additional entries to the content array.

  • Provider/Model Support: The number and type of file/image inputs may vary by provider/model. See the FastRouter model documentation for specifics.

  • Large Image Files: For efficiency, always use direct URLs for large images when possible.

Last updated