Pictures in
Send a picture with your question; get an answer about it.
1. Pick a model that reads pictures
Not every text model looks at pictures. Models that take pictures in lists the ones that do; the sample below uses anthropic/claude-sonnet-4.5.
A picture sent to a model that cannot read it is refused before it goes anywhere, with a 400. Nothing is charged.
2. Add the picture as a part of your message
A message's content is a text, or a list of parts. To send a picture, make it a list: one text part for your question, one image_url part for the picture.
| Part | Holds |
|---|---|
{"type": "text", "text": "..."} | your question |
{"type": "image_url", "image_url": {"url": "..."}} | the picture: a public link, or the picture itself as a data: URL |
Send as many image_url parts as the question needs, in the order you want them read.
import json
import os
import urllib.request
API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/chat/completions"
MODEL = "anthropic/claude-sonnet-4.5"
PROMPT = "What does this picture show?"
PICTURE = "https://opendunes.com/icon.png"
body = {
"model": MODEL,
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": PROMPT},
{"type": "image_url", "image_url": {"url": PICTURE}},
],
}
],
}
request = urllib.request.Request(
ADDRESS,
data=json.dumps(body).encode(),
headers={
"Authorization": "Bearer " + API_KEY,
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request) as response:
reply = json.load(response)
print(reply["choices"][0]["message"]["content"])
print(reply["usage"]["cost"])Send a public link when the picture is online, and a data: URL when it is a file on your side. The whole request, pictures included, stays under 32 MB.
Don't send a link that needs a sign-in to open. The model cannot sign in, and the request fails.
3. Read the answer
The answer is the text in choices[0].message.content, as on any text request. The picture is charged as input tokens beside your words, and usage.cost is the whole charge.
To send the answer back as a stream, see Streaming. To hold the answer to a shape, see Structured outputs. Every field of the request: Chat.
Pictures in the other direction, made from words, are in Pictures.
Errors
The body says why. What to do on every status: Errors and retries.
| Status | Means |
|---|---|
| 400 | the model takes no pictures, or the picture is not in a format it reads |
| 402 | the balanceBalanceWhat you can spend, in DA.More on Balance and charges → cannot cover the request |
| 404 | no such model |
| 413 | the request is larger than the door takes |