Skip to main content

Overview

Long agentic runs, such as deep research or heavy sandbox work, can take several minutes. Background mode runs these tasks asynchronously so your application can avoid timeouts and dropped connections: submit the run, store its response id, then poll for the result. The run continues server-side even if your client disconnects.

Submit a background request

Set background=true when you create the response. The submit endpoint is POST https://api.perplexity.ai/v1/agent. The create call returns a Response object immediately; store its id and check its initial status.

Poll for the result

Poll a background response with GET https://api.perplexity.ai/v1/responses/{id}. A background response is non-terminal while its status is queued or in_progress. It is terminal when its status is completed, failed, or cancelled. Poll until the response reaches any terminal status, then branch based on the final state.
After the loop, handle each terminal status explicitly. For completed, read the output; for failed, inspect the error object; for cancelled, treat the run as intentionally stopped.

Stream and reconnect

You can stream a long-running background response by creating it with both background=true and stream=true. Save the response id, and keep a cursor from the sequence_number on each streamed event. If the connection drops, reconnect with GET /v1/responses/{id}?stream=true&starting_after=N to resume after sequence number N.
Reconnect is only valid within the response’s reconnect window. If that window expires, the reconnect request returns 400; fall back to a plain GET /v1/responses/{id} to retrieve the final snapshot.

Cancel a run

Cancel an in-flight background response with POST https://api.perplexity.ai/v1/responses/{id}/cancel when the result is no longer needed. Cancelling is idempotent: cancelling an already-terminal response returns the current Response object.

Next Steps

Working with files

Sandbox

Wide Research

Streaming/output control