Are you sure you want to delete this access key?
sidebar_label |
---|
Perplexity |
The Perplexity API provides chat completion models with built-in search capabilities, citations, and structured output support. Perplexity models retrieve information from the web in real-time, enabling up-to-date responses with source citations.
Perplexity follows OpenAI's chat completion API format - see our OpenAI documentation for the base API details.
PERPLEXITY_API_KEY
environment variable or specify apiKey
in your configPerplexity offers several specialized models optimized for different tasks:
Model | Context Length | Description | Use Case |
---|---|---|---|
sonar-pro | 200k | Advanced search model with 8k max output tokens | Long-form content, complex reasoning |
sonar | 128k | Lightweight search model | Quick searches, cost-effective responses |
sonar-reasoning-pro | 128k | Premier reasoning model with Chain of Thought (CoT) | Complex analyses, multi-step problem solving |
sonar-reasoning | 128k | Fast real-time reasoning model | Problem-solving with search |
sonar-deep-research | 128k | Expert-level research model | Comprehensive reports, exhaustive research |
r1-1776 | 128k | Offline chat model (no search) | Creative content, tasks without web search needs |
providers:
- id: perplexity:sonar-pro
config:
temperature: 0.7
max_tokens: 4000
- id: perplexity:sonar
config:
temperature: 0.2
max_tokens: 1000
search_domain_filter: ['wikipedia.org', 'nature.com', '-reddit.com'] # Include wikipedia/nature, exclude reddit
search_recency_filter: 'week' # Only use recent sources
Perplexity models automatically search the internet and cite sources. You can control this with:
search_domain_filter
: List of domains to include/exclude (prefix with -
to exclude)search_recency_filter
: Time filter for sources ('month', 'week', 'day', 'hour')return_related_questions
: Get follow-up question suggestionsweb_search_options.search_context_size
: Control search context amount ('low', 'medium', 'high')providers:
- id: perplexity:sonar-pro
config:
search_domain_filter: ['stackoverflow.com', 'github.com', '-quora.com']
search_recency_filter: 'month'
return_related_questions: true
web_search_options:
search_context_size: 'high'
Control search results based on publication date:
providers:
- id: perplexity:sonar-pro
config:
# Date filters - format: "MM/DD/YYYY"
search_after_date_filter: '3/1/2025'
search_before_date_filter: '3/15/2025'
Localize search results by specifying user location:
providers:
- id: perplexity:sonar
config:
web_search_options:
user_location:
latitude: 37.7749
longitude: -122.4194
country: 'US' # Optional: ISO country code
Get responses in specific formats using JSON Schema:
providers:
- id: perplexity:sonar
config:
response_format:
type: 'json_schema'
json_schema:
schema:
type: 'object'
properties:
title: { type: 'string' }
year: { type: 'integer' }
summary: { type: 'string' }
required: ['title', 'year', 'summary']
Or with regex patterns (sonar model only):
providers:
- id: perplexity:sonar
config:
response_format:
type: 'regex'
regex:
regex: "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
Note: First request with a new schema may take 10-30 seconds to prepare. For reasoning models, the response will include a <think>
section followed by the structured output.
Enable image retrieval in responses:
providers:
- id: perplexity:sonar-pro
config:
return_images: true
promptfoo includes built-in cost calculation for Perplexity models based on their official pricing. You can specify the usage tier with the usage_tier
parameter:
providers:
- id: perplexity:sonar-pro
config:
usage_tier: 'medium' # Options: 'high', 'medium', 'low'
The cost calculation includes:
For in-depth research reports:
providers:
- id: perplexity:sonar-deep-research
config:
temperature: 0.1
max_tokens: 4000
search_domain_filter: ['arxiv.org', 'researchgate.net', 'scholar.google.com']
web_search_options:
search_context_size: 'high'
For problems requiring explicit reasoning steps:
providers:
- id: perplexity:sonar-reasoning-pro
config:
temperature: 0.2
max_tokens: 3000
For creative content that doesn't require web search:
providers:
- id: perplexity:r1-1776
config:
temperature: 0.7
max_tokens: 2000
search_domain_filter
to trusted domains for higher quality citationssearch_recency_filter
for time-sensitive topicsweb_search_options.search_context_size
to "low"web_search_options.search_context_size
to "high"<think>
section followed by the structured outputCheck our perplexity.ai-example with multiple configurations showcasing Perplexity's capabilities:
You can initialize these examples with:
npx promptfoo@latest init --example perplexity.ai-example
Pricing varies by model and usage tier:
Model | Input Tokens (per million) | Output Tokens (per million) |
---|---|---|
sonar | $1 | $1 |
sonar-pro | $3 | $15 |
sonar-reasoning | $1 | $5 |
sonar-reasoning-pro | $2 | $8 |
sonar-deep-research | $2 | $8 |
r1-1776 | $2 | $8 |
Rate limits also vary by usage tier (high, medium, low). Specify your tier with the usage_tier
parameter to get accurate cost calculations.
Check Perplexity's pricing page for the latest rates.
search_domain_filter
with trusted domains for better citations<think>
sections, which may need parsing for structured outputsPress p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
promptfoo is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?