UniterRouter
API ReferenceOpenAI Compatible

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"
  }
}
DetailDescriptionUse Case
low512px, faster, fewer tokensQuick classification
highFull resolution, more detailOCR, detailed analysis
autoModel decidesGeneral use (default)

Supported Formats

FormatMIME Type
JPEGimage/jpeg
PNGimage/png
GIFimage/gif
WebPimage/webp

Use Cases

Use CaseExample 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

How is this guide?