Vision
GPT-4 Vision API - Analyze images with GPT-4o, GPT-4-turbo through UniterRouter. Image understanding, OCR, diagram analysis for multimodal AI applications.
Vision
Analyze images using multimodal models like GPT-4o, Claude 3.5 Sonnet, or Gemini through the standard Chat Completions API.
Supported Models: GPT-4o, GPT-4 Turbo, Claude 3.5 Sonnet/Haiku, Gemini 2.0/1.5 Pro, and other vision-capable models.
Image Input Methods
URL Reference
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}Base64 Encoded
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
}
}
]
}Example Request
from openai import OpenAI
import base64
client = OpenAI(
base_url="https://api.uniterouter.ai/v1",
api_key="your_api_key",
)
# Using URL
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/photo.jpg"}
}
]
}
],
max_tokens=300
)
# Using Base64
with open("image.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{image_data}"
}
}
]
}
]
)import OpenAI from "openai";
import * as fs from "fs";
const client = new OpenAI({
baseURL: "https://api.uniterouter.ai/v1",
apiKey: process.env.UNITEROUTER_API_KEY,
});
// Using URL
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What's in this image?" },
{
type: "image_url",
image_url: { url: "https://example.com/photo.jpg" },
},
],
},
],
max_tokens: 300,
});
// Using Base64
const imageData = fs.readFileSync("image.jpg").toString("base64");
const response2 = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Describe this image" },
{
type: "image_url",
image_url: { url: `data:image/jpeg;base64,${imageData}` },
},
],
},
],
});curl https://api.uniterouter.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}
],
"max_tokens": 300
}'Multiple Images
Analyze multiple images in a single request:
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Compare these two images"},
{"type": "image_url", "image_url": {"url": "https://example.com/image1.jpg"}},
{"type": "image_url", "image_url": {"url": "https://example.com/image2.jpg"}}
]
}
]
)Image Detail Level
Control image processing detail:
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg",
"detail": "high" // "low", "high", or "auto"
}
}| Detail | Description | Use Case |
|---|---|---|
low | 512px, faster, fewer tokens | Quick classification |
high | Full resolution, more detail | OCR, detailed analysis |
auto | Model decides | General use (default) |
Supported Formats
| Format | MIME Type |
|---|---|
| JPEG | image/jpeg |
| PNG | image/png |
| GIF | image/gif |
| WebP | image/webp |
Use Cases
| Use Case | Example Prompt |
|---|---|
| OCR | "Extract all text from this image" |
| Object Detection | "List all objects you can see" |
| Image Description | "Describe this image in detail" |
| Comparison | "What are the differences between these images?" |
| Chart Analysis | "Analyze this chart and summarize the data" |
| Code Screenshot | "Convert this code screenshot to text" |
Limitations
- Maximum image size varies by model
- Some models have limits on images per request
- Animated GIFs use only the first frame
Related
- Chat Completions - Base API reference
- Streaming - Stream responses
How is this guide?
Streaming
OpenAI Streaming API - Real-time GPT-4, Claude responses with Server-Sent Events. Implement streaming chat, reduce time-to-first-token for better UX in AI applications.
Function Calling
OpenAI Function Calling API - Enable GPT-4, GPT-3.5 to call external tools and APIs. Build AI agents with tool use, structured data extraction, and automated workflows.