{"record":{"id":"db7eb74e3fdb74c4","repo":"BerriAI/litellm","slug":"failed-to-get-models-response-text","errorCode":null,"errorMessage":"Failed to get models: {response.text}","messagePattern":"Failed to get models: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/chat/gpt_transformation.py","lineNumber":711,"sourceCode":"\n        if api_base is None:\n            api_base = \"https://api.openai.com\"\n        if api_key is None:\n            api_key = get_secret_str(\"OPENAI_API_KEY\")\n\n        # Strip api_base to just the base URL (scheme + host + port)\n        parsed_url: Final = httpx.URL(api_base)\n        base_url = f\"{parsed_url.scheme}://{parsed_url.host}\"\n        if parsed_url.port:\n            base_url += f\":{parsed_url.port}\"\n\n        response: Final = litellm.module_level_client.get(\n            url=f\"{base_url}/v1/models\",\n            headers={\"Authorization\": f\"Bearer {api_key}\"},\n        )\n\n        if response.status_code != 200:\n            raise Exception(f\"Failed to get models: {response.text}\")\n\n        models: Final = response.json()[\"data\"]\n        return [model[\"id\"] for model in models]\n\n    @staticmethod\n    def get_api_key(api_key: str | None = None) -> str | None:\n        return api_key or litellm.api_key or litellm.openai_key or get_secret_str(\"OPENAI_API_KEY\")\n\n    @staticmethod\n    def get_api_base(api_base: str | None = None) -> str | None:\n        return (\n            api_base\n            or litellm.api_base\n            or get_secret_str(\"OPENAI_BASE_URL\")\n            or get_secret_str(\"OPENAI_API_BASE\")\n            or \"https://api.openai.com/v1\"\n        )\n","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openai/chat/gpt_transformation.py#L693-L729","documentation":"Raised when the GET {base_url}/v1/models request used to discover OpenAI-compatible models returns a non-success response; the response body text is embedded verbatim. Typically caused by a wrong api_base, an invalid/expired API key, or a backend that does not implement the /v1/models listing endpoint.","triggerScenarios":"Thrown at litellm/llms/openai/chat/gpt_transformation.py:711 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the response body in the message; verify the API key has permission to list models and the base URL is correct."],"exampleFix":null,"handlingStrategy":"try-catch","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"}