{"record":{"id":"9c1dafde919d9914","repo":"BerriAI/litellm","slug":"failed-to-fetch-models-from-gemini-status-code","errorCode":null,"errorMessage":"Failed to fetch models from Gemini. Status code: {response.status_code}, Response: {response.json()}","messagePattern":"Failed to fetch models from Gemini\\. Status code: (.+?), Response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/common_utils.py","lineNumber":397,"sourceCode":"            litellm_model_names.append(litellm_model_name)\n        return litellm_model_names\n\n    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:\n        api_base = GeminiModelInfo.get_api_base(api_base)\n        api_key = GeminiModelInfo.get_api_key(api_key)\n        endpoint: Final = f\"/{self.api_version}/models\"\n        if api_base is None or api_key is None:\n            raise ValueError(\n                \"GEMINI_API_BASE or GEMINI_API_KEY/GOOGLE_API_KEY is not set. Please set the environment variable, to query Gemini's `/models` endpoint.\"\n            )\n\n        response: Final = litellm.module_level_client.get(\n            url=f\"{api_base}{endpoint}\",\n            headers={\"x-goog-api-key\": api_key},\n        )\n\n        if response.status_code != 200:\n            raise ValueError(\n                f\"Failed to fetch models from Gemini. Status code: {response.status_code}, Response: {response.json()}\"\n            )\n\n        models: Final = response.json()[\"models\"]\n\n        litellm_model_names: Final = self.process_model_name(models)\n        return litellm_model_names\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        return GeminiError(status_code=status_code, message=error_message, headers=headers)\n\n    def get_token_counter(self) -> BaseTokenCounter | None:\n        \"\"\"\n        Factory method to create a token counter for this provider.\n\n        Returns:\n            Optional TokenCounterInterface implementation for this provider,\n            or None if token counting is not supported.","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/common_utils.py#L379-L415","documentation":"Error \"Failed to fetch models from Gemini. Status code: {response.status_code}, Response: {response.json()}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/gemini/common_utils.py:397 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the status code and response body in the error; the /models request was rejected.","Verify the API key is valid and has access to the Generative Language API."],"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"}