This example demonstrates how to send images to vision models through the OpenRouter API.
- Single Image with URL - Send a publicly accessible image URL
- Multiple Images - Send multiple images in a single request
- Detail Levels - Control image analysis detail (low/high/auto)
- ContentBuilder - Build complex messages with interleaved text and images
- Base64 Encoding - Send local images using base64 encoding
# Set your API key
export OPENROUTER_API_KEY="your-api-key"
# Run the example
go run examples/image-inputs/main.goOpenRouter supports the following image formats:
- PNG (image/png)
- JPEG (image/jpeg)
- WebP (image/webp)
- GIF (image/gif)
Use publicly accessible image URLs. This is more efficient as it doesn't require local encoding:
message := openrouter.CreateUserMessageWithImage(
"What's in this image?",
"https://example.com/image.jpg",
)For local files or private images:
// Automatically encodes the image to base64
message, err := openrouter.CreateUserMessageWithBase64Image(
"What's in this image?",
"path/to/image.jpg",
)Some models support detail level parameters:
"low"- Faster and cheaper, suitable for general understanding"high"- More detailed analysis at higher cost"auto"- Let the model decide based on image size (default)
message := openrouter.CreateUserMessageWithImageDetail(
"Describe this image in detail.",
"https://example.com/image.jpg",
"high",
)Send multiple images in a single request:
message := openrouter.CreateUserMessageWithImages(
"Compare these images",
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg",
)For complex messages with interleaved text and images:
content := openrouter.NewContentBuilder().
AddText("Here's the first image:").
AddImage("https://example.com/image1.jpg").
AddText("And here's the second:").
AddImageWithDetail("https://example.com/image2.jpg", "high").
AddText("What are the differences?")
message := content.BuildMessage("user")Most modern vision models support image inputs, including:
- Google Gemini models (gemini-2.0-flash-thinking-exp, etc.)
- OpenAI GPT-4 Vision models
- Anthropic Claude 3 models
- And many others
Check the OpenRouter documentation for the latest list of supported models.
- The number of images you can send in a single request varies per provider and per model
- Image URLs must be publicly accessible
- Base64-encoded images increase request size, so use URLs when possible
- Some providers may have size limits on images
- Pricing may vary based on image size and detail level