Claude API key: how to get and connect it

What a Claude API key is, where to get one, how to send it with a request and how to connect the key and Base URL to Claude Code and SDKs.

· 5 min read

A Claude API key is the string the server uses to tell who sent a request. Claude Code, the SDKs, code editors and your own scripts all rely on it. Without a key, no request reaches the model, even when everything else is set up correctly.

This guide covers where to get a key, how to send it with a request, which variables Claude Code needs and how to store the key so it never ends up in a repository.

What a Claude API key is

Every connection to the Claude API has two parts: the address that requests go to and the key that proves access. The address is called the Base URL. A program appends /v1/messages to it and sends the request there together with the key.

Diagram: the key and the Base URL in a Claude API request
The address tells a program where to send the request, and the key proves that access is allowed.

A key works like a password for programs. You never type it into a sign-in screen; it travels in a header with every request. That is why anyone holding a copy of the key can send requests in your name.

Where to get a Claude API key

There are two routes. The first is to create a key yourself in the Claude Console, under API keys. You give it a name and, optionally, an expiry date, and the key is shown only once, so save it somewhere safe right away. The account needs a topped-up balance, and the service is open only in the supported countries.

The second route is a ready-made key together with an address. At Hummbit the key and Base URL appear in your dashboard right after you sign up. The same dashboard has a card that sets up Claude Code with one command, plus setup guides for other apps.

Dashboard card with one-command setup for Claude Code
In the dashboard, the key, the address and a ready command for Claude Code sit side by side.

How to send the key with a request

The Claude API accepts the key in one of two headers: x-api-key or Authorization: Bearer. Each request also carries the API version in the anthropic-version header and the content type in content-type. The quickest way to test a key is a short request from the terminal.

curl {BASE}/v1/messages \
  -H "x-api-key: {KEY}" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-sonnet-5-5", "max_tokens": 200, "messages": [{"role": "user", "content": "Hello"}]}'

Replace {BASE} with the address and {KEY} with your key. If the model answers with text, the key works.

The SDKs for Python, TypeScript and other languages set all headers for you. They only need the key and, when required, the address:

from anthropic import Anthropic

client = Anthropic(api_key="{KEY}", base_url="{BASE}")
reply = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=200,
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.content[0].text)

How to connect the key to Claude Code

Claude Code reads the key and the address from environment variables. ANTHROPIC_BASE_URL sets the address. The key can go in two ways: ANTHROPIC_AUTH_TOKEN sends it in the Authorization: Bearer header, and ANTHROPIC_API_KEY sends it in the x-api-key header.

Diagram of the Claude Code variables for the key and the address
One variable sets the address, the other two decide how the key is sent.

To keep the settings after the terminal closes, put them in the env block of settings.json inside the .claude folder in your home directory. On Windows that is your user folder.

{
  "env": {
    "ANTHROPIC_BASE_URL": "{BASE}",
    "ANTHROPIC_AUTH_TOKEN": "{KEY}"
  }
}

With ANTHROPIC_API_KEY, Claude Code asks once in interactive mode whether to use that key. After a restart, check the connection with /status: it shows the address and the variable that holds the key. Every setup option is covered in detail in the guide to the Claude Code Base URL.

The /status screen in Claude Code with the address and the key
The /status command shows which address and which key variable the session uses.

How to keep the key safe

  • Keep the key in your user settings or in environment variables, never in code.
  • Do not put the key in .claude/settings.json inside a project: that file often gets committed.
  • Do not share the key in chats or show it in screenshots.
  • If the key may have leaked, revoke it and create a new one.

FAQ

How is a key different from signing in to Claude?

Signing in through the browser ties Claude Code to your account plan. A key works without signing in: requests go to the address in ANTHROPIC_BASE_URL, and the plan windows do not apply to them. Read more in the guide to Claude and Claude Code limits.

Which model should I put in the request?

The current models are claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5 and claude-fable-5-2. We compared them and explained which one fits which task in the overview of Claude 5.5 models.

What does a 401 error mean?

The server rejected the key. Most often the key was copied with an extra space or stored in the wrong variable. Copy it again, check the variable name and open a new terminal.

Can one key work in several programs?

Yes: Claude Code, Cursor, OpenCode and your own scripts all accept the same key. Separate keys are still handier, because they show which program uses the tokens.

Where to go next

If you do not have a key yet, the shortest route is to sign up at Hummbit and take the key and address from your dashboard. After that, the Claude Code guide and the article on prompt caching will help, since caching noticeably cuts token use in long sessions. We share new walkthroughs and Claude tips on our Telegram channel @hummbit.

Try it with your own tools

Create an account, get a key and connect Claude Code or any other app in a few minutes.

More posts

All posts