Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt

Use this file to discover all available pages before exploring further.

Available Models

The Agent API supports direct access to models from multiple providers. All models are accessed directly from first-party providers with transparent token-based pricing. Pricing rates are updated monthly and reflect direct first-party provider pricing with no markup. All charges are based on actual token consumption, and every API response includes exact token counts so you know your costs per request.
Looking for pre-configured model setups? See Presets — optimized for specific use cases.

Perplexity

Sonar — Perplexity’s grounded search model.
ModelInput ($/1M)Output ($/1M)Cache ($/1M)Docs
perplexity/sonar0.252.500.0625Sonar
Not all third-party models support all features (e.g., reasoning, tools). Check model documentation for specific capabilities.

Using a Model

from perplexity import Perplexity

client = Perplexity()

response = client.responses.create(
    model="openai/gpt-5.5",
    input="Explain the difference between supervised and unsupervised learning in machine learning.",
    max_output_tokens=300,
)

print(f"Response ID: {response.id}")
print(response.output_text)
See Your Costs in Real-Time: Every response includes a usage field with exact input tokens, output tokens, and cache read tokens. Calculate your cost instantly using the pricing table above.
{
  "usage": {
    "input_tokens": 150,
    "output_tokens": 320,
    "total_tokens": 470
  }
}

Model Fallback

For high-availability applications, you can specify multiple models in a fallback chain. When one model fails or is unavailable, the API automatically tries the next model in the chain.

Model Fallback Chain

Learn how to use model fallback chains to ensure high availability and reliability by automatically trying multiple models when one fails.
Example:
response = client.responses.create(
    models=["openai/gpt-5.5", "anthropic/claude-sonnet-4-6", "google/gemini-3-flash-preview"],
    input="Your question here"
)
For detailed examples, pricing information, and best practices, see the Model Fallback documentation.

Next Steps

Web Search

Equip your model with web search for source-grounded context.

Prompt Guide

Write prompts that get the most out of the Agent API.

Output Control

Shape responses with structured outputs and JSON schemas.

Finance Search

Query market data, filings, and ticker-level information.