Image input (vision)
Send images to vision models on BigModel.io as URLs or base64 data in Chat Completions and Messages requests, and fix errors from text-only models.
On this page
Vision models accept images next to text in the same message. On BigModel.io you send images in the format of the endpoint you call; the gateway converts between formats when a group uses a different protocol upstream.
| Endpoint | Image content part |
|---|---|
/v1/chat/completions |
{"type": "image_url", "image_url": {"url": "https://..." }} or a data:image/...;base64,... URL |
/v1/messages |
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "..."}} |
/v1/responses |
{"type": "input_image", "image_url": "..."} |
Only models that accept image input can read images. On a model's page in the catalog, look for image among its inputs or a Vision tag. Availability depends on your key's group.
#Send an image with Chat Completions
Use a public URL:
curl https://bigmodel.io/v1/chat/completions \
-H "Authorization: Bearer $BIGMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_VISION_MODEL_ID",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"}}
]
}]
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://bigmodel.io/v1", api_key=os.environ["BIGMODEL_API_KEY"])
completion = client.chat.completions.create(
model="YOUR_VISION_MODEL_ID",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"}},
],
}],
)
print(completion.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://bigmodel.io/v1", apiKey: process.env.BIGMODEL_API_KEY });
const completion = await client.chat.completions.create({
model: "YOUR_VISION_MODEL_ID",
messages: [{
role: "user",
content: [
{ type: "text", text: "What is in this picture?" },
{ type: "image_url", image_url: { url: "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg" } },
],
}],
});
console.log(completion.choices[0].message.content);Replace YOUR_VISION_MODEL_ID with a model ID from the catalog that lists image input.
#Local files as base64
The model provider fetches image URLs itself, so a URL on your laptop or private network will not work. Send local files as a data URL instead:
import base64
with open("photo.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode()
image_part = {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}}import { readFileSync } from "node:fs";
const b64 = readFileSync("photo.png").toString("base64");
const imagePart = { type: "image_url", image_url: { url: `data:image/png;base64,${b64}` } };#Send an image with the Messages API
On groups that serve /v1/messages, use Anthropic's image block:
import base64, os
from anthropic import Anthropic
client = Anthropic(base_url="https://bigmodel.io", api_key=os.environ["BIGMODEL_API_KEY"])
b64 = base64.b64encode(open("photo.png", "rb").read()).decode()
message = client.messages.create(
model="YOUR_VISION_MODEL_ID",
max_tokens=512,
messages=[{
"role": "user",
"content": [
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": b64}},
{"type": "text", "text": "What is in this picture?"},
],
}],
)
print(message.content[0].text)#How images are forwarded
- GLM and DeepSeek groups. The request body goes to the provider unchanged, so
image_urlparts (and options such asdetail) work exactly as far as the model supports them. - Converted groups. Chat
image_urlparts, Responsesinput_imageparts and Anthropic base64 image blocks are converted into each other, so you can use the format of the endpoint you call.
Image input is counted by the upstream provider, and the counts appear in the request's token usage in Usage, which is what you are billed for. Limits on image size and count are the provider's; if a request exceeds them, the provider's error is returned.
#Verify the setup
Run the cURL example with a vision model. The reply should describe the image (a cat). If the reply says it cannot see images, or you get a 400, the model is text-only.
#Troubleshooting
400 from the provider, or a reply saying it cannot see the image. The model does not accept image input. Pick a model whose page lists image input.
The provider cannot download the image. The URL is private, needs a login, or blocks bots. Send the file as a base64 data URL.
413 Request body too large. The request is over the gateway's body limit. Resize or compress images before encoding; base64 adds about a third to the file size. Providers also have their own, usually smaller, limits.
404 on /v1/messages. The key's group serves Chat Completions only. Use the image_url format on /v1/chat/completions.
503 api_error "No available accounts". The model ID is wrong or not served to your key's group. See Model IDs.
#Related
- Video generation for creating videos from text and images.
- Chat Completions API reference and Messages API reference.
- Model catalog to find vision models.
Updated · View as Markdown