AnyInt Docs
Models

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.

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:

  1. Set messages[].content to an array, not a plain string.
  2. Put instructions in a { "type": "text" } block.
  3. Put each image in a { "type": "image_url" } block.
  4. 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

FieldRequiredMeaningExample
modelYesImage-capable model ID. Fetch it from the Models API.gemini-3.1-flash-image-preview
messages[].roleYesMessage role. Image input usually belongs in a user message.user
messages[].content[]YesOrdered content blocks containing text and images.[{"type":"text",...},{"type":"image_url",...}]
content[].typeYesContent block type. Use text for instructions and image_url for images.image_url
content[].textFor text blocksInstruction text.Describe this image.
content[].image_url.urlFor image blocksPublic 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.png

Do not send a local file path:

/tmp/reference.png
C:\Users\you\image.png

Upstream 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[].content as 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-compatible messages[].content[] in the same request.
  • Sending bare base64 without the data:image/...;base64, prefix in the OpenAI-compatible image_url.url field.

On this page