Overview
The Sonar API supports comprehensive media handling: send images and files for analysis, and receive images and videos in responses. This guide covers all media functionality in one place.Sending Images
Send images to the API for analysis using either base64 encoding or HTTPS URLs. Images are embedded in themessages array alongside text content.
Base64 Encoded Images
Use base64 encoding when you have the image file locally:Python SDK
HTTPS URL Images
Reference images hosted online:Python SDK
Key Parameters
- Image format: Use
data:image/{format};base64,{content}for base64 (e.g.,data:image/png;base64,...) - Token pricing: Images are tokenized as
(width × height) / 750tokens, priced at input token rates - Supported formats: PNG (
image/png), JPEG (image/jpeg), WEBP (image/webp), GIF (image/gif)
Sending Files
Upload documents (PDF, DOC, DOCX, TXT, RTF) for analysis using URLs or base64 encoding. Files can be provided as publicly accessible URLs or base64 encoded bytes without any prefix.Using a Public URL
Python SDK
Using Base64 Encoding
Python SDK
Key Parameters
- Supported formats: PDF, DOC, DOCX, TXT, RTF
- Base64 encoding: Provide only the base64 string without
data:prefix - File size limit: 50MB per file, maximum 30 files per request
- URL requirements: Must be publicly accessible and return the file directly
Receiving Images
Control which images are returned in API responses usingreturn_images, image_domain_filter, and image_format_filter parameters.
The
return_images feature is currently only available in the Sonar API.Basic Image Returns
Enable image returns by settingreturn_images: true:
Python SDK
Filtering Image Domains
Control which image sources are included or excluded:Python SDK
Filtering Image Formats
Restrict results to specific file formats:Python SDK
Key Parameters
return_images: Set totrueto enable image returnsimage_domain_filter: Array of domains (max 10 entries). Prefix with-to exclude (e.g.,-gettyimages.com)image_format_filter: Array of lowercase file extensions (max 10 entries). Usegif,jpg,png,webp(no dot prefix)- Limitations: Maximum 30 images per response, filters only apply when
return_images: true
Receiving Videos
Enable video returns in responses using themedia_response.overrides.return_videos parameter.
The
return_videos feature is currently only available in the Sonar API.Basic Video Returns
Python SDK
Combining Videos with Images
You can request both videos and images in the same response:Python SDK
Key Parameters
media_response.overrides.return_videos: Set totrueto enable video returns- Response format: Videos appear in the
videosarray withurl,thumbnail_url, and metadata - Performance: Video-enabled requests may take longer to process and produce larger responses
Best Practices
Next Steps
Sonar Quickstart
Get started with the Sonar API and learn the fundamentals