Tickd.ai
API errors

How to Fix Claude API 401 Unauthorized Error

Updated 9/6/2026

The HTTP 401 Unauthorized error indicates that Anthropic's servers rejected your request because of an authentication failure. Unlike a 403 Forbidden error (which means your identity is verified but you lack permission to perform the action), a 401 error means the API does not recognize your credentials at all.

This issue usually stems from a missing environment variable, a syntax error in your authorization headers, an inactive API key, or a misconfigured SDK client initialization.

Follow these sequential troubleshooting steps to locate and resolve the authentication failure.

Step 1: Verify the Environment Variable Loading

Most SDK integration failures occur because the application cannot access the environment variable where your API key is stored. By default, the Anthropic SDKs search for an environment variable named ANTHROPIC_API_KEY.

To verify if your system is exposing this variable, run the following command in your terminal:

On macOS/Linux: `bash echo $ANTHROPIC_API_KEY `

On Windows (Command Prompt): `cmd echo %ANTHROPIC_API_KEY% `

On Windows (PowerShell): `powershell $env:ANTHROPIC_API_KEY `

If the terminal returns an empty line, your key is not set. You must export it. Add this to your shell profile (e.g., .bashrc, .zshrc) or run it in your active terminal session:

`bash export ANTHROPIC_API_KEY="your-actual-api-key-here" `

Note for developers using IDEs: Many development environments (like VS Code, PyCharm, or Xcode) do not automatically load system environment variables after they have been modified. Restart your IDE completely to force it to read the newly registered environment variable.

Step 2: Audit Your Manual HTTP Header Syntax

If you are calling the Anthropic API via raw HTTP requests (using tools like cURL, Postman, or custom HTTP libraries like Python's requests or Node's axios) rather than the official SDK, a minor formatting mistake will trigger a 401 error.

Anthropic does not use the standard Authorization: Bearer <key> format common to other AI APIs. Instead, it requires a custom header named x-api-key.

Ensure your raw HTTP headers strictly follow this structure:

`http POST /v1/messages HTTP/1.1 Host: api.anthropic.com x-api-key: your_exact_api_key_here anthropic-version: 2023-06-01 content-type: application/json `

Common manual errors include: 1. Prefacing the key with the word "Bearer ". 2. Capitalizing the header as X-API-Key on servers that strictly enforce lowercase headers. 3. Omitting the anthropic-version header, which can occasionally throw off validation processes.

Step 3: Check API Key Status in the Developer Console

An API key can be deactivated, deleted, or limited by account administrators.

  1. Log in to the [Anthropic Console](https://console.anthropic.com/).
  2. Navigate to the API Keys section.
  3. Locate the key you are currently using. Verify that its status is set to Active.
  4. If the key was recently generated, ensure no leading or trailing whitespace was accidentally copied. Even a single hidden space at the end of the string will cause the authentication server to reject the credential.
  5. If in doubt, click Create Key to generate a clean, new API key. Replace your existing key with this new one to isolate whether the issue was key-specific corruption.

Step 4: Resolve Billing and Workspace Suspensions

Sometimes, the Anthropic Console throws a generic 401 error if your workspace billing has been temporarily frozen or suspended due to a payment failure. The system treats calls from workspaces with unpaid balances as unauthorized.

  1. Inside the console, navigate to the Billing section.
  2. Ensure your account has sufficient credits or an active, valid credit card linked under payments.
  3. Check your workspace settings to confirm your account hasn't been locked or placed on a restrictive tier due to a lack of billing history.

When to escalate

If your API key is confirmed active, billing is fully funded, and a clean cURL request with direct headers still yields a 401 error, the issue may lie with an account-level restriction. Collect the exact timestamp of your failed request and the request-id header from the response metadata, then open a support ticket via the Anthropic Console help chat tool.

Quick fixes

  • Claude is down or not loading
  • Claude Pro billing or payment problem
  • Can't sign in to Claude

While you're here

Tickd is more than troubleshooting — these three are free and take seconds.

Agent BuilderDesign your own AI agent and export it to ChatGPT, Claude, Gemini or Grok.Build one free