{"record":{"id":"3378d1922020acdb","repo":"BerriAI/litellm","slug":"litellm-provider-returned-a-response-with-no-cho","errorCode":null,"errorMessage":"LiteLLM: provider returned a response with no 'choices'. Raw keys: {list(response_object.keys())}","messagePattern":"LiteLLM: provider returned a response with no 'choices'\\. Raw keys: (.+?)","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"litellm/litellm_core_utils/llm_response_utils/convert_dict_to_response.py","lineNumber":185,"sourceCode":"        ModelResponse: The converted streaming response object.\n\n    Returns:\n        None\n    \"\"\"\n    if response_object is None:\n        raise Exception(\"Error in response object format\")\n\n    model_response_object: Final = ModelResponseStream()\n\n    if model_response_object is None:\n        raise Exception(\"Error in response creating model response object\")\n\n    choice_list: Final[list[StreamingChoices]] = []\n\n    if not response_object.get(\"choices\"):\n        from litellm.exceptions import APIError\n\n        raise APIError(\n            status_code=500,\n            message=(\n                f\"LiteLLM: provider returned a response with no 'choices'. Raw keys: {list(response_object.keys())}\"\n            ),\n            llm_provider=\"\",\n            model=\"\",\n        )\n\n    for idx, choice in enumerate(response_object[\"choices\"]):\n        if (\n            choice[\"message\"].get(\"tool_calls\", None) is not None\n            and isinstance(choice[\"message\"][\"tool_calls\"], list)\n            and len(choice[\"message\"][\"tool_calls\"]) > 0\n            and isinstance(choice[\"message\"][\"tool_calls\"][0], dict)\n        ):\n            pydantic_tool_calls = []\n            for index, t in enumerate(choice[\"message\"][\"tool_calls\"]):\n                if \"index\" not in t:","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/llm_response_utils/convert_dict_to_response.py#L167-L203","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the 'Raw keys' in the message to identify what the payload contained, then fix the producer (cache writer or adapter) accordingly","Ensure cached objects are the complete response dict including choices before being returned as hits","Skip usage-only and error-shaped chunks in custom streaming adapters instead of converting them","Catch APIError on this path and fall back to a live provider call"],"exampleFix":"# before\nasync for chunk in convert_to_streaming_response_async(payload):\n    yield chunk  # payload = {\"usage\": {...}} -> APIError: no 'choices'\n\n# after\nif not payload.get(\"choices\"):\n    return  # skip usage-only/error trailers\nasync for chunk in convert_to_streaming_response_async(payload):\n    yield chunk","handlingStrategy":"try-catch","validationCode":"if not response_object or not response_object.get(\"choices\"):\n    return  # skip usage-only / error-shaped payloads\nasync for chunk in convert_to_streaming_response_async(response_object):\n    yield chunk","typeGuard":"def has_choices(payload: object) -> bool:\n    return isinstance(payload, dict) and isinstance(payload.get(\"choices\"), list) and len(payload[\"choices\"]) > 0","tryCatchPattern":"from litellm.exceptions import APIError\n\ntry:\n    async for chunk in convert_to_streaming_response_async(payload):\n        yield chunk\nexcept APIError as e:\n    if \"no 'choices'\" in str(e):\n        log.warning(\"skipping choices-less payload keys=%s\", list(payload.keys()))\n        return\n    raise","preventionTips":["Store complete response dicts (with choices) in caches, never metadata-only payloads","Skip usage-only final SSE chunks in custom adapters instead of converting them","Use the Raw keys in the error message to trace which producer emitted the bad payload"],"tags":["litellm","streaming","response-format","cache","provider-error"],"backgroundTag":"provider-response-missing-choices","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}