# LLM API: 401 authentication_error — invalid x-api-key / Incorrect API key provided

**Code:** `authentication_error` · **Category:** API · **Seen on:** Anthropic, OpenAI

The LLM provider rejected your key.

## Meaning

The provider could not authenticate the key. Keys are tied to one provider and one workspace; they are also revoked automatically when found in public repositories.

## Common causes

- Wrong or revoked key
- Key from another provider
- Env not loaded
- Whitespace
- Using a key in the wrong header (x-api-key vs Authorization)

## Quick fix

1. Create a new key
2. Check env loading
3. Generate a new key in the provider console
4. Print the key length (not the value) to find stray whitespace

## Detailed fix by platform

### Shell

1. `echo -n "$ANTHROPIC_API_KEY" | wc -c` to spot stray characters

## How to diagnose

1. **Key** — Valid?
2. **Provider** — Right provider?
3. **Env** — Loaded?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/api/llm-invalid-x-api-key)
