Skip to main content

Image Analysis

Analyze images using vision models through the Perplexity Agent API, then enrich the analysis with web search to provide real-world context. This example combines image understanding with live information retrieval in a two-step pipeline: identify what is in the image, then research the identified subjects.

Features

  • Upload images via base64 encoding or public HTTPS URL
  • Analyze images with vision-capable models like openai/gpt-5.4 through the Agent API
  • Combine image analysis with web search for context enrichment
  • Two-step pipeline: identify, then research
  • Support for PNG, JPEG, WEBP, and GIF formats

Installation

Usage

Full Code

Example Output

Base64-encoded images count toward input token usage. A 1024x768 image consumes approximately 1,048 tokens. The maximum file size for base64 images is 50 MB.
Vision input is supported on the Agent API via the input_image content type. Use a vision-capable model like openai/gpt-5.4. Check the Agent API Image Attachments docs for supported formats and size limits.

Limitations

  • Image analysis requires a vision-capable model (e.g., openai/gpt-5.4). Not all models support input_image.
  • Web search quality in Step 2 depends on identification accuracy in Step 1.
  • Only publicly accessible HTTPS URLs work for URL-based input. Private URLs will fail.
  • Animated GIFs are supported but only the first frame is analyzed.