Images in Messages
Include images in user messages:Image Sources
Images can be provided via URL or base64:- URL
- Base64
Content Part Types
User messages can contain multiple content parts:Multiple Images
Include multiple images in one message:Text and Images Together
Mix text and images in any order:Audio input
Audio parts use base64 data and a MIME type:inlineData. OpenAI accepts
audio only through openai.chat.chatModel() with an audio-capable Chat
Completions model. Other providers reject audio with
UnsupportedInputModalityError.
File Attachments
Include files in messages:File support varies by provider and model. Check your provider’s
documentation for supported file types.
Common Use Cases
- Image Analysis
- OCR / Text Extraction
- Image Comparison
- Visual Question Answering
Multi-Modal with Streaming
Stream responses for multi-modal inputs:Reading Images from Disk
Load and encode local images:Multi-Modal Conversations
Build conversations with images:Provider Support
Multi-modal support varies by provider:- OpenAI
- Anthropic
Model support
Not every model accepts every input type. Readmodel.capabilities.modalities.input before you build a request:
UnsupportedInputModalityError (a ValidationError) before the request
reaches the provider:
base64 and url image
sources.
To run the same check yourself before dispatching a request, use validateInputModalities:
Best Practices
Use appropriate image formats
Use appropriate image formats
Common formats work best:
- JPEG: Photos, complex images
- PNG: Screenshots, diagrams, transparency
- WebP: Modern format, good compression
Optimize image size
Optimize image size
Resize large images before sending:
Be specific in prompts
Be specific in prompts
Tell the model what to focus on:
Check image support before building a request
Check image support before building a request
Read the capability instead of guessing from the model ID, and fall back to a
text-only prompt when images are not available:
Next Steps
Image Generation
Generate images from text prompts
Chat Completion
Learn basic text generation
Streaming
Stream multi-modal responses
Structured Outputs
Extract structured data from images