Vision
Send images (URL or base64) or files such as PDFs in messages so the model can describe, recognize or analyze them, with both the Chat Completions and the Responses format.
Models that can see images accept them in messages: write messages[].content as an array of content parts, with text and images as separate parts. An image can be a URL that's publicly reachable, or a base64-encoded data URL. The endpoint is still Chat Completions. For PDF files, see PDF files; for the Responses format, see In the Responses API.
Whether a model can see images depends on the model itself: check the model's description in Model Square first, and if you're not sure, send one real request with a small image to confirm. The models you can use also depend on your key's group.
POST https://codaapi.com/v1/chat/completions
Request headers
| Name | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer sk-…, your API key |
Content-Type |
Yes | application/json |
Request body
The table lists only the fields for sending images. For the other parameters, see Chat Completions.
| Parameter | Type | Required | Description |
|---|---|---|---|
messages[].content |
array | Yes | Array of content parts; it can hold several pieces of text and several images |
messages[].content[].type |
string | Yes | text or image_url; use file for a PDF, see PDF files |
messages[].content[].text |
string | No | The text, when type is text |
messages[].content[].image_url.url |
string | No | The image, when type is image_url: an https://… address, or a data URL like data:image/jpeg;base64,… |
messages[].content[].image_url.detail |
string | No | Image detail: auto (default), low or high; only models that support it use it |
Common formats such as PNG, JPEG and WEBP work. The supported formats and the size limit per image are set by the upstream.
When you send an image by URL, it must be directly downloadable from the internet. OpenAI and similar upstreams download the address themselves; for Claude and Gemini, the gateway downloads it and converts it to base64 before sending it upstream. Addresses that need a login, block hotlinking or are reachable only on an internal network fail; use base64 for those.
Request examples
curl (image URL)
curl https://codaapi.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4-mini",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]
}]
}'
Replace https://example.com/photo.jpg with the address of your own publicly reachable image.
Python (local image as base64, pip install openai)
import base64
from openai import OpenAI
client = OpenAI() # reads OPENAI_BASE_URL and OPENAI_API_KEY
with open("photo.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="gpt-5.4-mini",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}},
],
}],
)
print(response.choices[0].message.content)
The type in the data URL must match the image; for PNG, write data:image/png;base64,….
Node.js (local image as base64, npm install openai)
import fs from 'node:fs';
import OpenAI from 'openai';
const client = new OpenAI(); // reads OPENAI_BASE_URL and OPENAI_API_KEY
const imageB64 = fs.readFileSync('photo.jpg').toString('base64');
const completion = await client.chat.completions.create({
model: 'gpt-5.4-mini',
messages: [{
role: 'user',
content: [
{ type: 'text', text: 'What is in this image?' },
{ type: 'image_url', image_url: { url: `data:image/jpeg;base64,${imageB64}` } },
],
}],
});
console.log(completion.choices[0].message.content);
One message can hold several images; just list them in order, for example to ask the model to compare two pictures.
Response
The response format is the same as Chat Completions. The model's description of the image is in choices[0].message.content, and the tokens the images are counted as are included in usage.prompt_tokens. Streaming works too; see Streaming responses.
PDF files
Chat Completions accepts PDFs too: put a content part whose type is file in the content array, with the file name in file.filename and a data URL like data:application/pdf;base64,… in file.file_data, followed by text saying what to do. The request body:
{
"model": "gpt-5.5",
"messages": [{
"role": "user",
"content": [
{
"type": "file",
"file": {"filename": "report.pdf", "file_data": "data:application/pdf;base64,JVBERi0xLjcK…"}
},
{"type": "text", "text": "What is the first conclusion in this document?"}
]
}]
}
Python (local PDF as base64, pip install openai)
import base64
from openai import OpenAI
client = OpenAI() # reads OPENAI_BASE_URL and OPENAI_API_KEY
with open("report.pdf", "rb") as f:
pdf_b64 = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{
"role": "user",
"content": [
{"type": "file", "file": {"filename": "report.pdf", "file_data": f"data:application/pdf;base64,{pdf_b64}"}},
{"type": "text", "text": "What is the first conclusion in this document?"},
],
}],
)
print(response.choices[0].message.content)
Whether a model can read PDFs depends on the model, too. When you call Claude or Gemini models through Chat Completions, the gateway converts this content part to a Claude document block or Gemini inlineData. A PDF is counted as input tokens page by page, so more pages cost more.
In the Responses API
The Responses endpoint uses the input_text and input_image content parts, and image_url is a plain string (a URL or a data URL):
curl https://codaapi.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"input": [{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{"type": "input_image", "image_url": "https://example.com/photo.jpg"}
]
}]
}'
File analysis
The Responses endpoint takes files in an input_file content part. Put the file's address in file_url; it must be directly downloadable from the internet. Instead of an address, you can also send filename together with file_data (a base64 data URL). Besides PDFs, common formats such as Word, Excel, PowerPoint, plain text, Markdown, CSV and code files work as well; the supported formats are set by the upstream.
curl https://codaapi.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": [{
"role": "user",
"content": [
{"type": "input_file", "file_url": "https://example.com/report.pdf"},
{"type": "input_text", "text": "What does this document say?"}
]
}]
}'
For the response format, see Responses: the answer is in the item of output whose type is message, and the tokens the file is counted as are included in usage.input_tokens.
Errors
Errors come back with a 4xx or 5xx status code and an OpenAI-style error body, {"error": {"message": "…", "type": "…", "code": "…"}}, where message ends with the ID of the request (the request id). An image address that can't be downloaded, or an unsupported format, is reported the same way. For common status codes and what to do about them, see Error codes.
Billing
Images are billed as input tokens. How an image converts to tokens depends on the model; generally, larger images and a higher detail use more tokens. For each model's price, see Model Square and the price list; for the rules, see Pricing and multipliers.