GrabAICredits (GrabAICredits)Submit a deal

How to Get an Anthropic API Key (Claude API Key) in 2026: Steps, Credits & Free Options

Verified ·14 min read

You create an Anthropic API key (also called a Claude API key) in the Claude Console: sign in at platform.claude.com, open the API keys page, click Create key and copy the key, which starts with sk-ant- and is shown only once. The Claude API is prepaid, so you also need credits on the Billing page before requests succeed. There is no ongoing free API tier: Anthropic's pricing FAQ says only that new users receive a small amount of free credits to test the API, without stating an amount. Larger included API credits come with the Max 5x, Max 20x and Team plans.

This guide walks through each step with the exact Console names, shows how to set the ANTHROPIC_API_KEY variable on macOS, Linux and Windows, makes a first test request, explains what requests cost, and lists the errors people hit most often with their fixes. Everything was checked against Anthropic's documentation and help center on October 17, 2026.

What you need before you start

  • A Claude Console account. This is separate from a claude.ai chat subscription. You can sign in to the Console with the same email, but a Pro or Max plan does not by itself give you API access or API credits.
  • A payment card, or included credits. Anthropic's pricing FAQ says major credit cards are accepted for standard accounts, and enterprise customers can arrange invoicing. If you have Max 5x, Max 20x or Team, you can link a Console organization to receive monthly credits instead of paying by card.
  • The right Console role. Buying credits needs an Admin or Billing role. If you were invited to someone else's organization and the Create key button is greyed out, your role doesn't allow key creation.
  • A place to keep the secret. A password manager or a secrets manager. You only see the key once.

Step 1: Create your API key in the Claude Console

  1. Go to platform.claude.com and sign in, or create a Claude Console account.
  2. Open the API keys page at platform.claude.com/settings/keys.
  3. Click Create key, give the key a name, choose an expiration, and set Linked account to yourself (a personal key) or to a service account. You can also scope the key to a workspace.
  4. Copy the full key right away and store it in a password manager or secrets manager. The Console shows the key only once, at creation. If you lose it, you cannot view it again, so you create a new key.

If the Create key button is disabled, your organization role probably doesn't allow key creation. Ask an organization admin to change your role or to create a service account key for you.

Which key type to choose

Key typeActs asStops working whenUse it for
Personal keyYou, with your roles and permissionsYou lose access to the organization (or to its single workspace)Your own development and scripts
Service account keyA service account, not a personThe service account is archived or removed from the workspaceCI pipelines, production services, agents
Workspace key (legacy)No one; it belongs to a workspaceIt expires, is disabled or deleted, or the workspace is archivedOlder setups only; Anthropic recommends the other two types

Anthropic's authentication docs explain why identity-backed keys are preferred: a personal or service account key stops working automatically when that person or workload is removed, so keys don't outlive their owners. A shared personal key acts as one person and breaks when they leave, so anything shared should use a service account.

Choosing an expiration

When you create a key you pick a preset expiration of 3 hours, 1 day, 7 days or 30 days, a custom duration, or Never for keys you keep in a secrets manager and rotate yourself. If your organization sets a maximum expiration policy, Never is not offered. Expiration is fixed at creation and can't be changed later. Anthropic emails the key's creator before expiry: 7 days ahead for keys with a lifetime of at least 14 days, and 1 day ahead for keys with a lifetime of at least 7 days. Shorter-lived keys expire without a warning. An expired key returns a 401 authentication_error and can't be reactivated; you create a new one.

Workspaces and the workspace header

A key scoped to a single workspace only works in that workspace, and requests can leave out the workspace ID. A personal or service account key that works across several workspaces needs the anthropic-workspace-id header on every Claude API request. You can find a workspace's ID in the ID column of the Workspaces page at platform.claude.com/settings/workspaces. For a first key, scoping it to one workspace is the simplest choice.

Step 2: Add credits (billing)

Claude API and Console playground usage is paid from prepaid usage credits. Without credits, requests fail with a credit-balance error.

  1. Sign in to the Console with an Admin or Billing role.
  2. Go to Settings > Billing, click Buy credits, enter an amount and confirm. Purchased credits are available immediately.
  3. Optional: in the Credit balance section, click Set up auto-reload. Enter a threshold in When credit balance reaches and a target in Bring credit balance back up to. If your balance is already at or below the threshold, you are charged right away to bring it back up to the target, plus applicable taxes. To stop it later, click Manage auto-reload, then Turn off.
  4. Recommended: in the Spend limits section of the Billing page, click Adjust limit (or Set limit) to cap monthly spend. Your own limit can't exceed your tier's cap.

According to Anthropic's help center, purchased credits expire one year after the purchase date, the expiry can't be extended, and all credit purchases are non-refundable. Expired credits show up in Invoice history on the Billing page. Anthropic doesn't publish a minimum purchase amount in that article. For per-token prices, see Claude API pricing.

Usage tiers and monthly spend caps

Every organization also has a usage tier with a monthly spend cap. Anthropic places organizations on a tier automatically based on usage history and account standing. New organizations may start in an Evaluation tier with lower limits that rise automatically as history builds. You can see your tier on the Rate limits page at platform.claude.com/usage/limits, and request more with Request tier increase on the same page.

Usage tierMonthly spend cap
Start$500
Build$1,000
Scale$200,000
CustomNo cap; arranged with Anthropic

When your organization reaches its tier cap, API usage pauses until 00:00 UTC on the first day of the next month unless you get a higher limit sooner. When it reaches a lower spend limit that you set yourself, requests fail until you raise or remove that limit. The troubleshooting section below shows how to tell these apart.

Step 3: Set the ANTHROPIC_API_KEY environment variable

The official SDKs read ANTHROPIC_API_KEY automatically, so you don't have to paste the key into your code. To set it for the current terminal session on macOS, Linux or WSL:

export ANTHROPIC_API_KEY="sk-ant-api03-..."

That only lasts until you close the window. To keep it for every new terminal, Anthropic's CLI docs append the line to your shell profile. For Zsh, the default shell on macOS:

echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.zshrc
source ~/.zshrc

For Bash:

echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.bashrc
source ~/.bashrc

On Windows, set a user environment variable, then open a new terminal so the change takes effect:

setx ANTHROPIC_API_KEY "sk-ant-api03-..."

A key saved in a shell profile is readable by anything that runs as your user, and it is easy to forget. If you later switch Claude Code back to a subscription, or rotate the key, remember to remove or update that line. For servers and CI, use your platform's secrets store instead of a profile file.

Step 4: Make a first test request

Direct HTTP requests send the key in the x-api-key header (Anthropic's docs say an Authorization: Bearer header also works). This request, from Anthropic's authentication docs, checks that the key and billing are working:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello, Claude"}]
  }'

A successful call returns JSON with a content array holding Claude's reply. An error returns a JSON body with an error type such as authentication_error; see the troubleshooting table further down.

Python

Install the official SDK:

pip install anthropic

Then call the API. This is the quickstart example from Anthropic's docs; the client picks up ANTHROPIC_API_KEY on its own:

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1000,
    messages=[
        {
            "role": "user",
            "content": "What should I search for to find the latest developments in renewable energy?",
        }
    ],
)

for block in message.content:
    if block.type == "text":
        print(block.text)

TypeScript or JavaScript

npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const message = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 1000,
  messages: [
    {
      role: "user",
      content: "What should I search for to find the latest developments in renewable energy?"
    }
  ]
});

for (const block of message.content) {
  if (block.type === "text") {
    console.log(block.text);
  }
}

The official SDKs retry transient failures (connection errors, rate limits and 5xx errors) twice by default with exponential backoff, and they honor the retry-after header when it is present.

What your first requests will cost

You pay per million tokens (MTok), with separate prices for input and output. These are the standard prices on Anthropic's pricing page for three current models:

Model (API ID)InputOutput
Claude Opus 5.5 (claude-opus-5-5)$4 / MTok$20 / MTok
Claude Sonnet 5.5 (claude-sonnet-5-5)$2 / MTok$10 / MTok
Claude Haiku 5.5 (prompts up to 100,000 tokens)$0.10 / MTok$0.50 / MTok

Worked example: a small app sends 1,000 requests a day, each with 2,000 input tokens and 500 output tokens. That is 2 million input tokens and 0.5 million output tokens a day.

  • Opus 5.5: 2 × $4 + 0.5 × $20 = $8 + $10 = $18 a day
  • Sonnet 5.5: 2 × $2 + 0.5 × $10 = $4 + $5 = $9 a day
  • Haiku 5.5: 2 × $0.10 + 0.5 × $0.50 = $0.20 + $0.25 = $0.45 a day

Two official discounts cut this further: the Message Batches API costs 50 percent less for work that doesn't need an immediate answer, and prompt caching makes repeated context much cheaper (cache hits on Sonnet 5.5 are $0.10 / MTok instead of $2). The full table, including cache-write prices and older models, is on our Claude API pricing page.

Is there a free Anthropic API key?

Only a small one. Anthropic's pricing FAQ says new users receive a small amount of free credits to test the API; it doesn't publish the amount, and there is no ongoing free tier. For extended enterprise trials, the FAQ points to Anthropic's sales team. Websites that hand out a free Claude API key are usually resellers or proxies, not Anthropic, and you'd be sending your prompts through a third party. These are the official ways to get Claude API credits without buying them directly:

RouteWhat you getNotes
Claude Max 5x$100 in API credits per monthClaim after 7 days on the plan by linking a Console organization in claude.ai Settings > Billing
Claude Max 20x$200 in API credits per monthCredits expire each billing cycle; no rollover
Claude Team$20 per Standard seat, $100 per Premium seat, pooled up to $500 per monthClaimed by a Team Primary Owner or Owner; discounted Nonprofit and Scientists Team plans also qualify
Claude for StartupsUp to $100K extra API credits via a partner VCDirect applications closed as of October 2026
Claude Campus programAPI credits for Builder Club leads to shareStudents only; 2026-27 applications have closed

Team credit example from Anthropic's docs: a team with three Standard seats and two Premium seats receives 3 × $20 + 2 × $100 = $260 a month. Adding another Premium seat raises the next month's credit to $360, and the pool never goes above $500. Included credits are spent before purchased credits, and an organization linked to an eligible plan moves up to at least the Start tier (or at least Build if its monthly credits are over $200).

The monthly API credits on Max and Team plans cover the Claude API, Managed Agents, the Agent SDK and the playground, but not Claude Code or extra usage in the Claude apps, and not Claude on Bedrock, Google Cloud or Microsoft Foundry. Free, Pro and Enterprise plans don't get them. Each plan links to one Console organization, and you can't change the link yourself, so pick the organization you'll build in. Compare plans on Claude pricing.

If you're comparing providers, our free AI API keys guide lists which APIs have real free tiers, and the Gemini API key guide covers Google's, which does have a free tier. For broader options, see how to get free AI credits.

Using your API key with Claude Code

Claude Code can use the same key. If ANTHROPIC_API_KEY is set, Claude Code asks once whether to use it, and if you approve, the key takes priority over your Pro or Max login. Usage then bills to your API credits instead of your subscription. In non-interactive mode (the -p flag), the key is always used when it is set. When you sign in to Claude Code with a Console account instead, Anthropic says a "Claude Code" workspace is created automatically in the Console for cost tracking.

To go back to your subscription, remove the variable in your shell (and delete it from your shell profile so it doesn't come back):

unset ANTHROPIC_API_KEY

Then start Claude Code and check which login is active with this command inside the session:

/status

Remember that Max and Team monthly API credits don't pay for Claude Code. If a Console organization holds only those credits, Claude Code shows a Credit balance too low message. See Claude Code pricing for which option costs less, and How to install Claude Code for setup.

Troubleshooting API key errors

The Claude API returns a JSON error with an HTTP status and an error type. These are the ones people run into most when setting up a new key, with the fix Anthropic's docs give for each.

What you seeWhat it meansWhat to do
401 authentication_errorThe key is malformed, revoked, disabled or expiredCheck that the whole key was copied with no spaces or quotes, check its status on the API keys page, and create a new key if it expired
400 with "Your credit balance is too low to access the Anthropic API"The organization has no usable creditsBuy credits or turn on auto-reload on the Billing page; included Max or Team credits expire at the end of each cycle
400 invalid_request_error starting "You have reached your specified API usage limits"You hit a spend limit you set yourself (or a workspace limit)Raise or remove the limit on the Billing page or the workspace settings
429 rate_limit_error with enforced_spend_limit_reachedYour tier's monthly spend cap is used upWait for 00:00 UTC on the 1st, or use Request tier increase; retrying won't help because this response has no retry-after header
429 rate_limit_error with a retry-after headerA per-minute rate limit (requests, input tokens or output tokens) was exceededWait the number of seconds in retry-after; ramp traffic up gradually
402 billing_errorA problem with billing or payment detailsCheck your payment details in the Console
403 permission_errorThe key isn't allowed to use that resourceCheck the organization's access and workspace settings, and send the workspace header for multi-workspace keys
529 overloaded_errorThe API is temporarily overloaded for all usersRetry with backoff; it isn't caused by your key
500 api_errorAn unexpected internal errorRetry with exponential backoff; contact support with the request ID if it persists

The key works in curl but not in my app

  • Your app was started from a shell or service that never loaded the variable. Environment variables set in one terminal don't reach programs launched elsewhere, such as an IDE opened from the Dock or a systemd service. Set the variable where that program starts, or pass the key from your secrets manager.
  • On Windows, a variable set with setx only appears in terminals opened afterwards. Close and reopen the terminal or editor.
  • Check for an older key that overrides the new one, for example a stale line in your shell profile or a .env file loaded by your framework.

I lost my key or think it leaked

The Console can never show a key's secret again, and Anthropic notes that the Admin API can't recover a lost key either; it only returns a partially redacted hint. Create a new key, switch your apps to it, then disable or delete the old one on the API keys page. Disable is reversible (you can re-enable the key), while Delete is permanent.

The Create key button is greyed out

Your role in that organization doesn't allow key creation. Ask an organization admin to change your role or to create a service account key for your workload. If you joined only to use Claude Code, the Claude Code role lets users create Claude Code keys only.

I'm getting rate limited on a brand-new account

New organizations can start in the Evaluation tier, whose limits sit below the standard Start-tier limits while account history builds. Anthropic says these limits rise automatically. Anthropic also notes that a sharp increase in usage can trigger 429 errors from acceleration limits, so ramp traffic up gradually.

API key safety tips

  • Never commit a key to Git or paste it into client-side code such as a browser or mobile app. Load it from an environment variable or a secrets manager on a server you control.
  • Pick an expiration when you create the key, and use service account keys for shared or production systems.
  • Give each project its own workspace with a workspace spend limit so one leaked key can't drain your whole balance.
  • Set an organization spend limit on the Billing page below your tier's cap.
  • Rotate keys periodically. For cloud workloads, Anthropic also supports Workload Identity Federation, which replaces long-lived keys with short-lived tokens from an identity provider you already use.
  • If a key leaks, create a new key in the Console, switch your apps to it, and disable or delete the old one. Lost keys can't be recovered.

Frequently asked questions

›Where do I find my Anthropic API key?

In the Claude Console at platform.claude.com/settings/keys. The full key is shown only once, when you create it. If you lost it, create a new key; neither the Console nor the Admin API can show an existing key's secret again.

›Is the Anthropic API free?

No, apart from a small amount of free credits for new users to test it, per Anthropic's pricing FAQ, which doesn't state the amount. After that the Claude API is billed per token from prepaid credits. Max 5x, Max 20x and Team plans include monthly API credits, and the Claude for Startups program has offered credits to selected startups.

›Does a Claude Pro subscription include API credits?

No. Per Anthropic's docs, the monthly API credits are for Max 5x ($100), Max 20x ($200) and Team (pooled, up to $500). Free, Pro and Enterprise plans aren't eligible.

›What does an Anthropic API key look like?

Keys start with sk-ant-. The example in Anthropic's docs is sk-ant-api03- followed by the secret.

›Why does my API call say my credit balance is too low?

Your organization has no usable credits. Buy credits or turn on auto-reload on the Billing page at platform.claude.com/settings/billing. If you rely on Max or Team monthly credits, they expire at the end of each billing cycle and don't pay for Claude Code.

›Do purchased API credits expire?

Yes. Anthropic's help center says purchased credits expire one year from the purchase date, the date can't be extended, and credit purchases are non-refundable.

›How long does an API key last?

As long as the expiration you chose at creation: 3 hours, 1 day, 7 days, 30 days, a custom duration, or Never if your organization allows it. A personal key also stops working if you leave the organization. Expired keys return a 401 error and can't be reactivated.

›Can I use my Claude API key in Claude Code?

Yes. Set ANTHROPIC_API_KEY and approve it when Claude Code asks. Usage is then billed at API rates from your purchased Console credits rather than counted against a Pro or Max plan. Max and Team monthly API credits don't cover Claude Code.

›Why am I getting a 429 error with plenty of credits?

Either you exceeded a per-minute rate limit for your usage tier, or your organization reached its tier's monthly spend cap. A rate-limit 429 includes a retry-after header; the spend-cap 429 doesn't, and it keeps failing until the 1st of the next month at 00:00 UTC or until your tier is raised.

Sources

Checked against these pages on Oct 17, 2026. Providers change offers often: always confirm on the official page before you rely on it.

  1. Official: Get your Claude API key (Claude Platform Docs)(platform.claude.com)
  2. Official: Get started with Claude (quickstart)(platform.claude.com)
  3. Official: How do I pay for my Claude API usage? (Claude Help Center)(support.claude.com)
  4. Official: API credits for Max and Team plans(platform.claude.com)
  5. Official: Rate limits and spend limits(platform.claude.com)
  6. Official: Claude Code authentication(code.claude.com)
  7. Official: Claude API pricing (FAQ: Are there free tiers or trials?)(platform.claude.com)
  8. Official: Authentication (key types, expiration, workspaces)(platform.claude.com)
  9. Official: Claude API errors(platform.claude.com)
  10. Official: CLI authentication (ANTHROPIC_API_KEY setup)(platform.claude.com)