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)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
- How to use the OpenAI SDK with a custom base URL
- How to call Claude with the OpenAI SDK
- How to call Gemini with the OpenAI SDK
- How to use the Anthropic Messages API on TokenRex
- How to stream LLM responses
- How to use function calling (tools) with an LLM API
- How to generate images with an API
- How to convert text to speech with an API