Skip to content
Nilay Kabariya

Entry No.022·AI·Updated ·4 min read

Fix: Could not resolve authentication method (Anthropic / Claude SDK)

Anthropic's SDK can't find your key. The old and new wording, ANTHROPIC_API_KEY vs ANTHROPIC_AUTH_TOKEN, and the 401 you get when a key is in the wrong one.

What changed on Nov 18, 2026: Re-ran on @anthropic-ai/sdk 1.10.0 and Python anthropic 2.10.0: all results held.

The error, verbatim

Jump to the fix ↓
Error: Could not resolve authentication method. Expected either apiKey or authToken to be set.
Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted

# newer versions of the SDK:
Error: Could not resolve authentication method. Expected one of apiKey, authToken, credentials,
config, or profile to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted

# SDK 1.x:
Error: Could not resolve authentication method. Expected one of apiKey, authToken, credentials,
config, or profile to be set. Or for the "Authorization" header to be explicitly omitted
✓ Reproduced on Windows 11 Pro

The fix that worked

Put it in ANTHROPIC_API_KEY:

ANTHROPIC_API_KEY=sk-ant-...
Not it? Every cause, tested ↓

Tested on

@anthropic-ai/sdk
0.30.1, 0.128.0, 0.133.0, 0.134.0, 0.137.0, 1.1.0, 1.3.0, 1.4.0 and 1.6.0
anthropic (Python)
1.8.0; re-tested on 2.3.0, 2.4.0, 2.6.0, 2.9.0 and 2.10.0
Runtime
Node 24.14.0, Python 3.14.5
OS
Windows 11 Pro

✓ Last re-run on GitHub Actions · see the run · all repros

The SDK looked for credentials and found none. It checks two environment variables, ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN, and they are not interchangeable, which is where most of the confusion around this error comes from.

Which wording you have

SDK Message
JavaScript, older (0.30) …Expected either apiKey or authToken to be set.
JavaScript, 0.120 to 0.137 …Expected one of apiKey, authToken, credentials, config, or profile to be set.
JavaScript, 1.x (checked 1.1.0 and 1.3.0) Same, but it ends Or for the "Authorization" header to be explicitly omitted
Python (1.8, and 2.3.0 on November 2) TypeError: "Could not resolve authentication method. Expected one of api_key, auth_token, or credentials to be set…"

Note that Python raises it as a TypeError, which is easy to misread as a bug in your own code.

The fix

Put your key from the Anthropic Console in ANTHROPIC_API_KEY:

ANTHROPIC_API_KEY=sk-ant-...

If it’s in a .env file, it has to be loaded before the client is created, exactly as with OpenAI’s SDK:

import 'dotenv/config';
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic();

If the key is in .env and you still see this error, nothing is loading the file, or it’s being loaded from the wrong folder. The causes and fixes are the same as for OpenAI’s version of this error: OPENAI_API_KEY is missing or empty.

ANTHROPIC_API_KEY vs ANTHROPIC_AUTH_TOKEN

The SDK sends them in two different ways. From its own source code:

Variable Sent as
ANTHROPIC_API_KEY X-Api-Key: <your key>
ANTHROPIC_AUTH_TOKEN Authorization: Bearer <your token>

That table is for SDK 0.x. From 1.0.0, ANTHROPIC_API_KEY is sent as Authorization: Bearer <your key> too, so both variables now travel in the same header. On 1.3.0, re-tested on 24 Oct 2026 against a local server, a key in ANTHROPIC_API_KEY arrived with no X-Api-Key header at all. That matters if a proxy or gateway in front of the API reads X-Api-Key.

A normal Console key (sk-ant-…) belongs in ANTHROPIC_API_KEY. The token variable is for setups that authenticate with a bearer token instead of a Console key.

The 401 message no longer tells you which variable your key landed in. Re-tested on 21 Oct 2026 with SDK 0.137.0 (and 0.134.0, same result), and on 24 Oct 2026 with 0.137.0 and 1.3.0 (same four messages), with invented keys:

Where the key was What it looked like 401 message
ANTHROPIC_API_KEY a Console key (sk-ant-api03-…) invalid x-api-key
ANTHROPIC_API_KEY an OAuth token (sk-ant-oat01-…) invalid x-api-key until October 24; OAuth access token is invalid. on November 2
ANTHROPIC_AUTH_TOKEN a Console key (sk-ant-api03-…) invalid x-api-key
ANTHROPIC_AUTH_TOKEN an OAuth token (sk-ant-oat01-…) OAuth access token is invalid.
ANTHROPIC_AUTH_TOKEN anything else Invalid bearer token

So a Console key gives invalid x-api-key in either variable, and that message alone doesn’t prove the variable is right. Since November 2 the API also judges the value by its shape in either variable: an OAuth token gets OAuth access token is invalid. even from ANTHROPIC_API_KEY, so that message no longer proves the value went in as ANTHROPIC_AUTH_TOKEN. Check where it is: a Console key (sk-ant-api03-…) goes in ANTHROPIC_API_KEY. If it’s already there and you still get invalid x-api-key, the key itself is wrong or revoked. Invalid bearer token means the value went in as ANTHROPIC_AUTH_TOKEN. OAuth access token is invalid. means the value is an OAuth token, in either variable (since November 2).

When this post was first tested (September 2026), a key in ANTHROPIC_API_KEY got API key is invalid. instead. That wording is gone; the change was on the API side, since SDK 0.134.0 now returns the new wording too.

How this was tested

@anthropic-ai/sdk 0.30.1 and 0.128.0 (re-tested with 0.134.0 and 0.137.0 on 21 Oct 2026, and with 0.137.0, 1.1.0 and 1.3.0 on 24 Oct 2026, and with 1.9.0 and Python 2.9.0 on 17 Nov 2026, and with 1.10.0 and Python 2.10.0 on 18 Nov 2026) on Node 24.14.0, and the Python SDK 1.8.0 on Python 3.14.5, on Windows 11. Each wording was produced with no credentials set; the 401s came from the real API, with an invented key placed in each variable in turn. The header mapping was read from the SDK’s client.mjs, and on 24 Oct 2026 checked against a local server that recorded the headers each version sent. No real key was used.

November 2, 2026: re-run on GitHub Actions ubuntu-latest (Node 24.22.1, Python 3.14.4) with @anthropic-ai/sdk 1.3.0 and anthropic 2.3.0, invented values only. The wordings matched; a local server again saw ANTHROPIC_API_KEY arrive as Authorization: Bearer with no X-Api-Key, and the “both set” warning was printed. Against the real API, four of the five 401 rows matched; the OAuth-shaped value in ANTHROPIC_API_KEY now got OAuth access token is invalid.. The script and output are public. On November 3, the same run on @anthropic-ai/sdk 1.4.0 and anthropic 2.4.0 gave identical results (run).

November 9, 2026: re-run with @anthropic-ai/sdk 1.6.0 and anthropic 2.6.0 for Python (run 42515025560): the same error text with no credentials, both variables still sent as Authorization: Bearer, the same “both are set” warning, and the same three 401 messages from the API for Console keys, OAuth tokens and other values.

— N.K., end of entry No.022

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.088

    Responses.create() unexpected keyword argument: new names

    max_tokens, messages, response_format, seed: their names in OpenAI's Responses API, tested. Plus the 'proxies' TypeError from httpx 0.28.

    > TypeError: Responses.create() got an unexpected keyword argument 'max_tokens'

    AI6 min
  2. No.087

    Claude SDK: unexpected keyword argument temperature, betas

    Messages.create() got an unexpected keyword argument after an anthropic upgrade, plus what SDK 2.0 (October 21) breaks next. Python and TypeScript, tested.

    > TypeError: Messages.create() got an unexpected keyword argument 'temperature'

    AI5 min
  3. No.060

    Claude "temperature is deprecated for this model" (400)

    Switching to Claude Sonnet 5.5, Haiku 5.5 or Opus 4.7 breaks code that sets temperature, even temperature: 0. Every case tested, in Node and Python.

    > BadRequestError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"`temperature` is deprecated for this model."}}

    AI4 min

tip: paste the exact error text