Submit a toolSubmit

OpenAI Agents API turn failed. Inspect the error, then retry only unfinished work

Don’t resubmit a failed Agents API turn. Retrieve saved items, fix billing or invalid input, then continue unfinished work only when the session is idle. Short answer: 5 steps. 1) Find the failure: HTTP response vs turn vs session; 2) Check saved work before any retry; 3) Fix non-retryable causes first; 4) Retry transient failures the documented way; 5) Stop when the session itself failed.

Last updated: · This page is the decision checklist; the tools list for “Recover an OpenAI Agents API failed turn” is a separate URL.

The problem: Don’t resubmit a failed Agents API turn. Retrieve saved items, fix billing or invalid input, then continue unfinished work only when the session is idle.

How do I inspect the error, then retry only unfinished work, when an OpenAI Agents API turn fails?

  1. Find the failure: HTTP response vs turn vs session

    For API request failures, read the HTTP status and `error` object. On `agent.session.turn.failed`, retrieve the turn and inspect `status` and `error`. On `agent.session.failed`, retrieve the session. Environment failures expose `environment.error` on `agent.session.environment.failed`. Use `error.code` in logic and `error.message` for humans; handle unknown codes without crashing. Docs: https://developers.openai.com/api/docs/guides/agents-api/errors

  2. Check saved work before any retry

    If a session was created, retrieve the session, the turn, and saved items. If the turn is still active, keep following it. If it completed, use its result. A failed turn may already have changed files or called tools—confirm those effects before asking the agent to repeat work. A disconnected stream or `error` event alone does not prove the final turn state.

  3. Fix non-retryable causes first

    Correct invalid input (`invalid_request` / `error.param`) before resubmitting. For `context_length_exceeded`, shrink input or start a shorter new session. For `session_budget_exceeded`, start a new session. For credit/spend/usage limit codes, follow OpenAI billing guidance instead of blind retries. Safety blocks (`cyber_policy`, `misalignment_policy_violation`) need a revised request, not a hammer retry.

  4. Retry transient failures the documented way

    For rate limits, overload (`server_overloaded`), timeouts, and temporary service errors: honor `Retry-After`, use exponential backoff, and cap attempts. For an HTTP error, retry the original operation after checking outcome. For a failed turn, wait until the session is `idle`, then send a follow-up message asking it to continue only unfinished work—that starts a new turn on the same conversation. Sessions guide: https://developers.openai.com/api/docs/guides/agents-api/sessions

  5. Stop when the session itself failed

    A failed turn does not always fail the session. If the session `status` is `failed` or you receive `agent.session.failed`, stop reconnecting, fix the cause (environment, executor, credentials), and create a new session with the inputs you still need. For persistent errors, include request ID, session ID, and turn ID with support. Error codes overview: https://developers.openai.com/api/docs/guides/error-codes

Which tools are best to recover an OpenAI Agents API failed turn?

Agents API errors and recovery

HTTP vs turn vs session errors, transient retry steps, and when to create a new session.

Run and continue sessions

Idle vs active turns, follow-up messages, and cancelling an active turn.

Error codes guide

Shared HTTP and billing error guidance referenced by Agents API recovery.

Agents API overview

Architecture context for sessions, turns, and environments.

All tools for “Recover an OpenAI Agents API failed turn” →

Related fixes

See also AI tools launched today on the daily board.