Image Input
How to send text and reference images in the same AnyInt request. The recommended default is the OpenAI-compatible image_url content block.
This page shows how to send images as model input. The common case is: you have one or more reference images and want the model to answer a question, describe the image, extract information, or use the image as context for a later task.
Recommended default
If you just need to attach an image to a request, start with the OpenAI-compatible chat route:
POST https://api.anyint.ai/openai/v1/chat/completions
Use this request shape:
- Set
messages[].contentto an array, not a plain string. - Put instructions in a
{ "type": "text" }block. - Put each image in a
{ "type": "image_url" }block. - Use a public HTTPS image URL, or a
data:image/...;base64,...data URL when you need to send local image bytes inline.
The selected model must support image input. Fetch model IDs from the Models API instead of hard-coding an example.
OpenAI-compatible example
This request sends one reference image and one text instruction in the same user message:
curl https://api.anyint.ai/openai/v1/chat/completions \
-H "Authorization: Bearer $ANYINT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Use this reference image and describe the product style in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://your-domain.com/reference.png"
}
}
]
}
]
}'The important part is messages[0].content:
[
{
"type": "text",
"text": "Use this reference image and describe the product style in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://your-domain.com/reference.png"
}
}
]Multiple reference images
To send multiple images, append more image_url blocks. The order of the blocks is the order the model sees.
[
{
"type": "text",
"text": "Compare the packaging differences between these two images."
},
{
"type": "image_url",
"image_url": {
"url": "https://your-domain.com/before.png"
}
},
{
"type": "image_url",
"image_url": {
"url": "https://your-domain.com/after.png"
}
}
]Fields
| Field | Required | Meaning | Example |
|---|---|---|---|
model | Yes | Image-capable model ID. Fetch it from the Models API. | gemini-3.1-flash-image-preview |
messages[].role | Yes | Message role. Image input usually belongs in a user message. | user |
messages[].content[] | Yes | Ordered content blocks containing text and images. | [{"type":"text",...},{"type":"image_url",...}] |
content[].type | Yes | Content block type. Use text for instructions and image_url for images. | image_url |
content[].text | For text blocks | Instruction text. | Describe this image. |
content[].image_url.url | For image blocks | Public HTTPS image URL or data URL. Public HTTPS URLs are best for production; data URLs are useful when the image starts as a local file. | https://your-domain.com/reference.png |
Image URL requirements
Use a public HTTPS URL that returns image bytes directly, for example:
https://your-domain.com/reference.pngDo not send a local file path:
/tmp/reference.png
C:\Users\you\image.pngUpstream models cannot read files from your local disk. Upload the image to object storage, a CDN, or another public location first.
If you want to send local image bytes without first uploading the image, encode the file as base64 and use a data URL. A PNG data URL looks like:
data:image/png;base64,<BASE64_IMAGE_DATA>For example:
IMAGE_DATA="$(base64 -i ./reference.png | tr -d '\n')"
curl https://api.anyint.ai/openai/v1/chat/completions \
-H "Authorization: Bearer $ANYINT_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"gemini-3.1-flash-image-preview\",
\"messages\": [
{
\"role\": \"user\",
\"content\": [
{
\"type\": \"text\",
\"text\": \"Use this reference image and describe the product style in one sentence.\"
},
{
\"type\": \"image_url\",
\"image_url\": {
\"url\": \"data:image/png;base64,$IMAGE_DATA\"
}
}
]
}
]
}"Use this format when the image starts as a local file and you do not want to upload it first. Keep payload size in mind: base64 increases the request body size, and very large images are usually easier to operate through object storage or a CDN.
Gemini-native inlineData
If your application already uses Gemini-native request bodies, the /gemini/v1beta route also accepts inline image bytes through contents[].parts[].inlineData:
IMAGE_DATA="$(base64 -i ./reference.png | tr -d '\n')"
curl https://api.anyint.ai/gemini/v1beta/models/gemini-3.1-flash-image-preview:generateContent \
-H "Authorization: Bearer $ANYINT_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"contents\": [
{
\"role\": \"user\",
\"parts\": [
{
\"text\": \"Use this reference image and describe the product style in one sentence.\"
},
{
\"inlineData\": {
\"mimeType\": \"image/png\",
\"data\": \"$IMAGE_DATA\"
}
}
]
}
]
}"Use this only when you want Gemini-native contents[].parts[] payloads. For one gateway-wide default, prefer the OpenAI-compatible image_url form above.
Anthropic-compatible format
If your application already uses Anthropic Messages API, use:
POST https://api.anyint.ai/anthropic/v1/messages
Anthropic-style image blocks use type: "image" and put image bytes in source.data; they do not use image_url:
curl https://api.anyint.ai/anthropic/v1/messages \
-H "x-api-key: $ANYINT_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 512,
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": "<BASE64_IMAGE_DATA>"
}
},
{
"type": "text",
"text": "Describe what is in this image."
}
]
}
]
}'If you do not need Anthropic-compatible request bodies, prefer the OpenAI-compatible image_url format above.
Image input vs image generation
Image input means the model can look at an image. Whether the response is text, an image, or mixed content depends on the selected model and route.
If your goal is to generate or edit images, see:
For customer-facing image input, the documented default is OpenAI-compatible chat with messages[].content[] and image_url. Gemini-native inlineData is also documented on the Gemini Compatible API page for integrations that intentionally use Gemini-native contents[].parts[] payloads.
Common mistakes
- Keeping
messages[].contentas a string, so there is nowhere to attach the image. - Sending a local file path in JSON instead of a public URL or data URL.
- Using an image URL that requires login, cookies, hotlink approval, or does not return image bytes directly.
- Choosing a model that does not support image input.
- Mixing Gemini-native
contents[].parts[]with OpenAI-compatiblemessages[].content[]in the same request. - Sending bare base64 without the
data:image/...;base64,prefix in the OpenAI-compatibleimage_url.urlfield.
Related pages
Overview
Choose the right AnyInt route family for image understanding, image generation, video generation, and music workflows.
Image Generation
AnyInt publishes Gemini-native, DashScope, and Transtreams Kling image-generation paths. They overlap in outcome, but the request bodies and strengths are different.