BerriAI/litellm · error · ValueError

Invalid completion response: no choices found

Error message

Invalid completion response: no choices found

What it means

Transform guard in translate_completion_to_generate_content: the ModelResponse from litellm.completion has an empty choices list, so there is no content to translate into Google GenAI generate_content format.

Solutions

  1. The completion response contained no choices; retry the request or check the provider response for errors.
  2. Verify the request parameters are valid for the target model.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/google_genai/adapters/transformation.py:493 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at litellm/google_genai/adapters/transformation.py:493

    def translate_completion_to_generate_content(
        self,
        response: ModelResponse,
    ) -> dict[str, object]:
        """
        Transform litellm completion response to Google GenAI generate_content format

        Args:
            response: ModelResponse from litellm.completion

        Returns:
            Dict in Google GenAI generate_content response format
        """

        # Extract the main response content
        choice: Final = response.choices[0] if response.choices else None
        if not choice:
            raise ValueError("Invalid completion response: no choices found")

        # Handle different choice types (Choices vs StreamingChoices)
        if isinstance(choice, Choices):
            if not choice.message:
                raise ValueError("Invalid completion response: no message found in choice")
            parts = self._transform_openai_message_to_google_genai_parts(choice.message)
        else:
            # Fallback for generic choice objects
            message_content = getattr(choice, "message", {}).get("content", "") or getattr(choice, "delta", {}).get(
                "content", ""
            )
            parts = [{"text": message_content}] if message_content else []

        # Create Google GenAI format response
        generate_content_response: Final[dict[str, object]] = {
            "candidates": [
                {
                    "content": {"parts": parts, "role": "model"},

View on GitHub (pinned to 77b7c6c40c)