DEVSAIO

Send images to AI models (vision) with the API

How to include images in chat requests as URLs or base64, with examples for screenshots, receipts and charts.

DEVSAIO team · 1 min read
Share on X

Many models can read images: screenshots, photos, receipts, charts, handwritten notes. You send the image inside a normal chat message.

Image from a URL

python
r = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's wrong with this UI? Give 3 concrete fixes."},
            {"type": "image_url", "image_url": {"url": "https://example.com/screenshot.png"}},
        ],
    }],
)

Image from a local file (base64)

python
import base64

with open("receipt.jpg", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

r = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "Extract merchant, date and total as JSON."},
        {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}},
    ]}],
)

Good uses

  • Receipts and invoices: extract fields into JSON (see extract data from invoices).
  • UI review: paste a screenshot and ask for accessibility or layout problems.
  • Charts: “summarise the trend in this chart”.
  • Bug reports: a screenshot of an error dialog is often clearer than a description.

Cost tips

Images are converted into input tokens, and large images cost more. Resize screenshots to the size that's still readable (around 1,000–1,500 px on the long side is usually plenty) before sending.

Check a model's capabilities on the model page: not every model accepts images.

Try it with one API key

Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.

Keep reading