High severity intermediate · Fix: 5-10 min

OpenAIError

openai.OpenAIError: Run failed with requires_action not handled

What this error means
The OpenAI client run failed because a 'requires_action' response was returned but not handled in code.

Stack trace

traceback
openai.OpenAIError: Run failed: requires_action not handled
  File "/app/main.py", line 42, in run_assistant
    response = client.chat.completions.create(model="gpt-4o", messages=messages)
  File "/usr/local/lib/python3.9/site-packages/openai/api_resources/chat.py", line 75, in create
    raise OpenAIError(f"Run failed: {error_detail}")
openai.OpenAIError: Run failed: requires_action not handled
QUICK FIX
Catch OpenAIError exceptions and add logic to detect and handle 'requires_action' responses before retrying or failing.

Why it happens

The OpenAI API can return a 'requires_action' status indicating additional user or system action is needed before continuing. If the client code does not explicitly check for and handle this status, it raises an error. This usually happens when using advanced assistant features or workflows requiring multi-step interactions.

Detection

Monitor for OpenAIError exceptions containing 'requires_action' in the message and log the full response payload to detect unhandled action requirements before failure.

Causes & fixes

1

The API returned a 'requires_action' status indicating further steps are needed but the client code does not check for it.

✓ Fix

Add explicit handling for 'requires_action' in the response, such as prompting the user or triggering the required follow-up action.

2

Using an OpenAI assistant feature that requires multi-turn interaction without implementing the required action flow.

✓ Fix

Implement the multi-turn action flow as documented, handling 'requires_action' responses by branching logic or user prompts.

3

Client code assumes all runs succeed immediately and does not handle intermediate states.

✓ Fix

Add robust error and state handling around run completions to detect and process intermediate statuses like 'requires_action'.

Code: broken vs fixed

Broken - triggers the error
python
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

messages = [{"role": "user", "content": "Start the assistant flow."}]

# This line raises OpenAIError: Run failed: requires_action not handled
response = client.chat.completions.create(model="gpt-4o", messages=messages)
print(response)
Fixed - works correctly
python
from openai import OpenAI, OpenAIError
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

messages = [{"role": "user", "content": "Start the assistant flow."}]

try:
    response = client.chat.completions.create(model="gpt-4o", messages=messages)
except OpenAIError as e:
    if "requires_action" in str(e):
        # Handle the requires_action response here, e.g., prompt user or trigger follow-up
        print("Requires action detected. Please handle the next steps.")
    else:
        raise
else:
    print(response)
Added try/except to catch OpenAIError and detect 'requires_action' in the error message to handle it gracefully instead of crashing.

Workaround

Wrap the API call in a try/except block catching OpenAIError, then parse the error message or response for 'requires_action' and implement a fallback prompt or manual intervention.

Prevention

Design your assistant workflows to detect and handle intermediate states like 'requires_action' by implementing multi-turn interaction logic and state management to avoid unhandled errors.

Python 3.9+ · openai >=1.0.0 · tested on 1.2.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.