BerriAI/litellm · error · ValueError

Error calling litellm.acompletion for generate_content: {e}

Error message

Error calling litellm.acompletion for generate_content: {e}

What it means

Catch-all from the async generate_content adapter: any exception raised while setting up or executing the underlying litellm.acompletion call (auth errors, bad params, transform failures, provider outages) is caught and re-wrapped as ValueError with the original message appended. The root cause is the chained exception text, not this wrapper.

Source

Thrown at litellm/google_genai/adapters/handler.py:102

                    )
                    return generate_content_response
                else:
                    # Transform streaming completion response to generate_content format
                    transformed_stream: Final = GOOGLE_GENAI_ADAPTER.translate_completion_output_params_streaming(
                        completion_response
                    )
                    if transformed_stream is not None:
                        return transformed_stream
                    raise ValueError("Failed to transform streaming response")
            else:
                # Transform completion response back to generate_content format
                generate_content_response = GOOGLE_GENAI_ADAPTER.translate_completion_to_generate_content(
                    cast(ModelResponse, completion_response)
                )
                return generate_content_response

        except Exception as e:
            raise ValueError(f"Error calling litellm.acompletion for generate_content: {e}")

    @staticmethod
    def generate_content_handler(
        model: str,
        contents: list[dict[str, object]] | dict[str, object],
        litellm_params: GenericLiteLLMParams,
        config: dict[str, object] | None = None,
        stream: bool = False,
        _is_async: bool = False,
        **kwargs: object,
    ) -> dict[str, object] | AsyncIterator[bytes] | Coroutine[None, None, dict[str, object] | AsyncIterator[bytes]]:
        """Handle generate_content call using completion adapter"""

        if _is_async:
            return GenerateContentToCompletionHandler.async_generate_content_handler(
                model=model,
                contents=contents,
                config=config,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the tail of the message after the colon — it contains the underlying acompletion error; fix that first
  2. Print the full traceback (`raise` inside except, or logging.debug) to see the original exception chain
  3. Validate inputs: contents must be Google generate_content shapes and the model must resolve to a supported provider
  4. Reproduce with litellm.acompletion directly using the mapped model string to isolate adapter vs provider issues

Example fix

# before
try:
    r = await agenerate_content(model='gemini-2.5-flash', contents=contents)
except ValueError as e:
    print(e)  # opaque wrapped message

# after
import traceback
try:
    r = await agenerate_content(model='gemini-2.5-flash', contents=contents)
except ValueError:
    traceback.print_exc()  # shows chained original_exception
    raise
Defensive patterns

Strategy: try-catch

Try / catch

try:
    r = await agenerate_content(model=m, contents=c)
except ValueError as e:
    log.exception("generate_content failed")  # preserves chained original
    raise

Prevention

When it happens

Trigger: Any failure inside litellm.acompletion invoked by the Google GenAI adapter: invalid API key for the mapped provider, malformed contents (not convertible to OpenAI messages), unsupported model name, or the streaming transform failure from the sibling raise in the same try block.

Common situations: Passing Google-SDK-style params (generation_config fields, safety_settings) the adapter cannot map; missing GEMINI_API_KEY/GOOGLE_API_KEY env vars; models renamed or not yet in the provider map after a version bump.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/c5bb63e82a49b947. Report an issue: GitHub.