Guides
Vision
Some models read images as well as text. Send the image inline in base64, or as a URL, in any of the three API formats.
Which models take images
A model that reads images has image in architecture.input_modalities in GET /v1/models. Models marks them too. The others read text only, so send images to one that takes them.
Send an image
Put the image in the message as a base64 data URL (data:image/png;base64,...), next to the text that asks about it.
import base64
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.libremodel.ai/v1", api_key=os.environ["LIBREMODEL_API_KEY"])
with open("receipt.png", "rb") as f:
image = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="deepseek-v4.1-flash-1017",
messages=[{"role": "user", "content": [
{"type": "text", "text": "What is the total on this receipt?"},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}},
]}],
)
print(response.choices[0].message.content)import base64
import os
from anthropic import Anthropic
client = Anthropic(base_url="https://api.libremodel.ai", api_key=os.environ["LIBREMODEL_API_KEY"])
with open("receipt.png", "rb") as f:
image = base64.b64encode(f.read()).decode()
message = client.messages.create(
model="deepseek-v4.1-flash-1017",
max_tokens=1024,
messages=[{"role": "user", "content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image}},
{"type": "text", "text": "What is the total on this receipt?"},
]}],
)
print(message.content[0].text)Each format has its own part for it:
| Format | Image part |
|---|---|
| Chat Completions | {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}} |
| Responses | {"type": "input_image", "image_url": "data:image/png;base64,..."} |
| Anthropic Messages | {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}} |
Cost and limits
- Formats: PNG, JPEG, GIF and WebP. Other formats (HEIC, HEIF, AVIF, SVG…) return
400 invalid_request. - Each image can be up to 5 MB, in base64 or by URL. A larger one returns
400 invalid_request. - An image URL (
httporhttps) works too: it is downloaded and sent like base64. Up to 5 URLs per request, 5 MB each; one that can't be downloaded returns400 invalid_request. - Images count as input tokens, at the model's input price, plus the model's price per image (
pricing.image), every time an image is sent. What each request cost comes inusage.cost. - A whole request, images included, can be up to 40 MB. Past that it returns
413 request_too_large. - Up to 50 images per request, counting the ones that come out of files. Past that, it returns
400 invalid_request. - PDFs, Word, Excel, PowerPoint and other documents go as files: see Files.
- Check what a model reads off an image before you rely on it: it can misread small text and numbers.