{"record":{"id":"c5bb63e82a49b947","repo":"BerriAI/litellm","slug":"error-calling-litellm-acompletion-for-generate-con","errorCode":null,"errorMessage":"Error calling litellm.acompletion for generate_content: {e}","messagePattern":"Error calling litellm\\.acompletion for generate_content: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/google_genai/adapters/handler.py","lineNumber":102,"sourceCode":"                    )\n                    return generate_content_response\n                else:\n                    # Transform streaming completion response to generate_content format\n                    transformed_stream: Final = GOOGLE_GENAI_ADAPTER.translate_completion_output_params_streaming(\n                        completion_response\n                    )\n                    if transformed_stream is not None:\n                        return transformed_stream\n                    raise ValueError(\"Failed to transform streaming response\")\n            else:\n                # Transform completion response back to generate_content format\n                generate_content_response = GOOGLE_GENAI_ADAPTER.translate_completion_to_generate_content(\n                    cast(ModelResponse, completion_response)\n                )\n                return generate_content_response\n\n        except Exception as e:\n            raise ValueError(f\"Error calling litellm.acompletion for generate_content: {e}\")\n\n    @staticmethod\n    def generate_content_handler(\n        model: str,\n        contents: list[dict[str, object]] | dict[str, object],\n        litellm_params: GenericLiteLLMParams,\n        config: dict[str, object] | None = None,\n        stream: bool = False,\n        _is_async: bool = False,\n        **kwargs: object,\n    ) -> dict[str, object] | AsyncIterator[bytes] | Coroutine[None, None, dict[str, object] | AsyncIterator[bytes]]:\n        \"\"\"Handle generate_content call using completion adapter\"\"\"\n\n        if _is_async:\n            return GenerateContentToCompletionHandler.async_generate_content_handler(\n                model=model,\n                contents=contents,\n                config=config,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/google_genai/adapters/handler.py#L84-L120","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the tail of the message after the colon — it contains the underlying acompletion error; fix that first","Print the full traceback (`raise` inside except, or logging.debug) to see the original exception chain","Validate inputs: contents must be Google generate_content shapes and the model must resolve to a supported provider","Reproduce with litellm.acompletion directly using the mapped model string to isolate adapter vs provider issues"],"exampleFix":"# before\ntry:\n    r = await agenerate_content(model='gemini-2.5-flash', contents=contents)\nexcept ValueError as e:\n    print(e)  # opaque wrapped message\n\n# after\nimport traceback\ntry:\n    r = await agenerate_content(model='gemini-2.5-flash', contents=contents)\nexcept ValueError:\n    traceback.print_exc()  # shows chained original_exception\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    r = await agenerate_content(model=m, contents=c)\nexcept ValueError as e:\n    log.exception(\"generate_content failed\")  # preserves chained original\n    raise","preventionTips":["Always log full tracebacks for wrapped adapter errors","Validate model name and API key env before the call"],"tags":["google-genai","error-wrapping","adapter"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}