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
Setbackground=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 withGET 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.
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 bothbackground=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 withPOST 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.