← All fixes
401OpenAI / OpenAI-compatible· Auth

“Incorrect API key provided” (401) — how to fix

Incorrect API key provided
Quick answer

The API key is missing, malformed, revoked, or doesn’t match the base URL you’re calling. Check the key value, the Authorization header, and that the key belongs to the endpoint you’re hitting.

What causes it

How to fix it

  1. Regenerate the key and paste it cleanly (no surrounding whitespace).
  2. Confirm the Authorization header is exactly `Bearer <key>`.
  3. Make sure the key matches the base URL / provider you’re calling.
  4. Check your env var is actually loaded at runtime.
Running an agent?

When wiring an agent to a new provider, a 401 usually means the base URL and key don’t belong to the same provider — verify both point at the same endpoint.

FAQ

My key looks right but still 401s — why?

Most often the key is for a different provider than the base URL you’re calling, or an env var didn’t load so an empty value is being sent. Verify the key and the endpoint match.

Related errors

“The model does not exist or you do not have access”OpenAI / OpenAI-compatible · 404OpenAI “You exceeded your current quota” (insufficient_quota)OpenAI · 429