Overview
Sonar models can return images as part of their responses to enhance the information provided. You can control which images are returned using domain and format filters, giving you fine-grained control over the sources and file types of image results.SDK Installation Required: Install the official SDK first -
pip install perplexityai
for Python or npm install @perplexity-ai/perplexity_ai
for TypeScript/JavaScript.The
image_domain_filter
and image_format_filter
parameters allow you to control the sources and file types of image results returned by the Sonar models.You can include a maximum of 10 entries in each of the filter lists. These filters currently apply only when
"return_images": true
is set in your request.Filter Types
Domain Filtering
Theimage_domain_filter
parameter controls which image sources are included or excluded:
- Exclude domains: Prefix with
-
(e.g.,-gettyimages.com
) - Include domains: Use domain name directly (e.g.,
wikimedia.org
)
Format Filtering
Theimage_format_filter
parameter restricts results to specific file formats:
- Use lowercase file extensions:
gif
,jpg
,png
,webp
- Omit the dot prefix: use
gif
, not.gif
Basic Usage
To enable image returns, your request must include"return_images": true
.
Filtering Examples
1. Exclude Specific Image Domains
Filter out images from specific providers like Getty Images:2. Only Return GIFs
Restrict results to GIF images only:3. Combine Domain and Format Filters
Use both filters together for precise control:Advanced Filtering
Multiple Domain Exclusions
Multiple Format Types
Include Specific Domains
Common Use Cases
Educational Content
Creative Projects
High-Quality Photography
Best Practices
Domain Filtering Strategy
Domain Filtering Strategy
- Use simple domain names like
example.com
or-gettyimages.com
- Do not include
http://
,https://
, or subdomains - Mix inclusion and exclusion in domain filters for precise control
- Keep lists short (≤10 entries) for performance and relevance
Format Filtering Guidelines
Format Filtering Guidelines
- File extensions must be lowercase:
["jpg"]
, not["JPG"]
- Omit dot prefix: use
gif
, not.gif
- Consider your use case: GIFs for animation, PNG for transparency, JPG for photos
- WebP offers good compression but may have limited compatibility
Performance Optimization
Performance Optimization
- Filters may slightly increase response time
- Overly restrictive filters may reduce result quality or quantity
- Test different filter combinations to find the right balance
- Monitor response times with different filter configurations
Filter Reference
Supported Image Formats
Format | Extension | Best For |
---|---|---|
JPEG | jpg | Photographs, complex images |
PNG | png | Screenshots, images with transparency |
WebP | webp | Modern format with good compression |
GIF | gif | Animated images, simple graphics |
Common Domain Exclusions
Domain | Type | Reason |
---|---|---|
-gettyimages.com | Stock Photos | Watermarked content |
-shutterstock.com | Stock Photos | Watermarked content |
-istockphoto.com | Stock Photos | Watermarked content |
-pinterest.com | Social Media | Mixed quality/attribution |
Start with broad filters and gradually refine them based on the quality and relevance of returned images.
Limitations
- Maximum of 10 entries in each filter list
- Filters only apply when
"return_images": true
is set - Some domains may not be filterable due to CDN usage
- Very restrictive filters may result in no images being returned