The image upload feature allows you to include images in your API requests to support multi-modal conversations alongside text.

The API currently only supports images in base64 format with limit of 20 MB per image. Direct file uploads or external URLs are not supported.

Supported formats

  • PNG (image/png)
  • JPEG (image/jpeg)
  • GIF (image/gif)

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 must 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 for .jpg or .jpeg
  • image/gif for .gif

This data URI 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:

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

Examples

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..."
          }
        }
      ]
    }
  ]
}'
  • Image and regex cannot be used together in the same request.
  • sonar-deep-research does not support image input.