Responses API: background: true drops code_interpreter_call.outputs even when retrieved with include[]

When using the Responses API with the Code Interpreter tool enabled and requesting include: ["code_interpreter_call.outputs"], I consistently get populated outputs (stdin/stdout entries) when background: false. However, when background: true, the response reaches a terminal state (e.g., completed) but any code_interpreter_call items in output always contain outputs: [], even when polling via GET /v1/responses/{id}?include[]=code_interpreter_call.outputs.

This blocks async workflows where I need Code Interpreter stdout/stderr in background-mode responses.

Environment

  • Endpoint: POST /v1/responses, GET /v1/responses/{response_id}
  • Model: gpt-5.2-2025-12-11
  • Tool: code_interpreter with container: { type: "auto", memory_limit: "4g" }
  • Include expansion: code_interpreter_call.outputs
  • Client: cURL (script below)
  • Auth: Bearer token

Expected behavior

When a background response completes, polling it with:

  • GET /v1/responses/{id}?include[]=code_interpreter_call.outputs

should return the Code Interpreter call outputs (stdout/stderr entries) in the code_interpreter_call.outputs array, consistent with background: false.

Observed behavior

  • With background: true:
    • Response reaches status=completed (or another terminal state).
    • output includes code_interpreter_call items, but each has outputs: [].
    • This occurs even when passing include[]=code_interpreter_call.outputs during polling.
  • With background: false (control):
    • The same request pattern returns code_interpreter_call.outputs populated as expected (stdout/stderr entries present).

Steps to reproduce

  1. Create a Response with:
    • tools: [{ type: "code_interpreter", ... }]
    • include: ["code_interpreter_call.outputs"]
    • background: true
    • An instruction that explicitly runs Python and prints a known string.
  2. Poll the Response until terminal using:
    • GET /v1/responses/{id}?include[]=code_interpreter_call.outputs
  3. Inspect output and locate type: “code_interpreter_call” items.
  4. Observe outputs: [] (empty array) even though the response is terminal.
  5. Repeat with background: false and confirm outputs are present.

Dedicated repro script (paste/run as-is)

I’m including the full repro script inline below. It demonstrates both the buggy behavior (background: true) and the expected behavior (background: false). This was written for zsh

setopt INTERACTIVE_COMMENTS

export OPENAI_API_KEY="REPLACE_ME"
export MODEL="gpt-5.2-2025-12-11"

# Helper: extract code_interpreter outputs from response JSON
show_outputs() {
  python3 -c '
import sys, json
items = json.load(sys.stdin).get("output", [])
ci = [x for x in items if x.get("type") == "code_interpreter_call"]
print(f"code_interpreter_call items: {len(ci)}")
for i, it in enumerate(ci):
    outs = it.get("outputs")
    print(f"\n[{i}] outputs: {type(outs).__name__}, len: {len(outs) if isinstance(outs, list) else 'n/a'}")
    print(json.dumps(outs, indent=2))
'
}

# Common request body (background value injected)
request_body() {
  cat <<JSON
{
  "model": "$MODEL",
  "input": "Use the code interpreter tool. Run Python that prints exactly: BG_STDOUT_OK",
  "tools": [{ "type": "code_interpreter", "container": { "type": "auto", "memory_limit": "4g" }}],
  "include": ["code_interpreter_call.outputs"],
  "background": $1,
  "reasoning": { "effort": "low" }
}
JSON
}

api() { curl -sS "$1" -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" "${@:2}"; }

#--- BUG CASE: background: true ---
echo "=== Background request (buggy) ==="
RESP=$(api "https://api.openai.com/v1/responses" -d "$(request_body true)")
ID=$(echo "$RESP" | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])')
echo "response_id=$ID"

# Poll until terminal
while true; do
  POLL=$(api "https://api.openai.com/v1/responses/$ID?include[]=code_interpreter_call.outputs")
  STATUS=$(echo "$POLL" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("status"))')
  echo "status=$STATUS"
  [[ "$STATUS" =~ ^(completed|failed|cancelled)$ ]] && break
  sleep 1
done

echo "$POLL" | show_outputs
# Expected: outputs with BG_STDOUT_OK | Observed: outputs: []

#--- EXPECTED CASE: background: false ---
echo "\n=== Foreground request (works) ==="
api "https://api.openai.com/v1/responses" -d "$(request_body false)" | show_outputs

Notes / additional context

I have ruled out common causes:

  • include is provided both at creation and on polling via include[]=code_interpreter_call.outputs.
  • Polling continues until the response is in a terminal state.
  • Issue persists regardless of state management approach (e.g., previous_response_id vs stateful conversation approaches).
  • This appears specific to background: true.

Request

Can you confirm whether this is:

  1. a known bug / regression in background-mode persistence of Code Interpreter outputs, or
  2. an intentional limitation of background-mode responses (and if so, please document it and suggest the supported retrieval mechanism)?
1 Like