Authentication Errors Across All AI Providers — 2026 Guide
Authentication errors are the second-largest error class in production AI applications after rate limits. Every provider handles auth differently — API keys, OAuth, IAM, Managed Identity, Entra ID. This is the cross-provider directory: every 401 and 403 pattern grouped by provider and mechanism.
Authentication is the second-largest error class in production AI applications after rate limits. Every provider handles it differently — Anthropic and OpenAI use static API keys; Google Gemini splits between simple keys (AI Studio) and cloud auth (Vertex AI); AWS Bedrock uses IAM; Azure OpenAI supports API keys, Entra ID tokens, and Managed Identity. This page is the cross-provider directory: every 401 and 403 pattern we've documented across every provider, IDE tool, and gateway, grouped so you can find your specific error in seconds.
For deep-dives on specific auth mechanisms, see the pillar guides linked in each section. For patterns around API key rotation and secrets management, see the observability chapter of the Cost Optimization Playbook. For related failure modes, see the Rate Limits category hub.
2026 auth mechanisms at a glance
Every provider takes a different approach to authentication. Use this table as a quick reference before diving into specific error patterns.
| Provider | Primary auth | Secondary | Token lifetime | Rotation |
|---|---|---|---|---|
| Anthropic Claude | API key (x-api-key header) | Workspace scoping | No expiry (until rotated) | Manual |
| Anthropic Claude Code | OAuth 2.0 + PKCE | API key fallback | Access ~1 hour, refresh ~30 days | Auto refresh |
| OpenAI | API key (Bearer token) | Project keys, Service accounts | No expiry (until rotated) | Manual |
| Google Gemini (AI Studio) | API key | None | No expiry (until rotated) | Manual |
| Google Gemini (Vertex AI) | Application Default Credentials (ADC) | Service account JSON, OAuth | ADC tokens ~1 hour | Auto (gcloud/SDK) |
| AWS Bedrock | IAM credentials | STS temporary, IAM roles, IRSA | STS 15 min – 12 hr configurable | Auto (STS) |
| Azure OpenAI | API key OR Entra ID token | Managed Identity, RBAC | Entra tokens ~60 min | Auto (Managed Identity) |
| IDE tools (Cursor/Copilot) | OAuth 2.0 + PKCE | PAT for enterprise | Session-based, varies | Auto refresh |
| Gateways (LiteLLM/OpenRouter/Portkey) | Gateway virtual key | Underlying provider key (BYOK) | No expiry (until rotated) | Manual |
Anthropic Claude
Claude uses simple API-key auth via the x-api-key header. Enterprise customers get workspace scoping and organization-level access controls. Auth errors are almost always one of three things: wrong key, expired/revoked key, or wrong workspace scope. Claude Code layers OAuth 2.0 on top for interactive workflows.
- 401 Invalid API keyWrong key, typo, or wrong environment
- 403 Permissions insufficientKey valid but lacks needed scope
- API key revoked / workspace access lostCommon after workspace admin change
- Organization not found (anthropic-organization header)Multi-org account misconfiguration
- Beta feature access denied (anthropic-beta header)Beta not enabled on account
OpenAI
OpenAI uses Bearer token API keys. Project keys (introduced 2024) scope access to specific projects; service account keys are for automated workflows. Country/region restrictions apply — some regions can't access certain models. Auth patterns changed materially in 2025 with the deprecation of user-scoped keys in favor of project-scoped.
- 401 Invalid Authentication (invalid_api_key)Bad key format or empty
- 401 Incorrect API key providedWrong key value, right format
- 403 Country / region not supportedGeo-restricted access
- Project API key access deniedKey scoped to wrong project
- Service account key permissions missingSA key needs explicit project role
Google Gemini
Gemini has two distinct auth paths. AI Studio uses simple API keys — easy for prototyping. Vertex AI uses Google Cloud auth (Application Default Credentials, service accounts, OAuth) — more secure but more complex. Choosing the wrong path for your deployment surface is the most common Gemini auth failure.
AWS Bedrock
Bedrock uses AWS IAM — no API keys, only IAM credentials (permanent or STS temporary). For serverless workloads, use IAM roles for service accounts (IRSA) or Lambda execution roles. For cross-account access, assume roles with STS. Auth failures typically manifest as AccessDeniedException — the fix depends on whether IAM policy, resource policy, or cross-account trust is the issue.
Azure OpenAI
Azure OpenAI supports three auth methods: API key (simplest), Entra ID (formerly Azure AD, more secure), and Managed Identity (best for Azure-hosted workloads — no secrets to manage). Enterprises typically move from API key to Entra ID as they mature. Managed Identity eliminates credential rotation entirely for Azure-native deployments.
Authentication at other layers of the stack
Auth failures don't only fire at the provider layer. IDE tools carry OAuth session state, gateways issue virtual keys, and frameworks wrap provider credentials — each layer adds its own failure modes.
IDE Tools
IDE tools (Cursor, Claude Code, GitHub Copilot) use OAuth 2.0 with PKCE for interactive sign-in. Session tokens refresh automatically until they don't — sign-in loops, expired refresh tokens, and SSO enforcement changes are the most common failure modes. Enterprise SSO adds another layer where org admin policy changes can invalidate all seat sessions simultaneously.
- Cursor sign-in loop / OAuth callback failsBrowser handoff not completing
- Cursor session expired — re-auth requiredRefresh token exceeded lifetime
- Claude Code 401 — OAuth token expiredclaude logout && claude login
- GitHub Copilot PAT expiredPersonal Access Token rotation
- Copilot org SSO authorization requiredSAML SSO re-auth after policy change
Gateway Layer
Gateways (LiteLLM, OpenRouter, Portkey) issue their own virtual API keys that sit on top of underlying provider keys. Virtual key revocation, budget-triggered auto-disable, and BYOK provider credential mismatches are the most common auth failures at the gateway layer.
Framework Layer
Frameworks (LangChain, LlamaIndex, MCP) don't have their own auth systems — they wrap provider SDKs. Auth failures at the framework layer are almost always environment variable misconfigurations, missing service context credentials, or MCP OAuth flow interruptions during agent runs.
Frequently asked questions
Why do I get 401 when my API key looks correct?
How do I rotate an API key without downtime?
What's the difference between API key auth and OAuth?
How do I use Entra ID (Azure AD) with Azure OpenAI?
Why does my STS token expire so quickly on Bedrock?
How do I authenticate from a serverless environment?
What are the best practices for API key storage?
Can I share API keys across environments?
What's the difference between service account and user account auth?
Why does auth work locally but fail in production?
Related resources
Deep dives, comparisons, and pillar guides related to authentication:
- Category Hub: Rate Limits (companion category)
- Pillar Guide: MCP Protocol (OAuth flows)
- Pillar Guide: Claude API Errors
- Pillar Guide: OpenAI API Errors
- Pillar Guide: AWS Bedrock (IAM auth)
- Pillar Guide: Azure OpenAI (Entra ID)
- Blog: The AI Errors Nobody Talks About
- Full errors library (330+ pages)
- Weekly digest — new auth patterns