Fix HTTP 401 Unauthorized / Invalid API Key (5 Hidden Causes)

Still getting 401 with a fresh API key? Check trailing whitespace, Bearer vs x-api-key header mismatch, stale env vars, and key spend limits.

HTTP 401All APIs401 Unauthorized / Incorrect API key provided / Invalid authentication

Root Causes

Common Triggers

  • Sending a Brioi API key to api.openai.com because base_url was not updated
  • Mixing Authorization: Bearer with Anthropic’s x-api-key header on the wrong endpoint
  • Hidden whitespace, line breaks, or stray quotes in .env files
  • Per-key spend cap reached or key disabled in console

Long-Term Stability Path

Brioi lets teams issue isolated per-project keys and audit status and quota consumption in real time.

Step-by-Step Fix

  • Step 1 · Confirm base_url matches your key providerAlways pair Brioi keys with https://vip.brioi.com/v1 (or https://vip.brioi.com for native Anthropic).
  • Step 2 · Trim env strings & inspect active shellStrip accidental whitespace and confirm no global OPENAI_API_KEY overrides your .env.
  • Step 3 · Check per-key quota statusVerify the key is enabled and below its configured spend limit in vip.brioi.com.

Working Reference Snippet

All APIs · HTTP 401
curl -i https://vip.brioi.com/v1/models \
  -H "Authorization: Bearer ${BRIOI_API_KEY}"

FAQ

Are failed 401 requests billed?

Never—requests rejected at authentication incur zero charges.

More Troubleshooting Guides