For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Background mode

Run long running tasks asynchronously in the background.

Agents like Codex and Deep Research show that reasoning models can take several minutes to solve complex problems. Background mode enables you to execute long-running tasks on models like GPT-5.2 and GPT-5.2 Pro reliably, without having to worry about timeouts or other connectivity issues.

Background mode kicks off these tasks asynchronously, and developers can poll response objects to check status over time. To start response generation in the background, make an API request with background set to true:

Background requests from Zero Data Retention (ZDR) projects run with store=false. Response data is temporarily stored to disk for roughly 10 minutes to enable asynchronous execution and polling.

For projects using Modified Abuse Monitoring, including enhanced Modified Abuse Monitoring, foreground requests follow standard retention when store is omitted or set to true. Background responses are retained after the polling period only when store=true is explicitly provided. If store is omitted or set to false for a background request, the response is deleted after roughly 10 minutes.

Generate a response in the background
from openai import OpenAI

client = OpenAI()

resp = client.responses.create(
    model="gpt-6-astra",
    input="Write a very long novel about otters in space.",
    background=True,
)

print(resp.status)

Polling background responses

To check the status of background requests, use the GET endpoint for Responses. Keep polling while the request is in the queued or in_progress state. When it leaves these states, it has reached a final (terminal) state.

Retrieve a response executing in the background
from openai import OpenAI
from time import sleep

client = OpenAI()

resp = client.responses.create(
    model="gpt-6-astra",
    input="Write a very long novel about otters in space.",
    background=True,
)

while resp.status in {"queued", "in_progress"}:
    print(f"Current status: {resp.status}")
    sleep(2)
    resp = client.responses.retrieve(resp.id)

print(f"Final status: {resp.status}\nOutput:\n{resp.output_text}")

Cancelling a background response

You can also cancel an in-flight response like this:

Cancel an ongoing response
import os

from openai import OpenAI

response_id = os.environ["OPENAI_RESPONSE_ID"]
client = OpenAI()

resp = client.responses.cancel(response_id)

print(resp.status)

Cancelling twice is idempotent - subsequent calls simply return the final Response object.

Streaming a background response