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:

  1. Encode the image as a base64 string and embed it in a data URI using the following format:
    data:image/png;base64,<BASE64_ENCODED_IMAGE>
    
    Replace image/png with the correct MIME type if you’re using JPEG or GIF (image/jpeg or image/gif).
  2. Provide a standard HTTPS URL pointing directly to the image file:
    https://example.com/path/to/your/image.png
    

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:

{
  "type": "image_url",
  "image_url": {
    "url": "data:image/png;base64,<BASE64_ENCODED_IMAGE>"
  }
}

Using HTTPS URL:

{
  "type": "image_url",
  "image_url": {
    "url": "https://example.com/path/to/your/image.png"
  }
}

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).
curl --location 'https://api.perplexity.ai/chat/completions' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
  "model": "sonar-pro",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Can you describe this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." // Replace with your base64 string
          }
        }
      ]
    }
  ]
}'
  • 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.