Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/cai/sdk/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,16 @@ async def get_response(

raise

# Guard against empty choices list which can occur with some API providers
# (e.g. Gemini via OpenAI-compatible endpoint) due to content filtering or
# transient API errors. Raise a clear error instead of an obscure IndexError.
if not response.choices:
raise ValueError(
f"Model '{self.model}' returned a response with no choices. "
"This may be caused by content filtering, rate limiting, or an "
"API compatibility issue with the provider."
)

if _debug.DONT_LOG_MODEL_DATA:
logger.debug("Received model response")
else:
Expand Down