Skip to main content

What is background mode?

In background mode, you submit a chat request without waiting for the model to finish. Retrieve the result later. This is useful for long-running tasks such as image generation, complex reasoning, deep research, or multi-turn conversations.
Models and tasks that often take longer include:
  • Reasoning models set to a high reasoning effort
  • Gemini Banana models that generate images in chat
  • Chat models working on lengthy image analysis, video understanding, or document tasks
  • Chat models with the sonar ID prefix (these require web search)
  • Web search chat models with search in their IDs
  • Deep research reasoning models with research in their IDs
  • Chat models using tools such as search (web_search) or image generation (image_generation)
  • Other chat models with built-in web search enabled or external search tools in use
  • Other chat models that support image generation, voice, web fetching, document chat, or video analysis
You can also use background mode with other chat models if they respond slowly.Background mode is available only for non-streaming Chat Completions requests. Image and video models offer their own asynchronous modes.

Enable background mode

Set background to true in your chat request:
Background mode works only with non-streaming Chat Completions requests. Setting both stream and background to true causes the request to fail:

Retrieve a background result

The initial response contains a unique id that identifies the chat task:
Use this id with the chat result endpoint to check the task status and retrieve the result:
Replace {id} in the endpoint path with the task id from the initial response (1498e730-e3c7-48a5-b748-9d2d3e7c525b in this example). The query can return the following statuses:
  • pending: The task is queued.
  • running: The task is being processed.
  • succeed: The task completed successfully.
On success, the result has the same format as a non-background Chat Completions response:
Deserialize the JSON just as you would for a non-streaming chat completion.
Results are retained for 7 days by default and then deleted automatically. Retrieve and save them before they expire.
If the task fails, the error has the same format as a non-streaming Chat Completions error. Use its code and message to diagnose the failure.