BerriAI/litellm · error · APIError

LiteLLM: provider returned a response with no 'choices'…

Error message

LiteLLM: provider returned a response with no 'choices'. Raw keys: {list(response_object.keys())}

What it means

After the None check, convert_to_streaming_response_async() requires the response dict to contain a non-empty 'choices' list; otherwise it raises APIError(500) whose message includes the payload's raw top-level keys (Raw keys: ['error'], ['usage'], ...). The raw-keys dump exists precisely so you can identify what the malformed payload actually carried.

Solutions

  1. Read the 'Raw keys' in the message to identify what the payload contained, then fix the producer (cache writer or adapter) accordingly
  2. Ensure cached objects are the complete response dict including choices before being returned as hits
  3. Skip usage-only and error-shaped chunks in custom streaming adapters instead of converting them
  4. Catch APIError on this path and fall back to a live provider call

Example fix

# before
async for chunk in convert_to_streaming_response_async(payload):
    yield chunk  # payload = {"usage": {...}} -> APIError: no 'choices'

# after
if not payload.get("choices"):
    return  # skip usage-only/error trailers
async for chunk in convert_to_streaming_response_async(payload):
    yield chunk
Defensive patterns

Strategy: try-catch

Validate before calling

if not response_object or not response_object.get("choices"):
    return  # skip usage-only / error-shaped payloads
async for chunk in convert_to_streaming_response_async(response_object):
    yield chunk

Type guard

def has_choices(payload: object) -> bool:
    return isinstance(payload, dict) and isinstance(payload.get("choices"), list) and len(payload["choices"]) > 0

Try / catch

from litellm.exceptions import APIError

try:
    async for chunk in convert_to_streaming_response_async(payload):
        yield chunk
except APIError as e:
    if "no 'choices'" in str(e):
        log.warning("skipping choices-less payload keys=%s", list(payload.keys()))
        return
    raise

Prevention

When it happens

Trigger: Replaying a cached payload whose choices array was stripped; converting a usage-only final SSE chunk (stream_options.include_usage), a 200-with-error body, or a content-filter/moderation block through the async streaming converter.

Common situations: Custom caches storing only metadata/usage; providers returning error-shaped bodies with HTTP 200; adapters feeding every SSE chunk - including usage-only trailers - into the converter.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/3378d1922020acdb. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/llm_response_utils/convert_dict_to_response.py:185

        ModelResponse: The converted streaming response object.

    Returns:
        None
    """
    if response_object is None:
        raise Exception("Error in response object format")

    model_response_object: Final = ModelResponseStream()

    if model_response_object is None:
        raise Exception("Error in response creating model response object")

    choice_list: Final[list[StreamingChoices]] = []

    if not response_object.get("choices"):
        from litellm.exceptions import APIError

        raise APIError(
            status_code=500,
            message=(
                f"LiteLLM: provider returned a response with no 'choices'. Raw keys: {list(response_object.keys())}"
            ),
            llm_provider="",
            model="",
        )

    for idx, choice in enumerate(response_object["choices"]):
        if (
            choice["message"].get("tool_calls", None) is not None
            and isinstance(choice["message"]["tool_calls"], list)
            and len(choice["message"]["tool_calls"]) > 0
            and isinstance(choice["message"]["tool_calls"][0], dict)
        ):
            pydantic_tool_calls = []
            for index, t in enumerate(choice["message"]["tool_calls"]):
                if "index" not in t:

View on GitHub (pinned to 77b7c6c40c)