Guides

Vision

Claude, GPT and Gemini models can read images: describe what's in them, extract text, and analyze charts and UI screenshots. Put the image and your text in the same user message.

Two ways to send an image

  • Image URL: a publicly reachable https:// address.
  • Base64: encode a local image and put it in the request. Good for private images.

OpenAI-compatible format

from openai import OpenAI

client = OpenAI(api_key="sk-...", base_url="https://api.flyrouter.ai/v1")

resp = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
        ],
    }],
)
print(resp.choices[0].message.content)

Anthropic native format

vision_claude.py
import base64
from anthropic import Anthropic

client = Anthropic(api_key="sk-...", base_url="https://api.flyrouter.ai")

with open("chart.png", "rb") as f:
    data = base64.b64encode(f.read()).decode()

msg = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=2048,
    messages=[{
        "role": "user",
        "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": data}},
            {"type": "text", "text": "Summarize the main trend in this chart"},
        ],
    }],
)
print(msg.content[0].text)

To use an image URL instead, set source to {"type": "url", "url": "https://..."}.

Things to know

  • Common formats such as JPEG, PNG, GIF and WebP are supported.
  • Images are billed as input tokens based on their size, so bigger images cost more. Resizing images to the resolution you actually need before sending can cut costs noticeably.
  • A single message can contain several images for comparison.
  • Placing images before the question text usually works better.
FlyRouter

One key, every top AI model