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
sonarID prefix (these require web search) - Web search chat models with
searchin their IDs - Deep research reasoning models with
researchin 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
Enable background mode
Setbackground to true in your chat request:
stream and background to true causes the request to fail:
Retrieve a background result
The initial response contains a uniqueid that identifies the chat task:
id with the chat result endpoint to check the task status and retrieve the result:
{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.
Results are retained for 7 days by default and then deleted automatically. Retrieve and save them before they expire.
