Perplexity API Timeout Default: How to Increase It
🔍 WiseChecker

Perplexity API Timeout Default: How to Increase It

When you send a request to the Perplexity API, the connection may stop waiting for a response before the answer is fully generated. This is called a timeout. The default timeout value is often too short for complex queries that require deep research or large context windows. This article explains why timeouts happen and how to increase the timeout setting in your code.

You will learn the default timeout values for the Perplexity API, the technical reason behind connection drops, and step-by-step instructions to extend the timeout in Python and other languages. We also cover related errors and common mistakes to avoid.

Key Takeaways: Perplexity API Timeout Settings

  • Default timeout: 30 seconds for most Perplexity API endpoints, but can be as low as 10 seconds in some SDKs.
  • Timeout error code: HTTP 504 Gateway Timeout or requests.exceptions.Timeout in Python.
  • Increase timeout via parameter: Pass timeout=120 in Python requests or set timeout in the OpenAI-compatible client.

ADVERTISEMENT

Why Perplexity API Timeouts Occur

The Perplexity API processes queries using large language models that perform multi-step reasoning and web searches. Complex queries that require extensive analysis or retrieval from many sources can take longer than the default timeout to complete. The default timeout is set by the API client library or by the HTTP client used in your code.

Most Perplexity API endpoints have a default timeout of 30 seconds. However, some SDKs such as the OpenAI Python library (used to call Perplexity) may default to 10 seconds or 60 seconds depending on the version. When the server does not return a response within that window, the client closes the connection and raises a timeout error.

The timeout is not a server-side limit. Perplexity servers continue processing even after the client times out. The timeout is purely a client-side setting that controls how long your application waits for the first byte of the response. If you receive a timeout error, the answer may still be generated on the server but is never delivered to your client.

Common Timeout Error Messages

The exact error message depends on your programming language and HTTP library. In Python with the requests library, you see requests.exceptions.ConnectTimeout or requests.exceptions.ReadTimeout. In Node.js with axios, you see Error: timeout of 10000ms exceeded. In the OpenAI Python client, you see openai.APITimeoutError.

Steps to Increase the Perplexity API Timeout

You can increase the timeout in two ways: by setting the timeout parameter in your HTTP request or by configuring the client object globally. Below are the steps for the most common environments.

Method 1: Increase Timeout in Python Using the requests Library

  1. Import the requests library
    Ensure you have the requests module installed. If not, run pip install requests in your terminal.
  2. Set the timeout parameter to a higher value
    In your API call, add the timeout argument. For example, set it to 120 seconds: response = requests.post(url, headers=headers, json=data, timeout=120).
  3. Handle the timeout exception
    Wrap the call in a try-except block to catch requests.exceptions.Timeout and log or retry the request.

Method 2: Increase Timeout in Python Using the OpenAI Client

Perplexity API is compatible with the OpenAI Python library. The default timeout in the OpenAI client is 60 seconds. To increase it:

  1. Install or update the openai library
    Run pip install openai --upgrade.
  2. Create the client with a custom timeout
    Use the timeout parameter when initializing the client: client = OpenAI(api_key='YOUR_KEY', base_url='https://api.perplexity.ai', timeout=120.0).
  3. Make the API call as usual
    The client now waits up to 120 seconds for a response. Example: response = client.chat.completions.create(model='sonar-pro', messages=[{'role':'user','content':'Your query'}]]).

Method 3: Increase Timeout in Node.js Using Axios

  1. Install axios
    Run npm install axios in your project directory.
  2. Set the timeout option in the request config
    Pass a config object with timeout set to milliseconds: const response = await axios.post(url, data, { headers: headers, timeout: 120000 }). This sets a 120-second timeout.
  3. Add error handling for timeout
    Check error.code === 'ECONNABORTED' to detect timeout errors specifically.

ADVERTISEMENT

Common Mistakes When Adjusting Perplexity API Timeout

Setting Timeout on the Wrong Object

When using the OpenAI client, the timeout must be set on the client object, not on the individual request method. Setting timeout inside client.chat.completions.create() is ignored in some library versions. Always set it in the constructor.

Using Too Low a Timeout for Complex Queries

Queries that require web search, multiple sources, or large context windows can take 60 to 120 seconds. If you set the timeout to 30 seconds, these queries will consistently fail. Increase the timeout to at least 120 seconds for production applications.

Not Handling Timeout Errors Gracefully

A timeout does not mean the request failed permanently. The server may still be processing. Implement a retry mechanism with exponential backoff to re-send the request after a short delay. Without retries, users see an error message for a query that would have succeeded if given more time.

Confusing Client Timeout with Server Timeout

The Perplexity API server also has internal timeouts for very long-running queries. If your client timeout is set to 300 seconds but the server times out at 180 seconds, you still get an error. Perplexity does not publicly document the server-side timeout, but it is generally above 120 seconds for standard endpoints. If you consistently get errors even with a high client timeout, contact Perplexity support.

Perplexity API Client Timeout Settings Comparison

Item Python requests Library OpenAI Python Client Node.js Axios
Default timeout None (waits indefinitely) 60 seconds None (waits indefinitely)
How to set timeout timeout=120 in request call timeout=120.0 in client constructor timeout: 120000 in config object
Timeout unit Seconds Seconds Milliseconds
Error type requests.exceptions.Timeout openai.APITimeoutError Error with code ECONNABORTED
Recommended value for Perplexity 120 seconds 120 seconds 120000 ms

Now you can adjust the timeout in your Perplexity API client to match the complexity of your queries. Start by setting the timeout to 120 seconds and monitor your application logs for timeout errors. If you still see timeouts, increase the value to 180 seconds. For advanced use, combine the timeout increase with a retry policy using the tenacity library in Python or the retry package in Node.js.

ADVERTISEMENT