Overview

Sonar models provide powerful web search capabilities, but there are times when you want to control when and how searches are performed. Perplexity offers two main approaches for search control:
  • Search Classifier - Let AI intelligently decide when to search based on the query context
  • Disable Search - Turn off web search completely for specific requests
Search control is available across all Sonar models.
Pricing remains the same regardless of whether search is triggered or not. Search control features are designed for performance optimization and user experience, not cost reduction.

Search Classifier

The search classifier is a trained model that automatically determines whether a web search is necessary based on the context and content of your query. This helps optimize performance and costs by only searching when beneficial.

How It Works

The classifier analyzes your query and decides whether:
  • Search is needed - For questions requiring current information, facts, or research
  • Search is unnecessary - For creative tasks, math problems, or general knowledge that doesn’t require real-time data

When to Use Search Classifier

Use the search classifier when you want to:
  • Improve response speed - Skip search for queries that don’t benefit from it
  • Automatic intelligence - Let AI decide the best approach for each query
  • Optimal user experience - Ensure search is only used when it adds value
import requests

# API configuration
API_URL = "https://api.perplexity.ai/chat/completions"
API_KEY = "your-api-key-here"

headers = {
    "accept": "application/json",
    "authorization": f"Bearer {API_KEY}",
    "content-type": "application/json"
}

# Query that benefits from search classifier
user_query = "What are the latest developments in quantum computing?"

payload = {
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": user_query}],
    "stream": False,
    "enable_search_classifier": True
}

response = requests.post(API_URL, json=payload, headers=headers)
print(response.json())

Search Classifier Examples

Disabling Search Completely

For certain use cases, you may want to disable web search entirely. This is useful when:
  • Offline-like responses - Get responses based only on training data
  • Creative tasks - Focus on generation without external influence
  • Deterministic responses - Ensure consistent outputs based only on training data

Implementation

To disable search completely, set the disable_search parameter to true:
import requests

# API configuration
API_URL = "https://api.perplexity.ai/chat/completions"
API_KEY = "your-api-key-here"

headers = {
    "accept": "application/json",
    "authorization": f"Bearer {API_KEY}",
    "content-type": "application/json"
}

# Query that doesn't need web search
user_query = "What is 2 + 2?"

payload = {
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": user_query}],
    "stream": False,
    "disable_search": True
}

response = requests.post(API_URL, json=payload, headers=headers)
print(response.json())
When search is disabled, responses will be based solely on the model’s training data and may not include the most current information.

Comparison and Best Practices

When to Use Each Approach

Search Classifier

Best for:
  • Mixed workloads with varying query types
  • Performance optimization without manual intervention
  • General-purpose applications
  • Unknown query patterns

Disabled Search

Best for:
  • Creative content generation
  • Mathematical computations
  • Sensitive data processing
  • Offline-like experiences

Performance Considerations

Search Classifier: Variable response time depending on whether search is triggeredDisabled Search: Consistently faster responses since no search operations occur

Complete Examples

Search Classifier in Action

1

Set up the request with search classifier

payload = {
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": "Explain machine learning"}],
    "enable_search_classifier": True
}
The classifier will likely skip search for this general concept explanation.
2

Try with a current events query

payload = {
    "model": "sonar-pro", 
    "messages": [{"role": "user", "content": "Latest AI news this week"}],
    "enable_search_classifier": True
}
The classifier will trigger search for this time-sensitive query.
Here’s an example of using disabled search for creative content generation:
import requests

payload = {
    "model": "sonar-pro",
    "messages": [
        {
            "role": "user", 
            "content": "Write a short science fiction story about time travel"
        }
    ],
    "disable_search": True,
    "temperature": 0.8
}

response = requests.post(
    "https://api.perplexity.ai/chat/completions",
    headers={
        "authorization": "Bearer your-api-key-here",
        "content-type": "application/json"
    },
    json=payload
)

Troubleshooting

Start with the search classifier for most applications, then selectively disable search for specific use cases where you want guaranteed offline-like behavior.