Vision
Send images to a chat model with the vision capability.
Send an image#
Give the user message's content as a list of parts: text parts and image_url parts. The URL is a data: URL with base64 image data, such as data:image/png;base64,…. The gateway does not fetch remote http or https URLs; they are refused with 400 invalid_request. detail is auto (the default), low or high.
The samples read the model id from PANWARD_VISION_MODEL: set it to a chat model with the vision capability from the model catalog. A model without it refuses the request with 400 unsupported_parameter before any upstream call, so nothing is billed.
cat > body.json <<EOF { "model": "$PANWARD_VISION_MODEL", "messages": [{ "role": "user", "content": [ {"type": "text", "text": "Read the values on this lab report."}, {"type": "image_url", "image_url": {"url": "data:image/png;base64,$(base64 < report.png | tr -d '\n')", "detail": "high"}} ] }] } EOF curl https://api.panward.ai/v1/chat/completions \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @body.json
import base64, os from openai import OpenAI client = OpenAI( base_url="https://api.panward.ai/v1", api_key=os.environ["PANWARD_API_KEY"], ) with open("report.png", "rb") as f: image = base64.b64encode(f.read()).decode() reply = client.chat.completions.create( model=os.environ["PANWARD_VISION_MODEL"], messages=[{ "role": "user", "content": [ {"type": "text", "text": "Read the values on this lab report."}, {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}}, ], }], ) print(reply.choices[0].message.content) print(reply.usage.prompt_tokens) # the image is counted here
import { readFileSync } from "node:fs"; import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.panward.ai/v1", apiKey: process.env.PANWARD_API_KEY, }); const image = readFileSync("report.png").toString("base64"); const reply = await client.chat.completions.create({ model: process.env.PANWARD_VISION_MODEL!, messages: [ { role: "user", content: [ { type: "text", text: "Read the values on this lab report." }, { type: "image_url", image_url: { url: `data:image/png;base64,${image}` } }, ], }, ], }); console.log(reply.choices[0].message.content);
Limits#
The whole request body, images included, may be up to 10 MB; a larger one is refused with 413 request_too_large. Base64 makes an image about a third larger than the file, so scale images down before you send them.
Token cost of images#
Images are counted as input tokens by the serving model's rule and appear in usage.prompt_tokens. Before the request is sent, each image counts as 16,384 tokens toward the model's context window, the project's maximum prompt size and the tokens-per-minute limits, whatever its size.
What is stored#
Images are inference content and are never stored: they exist in the gateway's memory while the request runs. The receipt holds the hash of the request bytes, which include the image, so keep the exact body you sent if you want to verify it.
Models without vision#
An image part sent to a model without the vision capability is refused with 400 unsupported_parameter before any upstream call.