{"record":{"id":"afa5f9359010f7b6","repo":"BerriAI/litellm","slug":"str-e-afa5f9","errorCode":null,"errorMessage":"str(e)","messagePattern":"str\\(e\\)","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"litellm/llms/chatgpt/chat/transformation.py","lineNumber":37,"sourceCode":"        api_key: str | None = None,\n        api_base: str | None = None,\n        custom_llm_provider: str = \"openai\",\n    ) -> None:\n        super().__init__()\n        self.authenticator = Authenticator()\n\n    def _get_openai_compatible_provider_info(\n        self,\n        model: str,\n        api_base: str | None,\n        api_key: str | None,\n        custom_llm_provider: str,\n    ) -> tuple[str | None, str | None, str]:\n        dynamic_api_base: Final = self.authenticator.get_api_base()\n        try:\n            dynamic_api_key: Final = self.authenticator.get_access_token()\n        except GetAccessTokenError as e:\n            raise AuthenticationError(\n                model=model,\n                llm_provider=custom_llm_provider,\n                message=str(e),\n            )\n        return dynamic_api_base, dynamic_api_key, custom_llm_provider\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        validated_headers: Final = super().validate_environment(\n            headers, model, messages, optional_params, litellm_params, api_key, api_base","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/chatgpt/chat/transformation.py#L19-L55","documentation":"Not a raised string itself — this is the chat-path re-wrap: `GetAccessTokenError` from the authenticator is converted to a litellm `AuthenticationError` whose message is `str(e)` of the original auth failure. Any device-flow/refresh failure (errors 1404–1415) surfaces through here on chat completion calls with the `chatgpt` provider.","triggerScenarios":"Calling `litellm.completion(..., model=\"chatgpt/...\")` (chat endpoint) when the authenticator cannot produce an access token: expired/revoked tokens, failed refresh, network failure during refresh, or never-completed device login.","commonSituations":"First use of the chatgpt provider without having logged in; expired auth file after long idle; servers where the interactive device flow was never completed; users expecting an API key pattern where ChatGPT requires OAuth.","solutions":["Complete the ChatGPT device login flow once so a valid auth file exists, then retry.","If previously working, the refresh token likely expired/revoked — re-login to mint fresh tokens.","Check network reachability of OpenAI auth endpoints from the runtime host.","If you cannot use OAuth in your environment, use the `openai/` provider with an API key instead of `chatgpt/`."],"exampleFix":"// before\nlitellm.completion(model=\"chatgpt/gpt-4o\", messages=[...])  # raises AuthenticationError\n\n// after (one-time interactive login first, then call)\n# python -m litellm  # or the documented chatgpt login entrypoint\nlitellm.completion(model=\"chatgpt/gpt-4o\", messages=[...])","handlingStrategy":"try-catch","validationCode":"import os\n\ndef chatgpt_auth_ready() -> bool:\n    path = os.path.expanduser(\"~/.litellm/chatgpt_auth.json\")  # adjust to your auth-file location\n    return os.path.exists(path)","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"chatgpt/...\", messages=msgs)\nexcept litellm.AuthenticationError as e:\n    logger.error(\"chatgpt auth failure: %s\", str(e))\n    prompt_relogin_or_fallback_to_openai_api_key()","preventionTips":["Complete device login once and verify the auth file exists before serving traffic.","Catch AuthenticationError and route to an api-key provider as a fallback.","Monitor token age and proactively re-login before expiry."],"tags":["chatgpt","auth","oauth","completion"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}