Please read this first
Describe the bug
When the upstream provider responds with an error payload ({"error": …}), the Agents SDK still returns a ChatCompletion-shaped object whose choices field is None.
openai_chatcompletions.py immediately dereferences response.choices[0] inside its debug logger, producing
TypeError: 'NoneType' object is not subscriptable
The exception is raised inside the SDK, before the calling application sees the provider error.
Debug information
| Item |
Value |
| Agents SDK version |
v0.0.13 |
| Python version |
3.12.9 |
| OS |
macOS 15.4 (arm64) |
Repro steps
# mockup_main.py
from agents import Runner
from agents.models import OpenAIChatCompletionsModel
# A key / proxy that will reliably return {"error": …}
model = OpenAIChatCompletionsModel(
model="gpt-3.5-turbo",
api_key="sk-dummy",
base_url="https://openrouter.ai/v1",
)
runner = Runner(model=model)
# ⇢ Raises TypeError in the SDK before we can handle the error payload
runner.run("Ping?")
Run:
export AGENTS_LOGGING_LEVEL=DEBUG # optional, shows failing log line
python repro.py
Observed output
TypeError: 'NoneType' object is not subscriptable
(full traceback shows the line in openai_chatcompletions.py that
logs response.choices[0]).
Expected behavior
The SDK should detect that response.choices is missing and raise a clear domain-specific exception (e.g. ProviderError) containing the provider’s error message, instead of crashing with an internal TypeError.
All downstream code paths would then have a chance to handle the error or retry gracefully.
Please read this first
Describe the bug
When the upstream provider responds with an error payload (
{"error": …}), the Agents SDK still returns aChatCompletion-shaped object whosechoicesfield isNone.openai_chatcompletions.pyimmediately dereferencesresponse.choices[0]inside its debug logger, producingThe exception is raised inside the SDK, before the calling application sees the provider error.
Debug information
Repro steps
Run:
Observed output
(full traceback shows the line in
openai_chatcompletions.pythatlogs
response.choices[0]).Expected behavior
The SDK should detect that
response.choicesis missing and raise a clear domain-specific exception (e.g.ProviderError) containing the provider’s error message, instead of crashing with an internalTypeError.All downstream code paths would then have a chance to handle the error or retry gracefully.