{"record":{"id":"ff74fa1eff3e4b4b","repo":"BerriAI/litellm","slug":"api-key-is-required-for-gemini-api-calls","errorCode":null,"errorMessage":"api_key is required for Gemini API calls","messagePattern":"api_key is required for Gemini API calls","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/realtime/transformation.py","lineNumber":135,"sourceCode":"                {\"text_tokens\": 0, \"audio_tokens\": 0},\n            ),\n        )\n        return usage_dict\n\n    def validate_environment(self, headers: dict, model: str, api_key: str | None = None) -> dict:\n        return headers\n\n    def get_complete_url(self, api_base: str | None, model: str, api_key: str | None = None) -> str:\n        \"\"\"\n        Example output:\n        \"BACKEND_WS_URL = \"wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent\"\";\n        \"\"\"\n        if api_base is None:\n            api_base = \"wss://generativelanguage.googleapis.com\"\n        if api_key is None:\n            api_key = get_api_key_from_env()\n        if api_key is None:\n            raise ValueError(\"api_key is required for Gemini API calls\")\n        api_base = api_base.replace(\"https://\", \"wss://\")\n        api_base = api_base.replace(\"http://\", \"ws://\")\n        # WebSocket connections do not support custom HTTP headers in all clients,\n        # so the API key must remain as a query parameter here. This is an accepted\n        # limitation; httpx is not used for WebSocket so MaskedHTTPStatusError\n        # already covers the main leak vector.\n        return f\"{api_base}/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key={api_key}\"\n\n    def map_model_turn_event(self, model_turn: HttpxContentType) -> OpenAIRealtimeEventTypes:\n        \"\"\"\n        Map the model turn event to the OpenAI realtime events.\n\n        Returns either:\n        - response.text.delta - model_turn: {\"parts\": [{\"text\": \"...\"}]}\n        - response.audio.delta - model_turn: {\"parts\": [{\"inlineData\": {\"mimeType\": \"audio/pcm\", \"data\": \"...\"}}]}\n\n        Assumes parts is a single element list.\n        \"\"\"","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/realtime/transformation.py#L117-L153","documentation":"Error \"api_key is required for Gemini API calls\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/gemini/realtime/transformation.py:135 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass api_key or set GEMINI_API_KEY/GOOGLE_API_KEY before opening the realtime session."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}