{"record":{"id":"bfa826b1ac50a8ae","repo":"BerriAI/litellm","slug":"error-calling-litellm-completion-for-generate-cont","errorCode":null,"errorMessage":"Error calling litellm.completion for generate_content: {e}","messagePattern":"Error calling litellm\\.completion for generate_content: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/google_genai/adapters/handler.py","lineNumber":163,"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.completion for generate_content: {e}\")\n","sourceCodeStart":145,"sourceCodeEnd":164,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/google_genai/adapters/handler.py#L145-L164","documentation":"Catch-all from the sync generate_content adapter: every exception thrown by the underlying litellm.completion call (and the streaming-transform raise above it) is caught and re-raised as ValueError('Error calling litellm.completion for generate_content: <original>'). Diagnose the appended original message, not the wrapper.","triggerScenarios":"Sync generate_content calls that fail inside litellm.completion: bad/missing API keys, contents that cannot map to OpenAI messages, unknown model→provider mapping, or the streaming transform ValueError from the same try block.","commonSituations":"Switching from the official google-genai SDK to litellm's adapter and carrying over unsupported kwargs; API key env var naming mismatches (GEMINI_API_KEY vs GOOGLE_API_KEY); stale model names.","solutions":["Inspect the suffix of the message / full traceback to find the true underlying error and fix that","Verify the model string and that the required API key env var is set for the resolved provider","Simplify: reproduce with litellm.completion(model='gemini/<model>', messages=[...]) to see the raw provider error","Update litellm if the failure is inside the transform itself"],"exampleFix":"# before\nexcept ValueError as e:\n    log(str(e))\n\n# after\nimport traceback\nexcept ValueError:\n    traceback.print_exc()  # original exception is chained\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    r = generate_content(model=m, contents=c)\nexcept ValueError as e:\n    # suffix after 'generate_content: ' is the real provider error\n    root = str(e).rsplit(\": \", 1)[-1]\n    handle(root)","preventionTips":["Set required GEMINI_API_KEY/GOOGLE_API_KEY in env","Reproduce failures with litellm.completion directly to bypass the wrapper"],"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"}