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.
How do I inspect the error, then retry only unfinished work, when an OpenAI Agents API turn fails?
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
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.
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.
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
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.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Recover an OpenAI Agents API failed turn” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.