diff --git a/sdk/python/examples/10_error_handling_and_retry/async.py b/sdk/python/examples/10_error_handling_and_retry/async.py index b719b2fcd0..f1711bffc9 100644 --- a/sdk/python/examples/10_error_handling_and_retry/async.py +++ b/sdk/python/examples/10_error_handling_and_retry/async.py @@ -21,6 +21,7 @@ from openai_codex import ( TextInput, is_retryable_error, ) +from openai_codex.types import TurnStatus ResultT = TypeVar("ResultT") @@ -72,6 +73,10 @@ async def main() -> None: print(f"JSON-RPC error {exc.code}: {exc.message}") return + if result.status == TurnStatus.failed: + print("Turn failed:", result.error) + return + print("Text:", result.final_response) diff --git a/sdk/python/examples/10_error_handling_and_retry/sync.py b/sdk/python/examples/10_error_handling_and_retry/sync.py index 9c3aca64fa..c134063c80 100644 --- a/sdk/python/examples/10_error_handling_and_retry/sync.py +++ b/sdk/python/examples/10_error_handling_and_retry/sync.py @@ -16,6 +16,7 @@ from openai_codex import ( TextInput, retry_on_overload, ) +from openai_codex.types import TurnStatus with Codex(config=runtime_config()) as codex: thread = codex.thread_start(model="gpt-5.4", config={"model_reasoning_effort": "high"}) @@ -32,4 +33,7 @@ with Codex(config=runtime_config()) as codex: except JsonRpcError as exc: print(f"JSON-RPC error {exc.code}: {exc.message}") else: - print("Text:", result.final_response) + if result.status == TurnStatus.failed: + print("Turn failed:", result.error) + else: + print("Text:", result.final_response)