{"record":{"id":"0b2369f53c416271","repo":"BerriAI/litellm","slug":"missing-gemini-api-key-set-the-gemini-api-key-or","errorCode":null,"errorMessage":"Missing Gemini API key. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable.","messagePattern":"Missing Gemini API key\\. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/vertex_llm_base.py","lineNumber":642,"sourceCode":"        3. Vertex AI with PSC endpoints - constructs full path structure\n           {api_base}/v1/projects/{project}/locations/{location}/endpoints/{model}:{endpoint}\n           (only when use_psc_endpoint_format=True)\n\n        Args:\n            use_psc_endpoint_format: If True, constructs PSC endpoint URL format.\n                                     If False (default), uses api_base as-is and appends :{endpoint}\n\n        ## Returns\n        - (auth_header, url) - Tuple[Optional[str], str]\n        \"\"\"\n        if api_base:\n            if custom_llm_provider == \"gemini\":\n                # For Gemini (Google AI Studio), construct the full path like other providers\n                if model is None:\n                    raise ValueError(\"Model parameter is required for Gemini custom API base URLs\")\n                url = f\"{api_base}/models/{model}:{endpoint}\"\n                if gemini_api_key is None:\n                    raise ValueError(\n                        \"Missing Gemini API key. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable.\"\n                    )\n                if gemini_api_key is not None:\n                    auth_header = {\"x-goog-api-key\": gemini_api_key}\n            else:\n                # For Vertex AI\n                if use_psc_endpoint_format:\n                    # User explicitly specified PSC endpoint format\n                    # Construct full PSC/custom endpoint URL\n                    if not (vertex_project and vertex_location and model):\n                        raise ValueError(\n                            \"vertex_project, vertex_location, and model are required when use_psc_endpoint_format=True\"\n                        )\n                    # Strip routing prefixes (bge/, gemma/, etc.) for endpoint URL construction\n                    model_for_url: Final = get_vertex_base_model_name(model=model)\n                    # Format: {api_base}/v1/projects/{project}/locations/{location}/endpoints/{model}:{endpoint}\n                    version: Final = vertex_api_version or \"v1\"\n                    url = \"{}/{}/projects/{}/locations/{}/endpoints/{}:{}\".format(","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/vertex_llm_base.py#L624-L660","documentation":"Raised while building a Gemini (AI Studio) URL with a custom api_base: the request carries no Gemini API key from param, litellm.gemini_api_key, or GEMINI_API_KEY/GOOGLE_API_KEY env — the endpoint would be unauthenticated.","triggerScenarios":"Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:642 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable.","Alternatively pass the key explicitly via the api_key parameter."],"exampleFix":null,"handlingStrategy":"validation","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-14T05:17:10.506Z"}