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 50 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.
- 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:
messages
array, using the image_url
content type.
⸻
Request Format
Images must be embedded in themessages
array, alongside any text input. Each image should be provided using the following structure:
Using Base64 Data URI:
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).
Pricing
Images are tokenized based on their pixel dimensions using the following formula:- A 1024×768 image would consume: (1024 × 768) / 750 = 1,048 tokens
- A 512×512 image would consume: (512 × 512) / 750 = 349 tokens
sonar-pro
, sonar
, etc.). The image tokens are added to your total token count for the request alongside any text tokens.
- 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.