LLM Image Input API: Screenshots and Scans
Send screenshots, photos and scans to a chat model with one LLM image input API: URL vs base64 data URL, per-model image limits, the 400 error and token costs.
By OceanToken Team

Editor's note: Sending one image to a chat model is a five-line change. The bugs show up later: an agent that has piled up forty screenshots hits a per-request image limit and starts failing with
400, or someone swaps in a text-only model and the images are simply not read. We would design for those two cases on day one, because both come from the conversation, not the code.
Want to run the examples in this article? Get API Key and call every model below with one key.
Short answer: With an LLM image input API, the message content becomes a list: a text part plus one image_url part per image, each a public https URL or a base64 data URL. Use PNG, JPEG or WebP, keep requests under about 10 MB, check the model lists image input, and drop old images before the per-request limit returns 400.
We use OceanToken for the examples because one OpenAI-compatible key reaches vision-capable chat models from OpenAI, Anthropic, Google, Qwen, Z.ai and MiniMax, so the same request works across them by changing the model string. Every fact here comes from our docs, public model catalog and model pages, read November 29, 2026. We have not run your images through these models, so the end of the article has a test you can run. Rates are on /pricing and each model's page.
01 · How the LLM image input API request is shaped
The change from a text request is one field. content stops being a string and becomes a list of parts, in the order the model should read them: text parts and image_url parts. Our vision guide says the image is either a public https:// URL, which the model fetches, or the file itself as a data URL such as data:image/png;base64,....
That order matters more than it looks. If you are asking about two receipts, put a short text label before each image ("Receipt A:", "Receipt B:") so the model can refer to them by name. If the question is about one image, put the question first and the image after; the docs sample does exactly that.
Several images go in the same message as several image_url parts. There is no separate "images" field on chat requests, which is a common confusion for people coming from image generation, where reference images do have their own list. To generate or edit pictures rather than read them, that is a different endpoint; see our image generation API guide in Python.

02 · Send an image to an LLM API in Python
To send an image to an LLM API in Python, use the OpenAI SDK with the base URL changed and pass a list of parts as content. This is the URL version, for images already hosted somewhere public:
# pip install openai
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.oceantoken.ai/v1",
api_key=os.environ["OCEANTOKEN_API_KEY"])
resp = client.chat.completions.create(
model="google/gemini-3.8-flash",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What error message is shown in this screenshot?"},
{"type": "image_url", "image_url": {"url": "https://example.com/screenshot.png"}},
],
}],
)
print(resp.choices[0].message.content)
print("prompt tokens:", resp.usage.prompt_tokens)
Printing usage.prompt_tokens from the first request is a habit worth having. Images are billed as input tokens, and the count depends on the model and the image size, so this number is your only reliable view of what an image costs on a given model.
The URL must be reachable by the model without a login. A presigned link from your storage bucket works as long as it has not lapsed by the time the request runs; an image behind your app's session cookie does not. For anything private, use a data URL, covered next.
03 · image_url with a data URL or base64
An image_url part accepts a base64 data URL in the same url field, so local files and private images need no hosting. Read the bytes, base64-encode them, and prefix the MIME type:
import base64, mimetypes
def to_data_url(path):
mime = mimetypes.guess_type(path)[0] or "image/png"
if mime not in ("image/png", "image/jpeg", "image/webp"):
raise ValueError(f"convert {path} to PNG, JPEG or WebP first")
with open(path, "rb") as f:
return f"data:{mime};base64," + base64.b64encode(f.read()).decode()
resp = client.chat.completions.create(
model="qwen/qwen3.8-flash",
messages=[{"role": "user", "content": [
{"type": "text", "text": "What is the total on this receipt?"},
{"type": "image_url", "image_url": {"url": to_data_url("receipt.jpg")}},
]}],
)
The trade-off is size. Our docs say base64 makes a file about a third larger, and suggest keeping the whole request under 10 MB where you can. A phone photo at full resolution can be several megabytes before encoding, and a conversation with a few of them in history grows quickly. Two fixes: send large images as URLs instead, or resize before encoding. For reading a receipt or a screenshot, a long edge of a couple of thousand pixels is usually more than the text needs, though the right size for your documents is something to test (see the checklist).
The format check in to_data_url is there because our docs name PNG, JPEG and WebP as the safe formats. HEIC photos from phones and multi-page TIFF scans are the usual surprises; convert them first rather than finding out from an error.
| Method | Best for | Watch out for |
|---|---|---|
Public https:// URL |
Large images, images already in a public bucket or CDN | The model must reach it without a login; links that lapse |
Data URL (data:image/...;base64,) |
Local files, private images, screenshots from an agent | About a third larger than the file; request size |
Anthropic image block, source.type: "url" |
Codebases on the Anthropic SDK | Same reachability rules as a URL |
Anthropic image block, source.type: "base64" |
Anthropic SDK with local files | Needs media_type and the raw base64, no data: prefix |
04 · Which models read images
A model without image input cannot read images at all, so check before you send. Model pages on Models show an Input row in the spec block, and our public catalog carries a supports_vision flag. Here is what both showed for eight models on November 29, 2026:
| Model id | Publisher | Input on model page | supports_vision (catalog) |
|---|---|---|---|
openai/gpt-6-luna |
OpenAI | file, image, text | true |
anthropic/claude-sonnet-5.5 |
Anthropic | text, image, file | true |
google/gemini-3.8-flash |
text, image, video, file, audio | true | |
qwen/qwen3.8-flash |
Qwen | text, image, video | true |
z-ai/glm-5.3-flash |
Z.ai | text, image, video | true |
minimax/minimax-m3 |
MiniMax | text, image, video | true |
z-ai/glm-5.3 |
Z.ai | text | false |
deepseek/deepseek-v4-pro |
DeepSeek | text | false |
The GLM pair is the one to remember. z-ai/glm-5.3-flash reads images and z-ai/glm-5.3 does not, even though the names suggest the larger one would do more. A config change from one to the other silently removes vision from your app. For a model-specific walkthrough, see our GLM-5.3-Flash image input tutorial or the Qwen vision guide.
We do not rank the six vision models here. The table says which ones accept images; how well each reads your particular screenshots, charts or handwriting is what the test plan below measures.
05 · Too many images in a conversation: the 400 error
If a request fails with 400 invalid_request after a long conversation, the most likely cause is the per-request image limit. Our docs say every model has a maximum number of images per request, and it counts the images in every earlier turn of the conversation, not just the new message. Past it, the request is refused and the error message gives the limit.
This is the failure that catches agents. A browser or desktop agent that sends a screenshot after every action keeps all of them in history by default. Turn one works, turn ten works, and somewhere later every request starts failing, with no change in your code. Because the limit differs by model and our docs do not list each number, the safe design is to keep the count low no matter which model you use.
Our docs' advice is to drop older images, such as an agent's old screenshots. A sliding window does that:
KEEP_LAST = 3 # tune per model; read the limit from the 400 message if you hit it
def trim_images(messages, keep_last=KEEP_LAST):
seen = 0
for msg in reversed(messages):
if not isinstance(msg.get("content"), list):
continue
parts = []
for part in reversed(msg["content"]):
if part.get("type") == "image_url":
seen += 1
if seen > keep_last:
parts.append({"type": "text", "text": "[earlier screenshot removed]"})
continue
parts.append(part)
msg["content"] = list(reversed(parts))
return messages
Replacing a dropped image with a short text marker, rather than deleting it outright, keeps the conversation readable for the model: it knows something was there. If a screenshot carried information the agent still needs, have the model write that down in text when it first sees the image; text is cheaper to carry forward than pixels anyway.
06 · Image input with the Anthropic Messages API
On /v1/messages, an image is a block in the Anthropic shape, and our docs say that works for every chat model with image input, not only Claude:
{"type": "image", "source": {"type": "url", "url": "https://example.com/chart.png"}}
or, for the file itself, "source": {"type": "base64", "media_type": "image/png", "data": "..."}. Note that the base64 form takes the raw base64 string and a separate media_type, while the OpenAI form takes a full data: URL. Mixing them up is a common source of 400 errors when people port code between SDKs.
Which shape should you use? Whichever your codebase already speaks. If you have an agent built on the Anthropic SDK, keep it and change the base URL; if you are on the OpenAI SDK, keep that. The per-request image limit and the input-token billing apply the same way to both.
07 · What images cost
Images are billed as input tokens. Our docs say how many tokens an image counts as depends on the model and the image's size, and that the request's usage.prompt_tokens and its line in Logs show what it was. There is no single conversion we can give you that holds across models, and we would be suspicious of any article that offers one.
What you can control: image size, and how many images ride along in history. Resizing a large photo before sending and trimming old screenshots both reduce input tokens on every later turn, since earlier images are resent with each request. Rates per token differ by model; see /pricing and the pages for Qwen3.8 Flash and Gemini 3.8 Flash.
If your app mixes chat, image generation and video in one product, our guide to a unified API for chat, image and video apps shows how those pieces share one key and one balance.
08 · A pre-flight check before every vision request
Most of the problems above can be caught before a request leaves your server, which is cheaper than catching them from a 400 or a confused answer. We would put three checks in one small function that every vision call goes through.
First, confirm the configured model accepts images. Keep a short allowlist built from the model pages or the catalog's supports_vision flag, and refuse to send image parts to anything else; a clear error in your logs beats a model that answers without having seen the picture. Second, count images across the whole message history, not just the new turn, and trim to your window before sending. Third, check the size of the encoded request and switch large files to URLs when it gets close to the 10 MB guideline.
None of this depends on which publisher's model you use, which is the point. When you change the model string, the checks still hold, and the only thing to update is the allowlist and, if you learned it from an error message, that model's image limit.
How to test this on your workload
We have not measured how these models read your images, so this is the test we would run before choosing one:
- Pick five real images from your product: a screenshot with small text, a photo, a chart, a scanned page and one with handwriting.
- Write one specific question per image with a known right answer.
- Send each to at least three vision models from the table, once as a URL and once as a data URL.
- Record
usage.prompt_tokensfor each request, so you see how image tokens differ by model. - Record whether each answer is right, not just plausible.
- Resize the screenshot to half its size and repeat; note when small text stops being read.
- Build a conversation with growing image count on one model until it returns
400, and save the limit from the error message. - Send one image to
z-ai/glm-5.3and see what a text-only model does with it.
Our take: Check image input before you configure a model, send URLs when you can and data URLs when you must, and cap screenshots in agent history at a small number from the start. Those three choices prevent most vision bugs we would expect to see in production.
Running it on OceanToken
From our docs and model pages, as of November 29, 2026:
- One key for vision models from six publishers. The six image-capable models above take the same
image_urlparts onhttps://api.oceantoken.ai/v1/chat/completions; switching is a change ofmodel. - Both SDK shapes. OpenAI-style
image_urlparts on/v1/chat/completions, and Anthropic image blocks on/v1/messages, for every chat model with image input. - Costs you can see.
usage.prompt_tokensand Logs show what each image counted as.
Price: see the current rate on /pricing, each model's page, and the series pages /qwen-api and /gemini-api.
FAQ
How do I send an image to a chat model API? Make content a list with a text part and an image_url part whose url is a public https URL or a base64 data URL.
Should I use a URL or base64? Use a URL for large or already-hosted images; use a data URL for local or private files. Base64 adds about a third to the size.
Why do I get 400 invalid_request after many turns? The per-request image limit counts images from every earlier turn. Drop old images; the error message gives the limit.
Which image formats are safe? PNG, JPEG and WebP. Convert HEIC or TIFF first.
How are images billed? As input tokens; the count depends on the model and image size. Check usage.prompt_tokens and Logs.
Sources
- OceanToken docs: Image input (vision) (checked 2026-11-29)
- OceanToken public model catalog (checked 2026-11-29)
- GLM 5.3 Flash model page (checked 2026-11-29)
- GLM 5.3 model page (checked 2026-11-29)
- MiniMax M3 model page (checked 2026-11-29)
Get your OceanToken API key
- Create an OceanToken account and an API key.
- Copy the snippet below, paste your key, and run it.
- Check the current rate on /qwen-api.
curl https://api.oceantoken.ai/v1/chat/completions \
-H "Authorization: Bearer $OCEANTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen/qwen3.8-flash", "messages": [{"role": "user", "content": [{"type": "text", "text": "What error message is shown in this screenshot?"}, {"type": "image_url", "image_url": {"url": "https://example.com/screenshot.png"}}]}]}'
More from the blog
Veo 3.1 Reference Images API Guide
How to send reference images to Veo 3.1 through the API: input_references vs first frame, which tiers take them, two-shot Python script and a consistency test.
LLM Function Calling API Across Models
Write one LLM function calling API loop that works across GPT, Claude, Gemini, Qwen, GLM and DeepSeek: tool_choice, streaming and the silent no-call trap.
AI Voiceover API for Generated Video
Add narration to AI video with an AI voiceover API: write the script with a chat model, voice it with a speech model, and merge it onto a silent Seedance clip.