Guides
Image Guide
Learn how to use Sonar’s image upload feature.
The image upload feature allows you to include images in your API requests to support multi-modal conversations alongside text. Images can be provided either as base64 encoded strings within a data URI or as standard HTTPS URLs.
- When using base64 encoding, the API currently only supports images up to 5 MB per image.
- Supported formats for base64 encoded images: PNG (image/png), JPEG (image/jpeg), WEBP (image/webp), and GIF (image/gif).
- When using an HTTPS URL, the model will attempt to fetch the image from the provided URL. Ensure the URL is publicly accessible.
Image uploads can be useful for:
- Asking questions about visual content (e.g., text in a screenshot, diagram interpretation)
- Providing context for follow-up queries
- Analyzing visual media as part of a multi-turn conversation
⸻
Overview
To include an image in a request, you can either:
- Encode the image as a base64 string and embed it in a data URI using the following format:
Replace
image/png
with the correct MIME type if you’re using JPEG or GIF (image/jpeg
orimage/gif
). - Provide a standard HTTPS URL pointing directly to the image file:
This data URI or HTTPS URL should be included in your API request as part of a messages
array, using the image_url
content type.
⸻
Request Format
Images must be embedded in the messages
array, alongside any text input. Each image should be provided using the following structure:
Using Base64 Data URI:
Using HTTPS URL:
⸻
Examples
Use this method when you have the image file locally and want to embed it directly into the request payload. Remember the 5MB size limit and supported formats (PNG, JPEG, WEBP, GIF).
Use this method when you have the image file locally and want to embed it directly into the request payload. Remember the 5MB size limit and supported formats (PNG, JPEG, WEBP, GIF).
Use this method to reference an image hosted online. Ensure the URL is publicly accessible and points directly to the image file.
- Image and regex cannot be used together in the same request.
sonar-deep-research
does not support image input.- Ensure provided HTTPS URLs are publicly accessible.