← Back to Blog

Fix API Key 401 Unauthorized Errors: A Step-by-Step Checklist

Zivv9 min read
API key401troubleshooting

A 401 Unauthorized response means the server could not verify the identity attached to the request. It is usually unrelated to model quality or service capacity. The most common causes are an incomplete key, a malformed authorization header, a client still using an old key, or an account password being used where an API key is required.

Work through these checks in order before reinstalling anything.

Confirm You Have an API Key

A Zivv API key is created on the API Keys page and normally starts with sk-. None of these are API keys:

  • Your website password
  • A browser cookie
  • A payment or order number
  • The display name you gave a key

Paste the key into a plain-text editor and check for leading spaces, trailing spaces, or line breaks. Rich-text apps sometimes add invisible characters.

Test the Key Without Your Client

Bypass Claude Code, Codex, or a desktop client and request the model list directly:

curl https://zivv.pro/v1/models \
  -H "Authorization: Bearer sk-your-key"

Interpret the result:

ResultMeaningNext step
Model list returnedThe key worksCheck whether your client cached an old key
Still returns 401Key or header problemCopy the key again and check Bearer formatting
Cannot connectNot an auth resultCheck the domain, network, and proxy settings

OpenAI-compatible requests use Authorization: Bearer <KEY>. There must be one space after Bearer.

Check the Endpoint

Different tools do not always use the same base URL:

  • OpenAI SDKs, Codex, and most desktop clients normally use https://zivv.pro/v1
  • Claude Code uses ANTHROPIC_BASE_URL=https://zivv.pro without /v1

A wrong endpoint more often produces 404, but some clients construct an invalid path and surface it as a generic authentication failure. See the endpoint reference for current paths.

Make Sure the Client Uses the New Key

Many persistent 401 errors come from stale configuration:

  1. The terminal was not reopened after changing environment variables
  2. A system variable and shell variable contain different values
  3. The selected model still belongs to an older provider profile
  4. A Docker container or remote workspace never received the local variable

Claude Code users should reopen the terminal and compare both variables with the Claude Code guide. Codex users can follow the Codex guide.

Check Key Status and Access

In the console, verify that:

  • The key has not been deleted or disabled
  • Its expiry date has not passed
  • Its group is allowed to use the target endpoint
  • Account balance and key limits are available

Some clients turn several server responses into a generic “authentication failed” message. Usage records can show whether the request reached the platform.

If the Key May Be Exposed

Do not keep testing it and never send the complete key to support. Instead:

  1. Delete or disable the old key
  2. Create a replacement
  3. Update every place that used it
  4. Review recent usage for anything unexpected

Use separate keys for each teammate, project, and automation. If one key leaks, you can revoke it without interrupting everything else. Teams provides separate keys and spending limits.

Shortest Useful Checklist

  1. Confirm it is an sk- API key
  2. Request /v1/models with curl
  3. Check the Bearer header format
  4. Verify the endpoint for OpenAI tools versus Claude Code
  5. Restart the client or terminal
  6. Review key status, balance, and usage

If the issue remains, send support the time, client, endpoint, error text, and the last four key characters, never the full key. The error reference explains response fields, and the AI API quickstart covers a clean first setup.