How to send images to a vision model

Ask a chat model questions about an image by sending it in the message content.

Add an image part

Send the message content as a list with a text part and an image_url part. The image can be a public URL or a base64 data URL.

Example

from openai import OpenAI

client = OpenAI(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")

resp = client.chat.completions.create(
    model="gpt-6-astra",
    messages=[{"role": "user", "content": [{"type": "text", "text": "Describe this image"}, {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}]}],
)
print(resp.choices[0].message.content)
Get API keyCost calculatorDocs

Questions

Do I need a separate key for each provider?
No. One TokenRex API key works for every enabled model; change only the model ID.

Related