OpenAI API error
OpenAI API 401 Invalid Authentication: what it means and how to fix it
401 Invalid AuthenticationRetry? Not statedLast verified 2 documented fixes2 sources
What it means
Your authentication credentials are invalid. The Python library raises AuthenticationError when an API key or token is invalid, expired, or revoked.
Causes
- Using a revoked API key
- Using a different API key than the one assigned to the requesting organization or project
- Using an API key that does not have the required permissions for the endpoint being called
How to fix it
- Fix 1.
Check that you are using the correct API key and organization ID in your request header.
- Fix 2.
If unsure whether the key is valid, generate a new one and replace the old key in your requests.
More OpenAI API errors
All 23 OpenAI API errors400 invalid_request_error (Invalid service_tier argument)Retry? Not stated401 Incorrect API key providedRetry? Not stated401 You must be a member of an organization to use the APIRetry? Not stated401 IP not authorizedRetry? Not stated403 Country, region, or territory not supportedRetry? Not stated429 credit_balance_exhaustedRetry? No429 Rate limit reached for requestsRetry? Yes429 rate_limit_error slow_downRetry? Yes
HTTP 401 at other providers
Compare 401 across providers401 authentication_errorRetry? Not statedAnthropic API401 UnauthorizedRetry? Not statedAzure OpenAI401 UnauthorizedRetry? Not statedCohere API401 - Authentication FailsRetry? Not statedDeepSeek API401 authenticationRetry? NoGemini API401 UnauthorizedRetry? Not statedGroq API401 UnauthorizedRetry? Not statedMistral API401 authenticationRetry? Not statedOpenRouter401 UNAUTHENTICATEDRetry? NoVertex AI401 UnauthorizedRetry? Not statedxAI API
FAQ
What does the OpenAI API error "401 Invalid Authentication" mean?
Your authentication credentials are invalid. The Python library raises AuthenticationError when an API key or token is invalid, expired, or revoked.
How do I fix OpenAI API "401 Invalid Authentication"?
There are 2 documented fixes. Start with the first: Check that you are using the correct API key and organization ID in your request header.
Should I retry OpenAI API "401 Invalid Authentication"?
Not stated. The official docs do not say whether this error is retryable.
Which other AI APIs return HTTP 401?
Per their official error docs: Anthropic API (401 authentication_error), Azure OpenAI (401 Unauthorized), Cohere API (401 Unauthorized), DeepSeek API (401 - Authentication Fails), Gemini API (401 authentication), Groq API (401 Unauthorized), Mistral API (401 Unauthorized), OpenRouter (401 authentication), Vertex AI (401 UNAUTHENTICATED), xAI API (401 Unauthorized).
Sources
Last verified against 2 sources: OpenAI API's official docs and official SDK repositories.
- developers.openai.comhttps://developers.openai.com/api/docs/guides/error-codes
- github.comhttps://github.com/openai/openai-python/blob/main/README.md
Newsletter
Know when the APIs change
One email per week. New model releases, API changes, what broke, and how developers are working around it.