BerriAI/litellm · error · AuthenticationError
str(e)
Error message
str(e)
What it means
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.
Source
Thrown at litellm/llms/chatgpt/chat/transformation.py:37
api_key: str | None = None,
api_base: str | None = None,
custom_llm_provider: str = "openai",
) -> None:
super().__init__()
self.authenticator = Authenticator()
def _get_openai_compatible_provider_info(
self,
model: str,
api_base: str | None,
api_key: str | None,
custom_llm_provider: str,
) -> tuple[str | None, str | None, str]:
dynamic_api_base: Final = self.authenticator.get_api_base()
try:
dynamic_api_key: Final = self.authenticator.get_access_token()
except GetAccessTokenError as e:
raise AuthenticationError(
model=model,
llm_provider=custom_llm_provider,
message=str(e),
)
return dynamic_api_base, dynamic_api_key, custom_llm_provider
def validate_environment(
self,
headers: dict,
model: str,
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
api_key: str | None = None,
api_base: str | None = None,
) -> dict:
validated_headers: Final = super().validate_environment(
headers, model, messages, optional_params, litellm_params, api_key, api_baseView on GitHub (pinned to 6c2dcb801b)
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/`.
Example fix
// before litellm.completion(model="chatgpt/gpt-4o", messages=[...]) # raises AuthenticationError // after (one-time interactive login first, then call) # python -m litellm # or the documented chatgpt login entrypoint litellm.completion(model="chatgpt/gpt-4o", messages=[...])
Defensive patterns
Strategy: try-catch
Validate before calling
import os
def chatgpt_auth_ready() -> bool:
path = os.path.expanduser("~/.litellm/chatgpt_auth.json") # adjust to your auth-file location
return os.path.exists(path) Try / catch
try:
resp = litellm.completion(model="chatgpt/...", messages=msgs)
except litellm.AuthenticationError as e:
logger.error("chatgpt auth failure: %s", str(e))
prompt_relogin_or_fallback_to_openai_api_key() Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to request device code: {exc}
- Polling failed: {exc}
- Timed out waiting for device authorization
- Token exchange failed: {exc}
- Refresh token failed: {exc}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/afa5f9359010f7b6.
Report an issue: GitHub.