Skip to content
Petra Vlk

Dec 5, 202616 min read

An Anthropic API key is a secret string issued from the Claude Console, and you can paste it into tools like Activepieces when you want them to call the API on your behalf.

It's separate from a Claude.ai subscription: paying for chat doesn't give you API access, and API credit doesn't unlock chat.

The steps below follow Anthropic's documentation, checked on 5 December 2026. Anthropic can move menu labels, so trust the Console over this page if they differ.

You sign up at the Claude Console with an email address or a supported single sign-on login, and it creates an organization for you. Expect email verification, and possibly a phone check.

The Console account is a different login context from your Claude.ai chat account, so a working chat session proves nothing about API access.

1. Create an Anthropic API key in the Console

Add billing credits to your Anthropic API account

Before requests succeed, a new account needs a payment method or prepaid credits, because Anthropic bills calls to the organization. The Console's billing page shows whether your account carries any free allowance, and it's the only source worth trusting.

Without credit, expect a billing or credit-balance error on your first request, not a bad-key error. That's the first place people lose an afternoon.

  1. Open the Console and go to the API Keys page in settings.
  2. Click Create Key.
  3. Name it for the project that will use it, such as "invoice-bot-staging", so you can revoke the right one later.
  4. Copy it as soon as the Console reveals it. The Console shows the full value once, and afterwards only a truncated form.

If you lose it, you create a new key and delete the old one. You can't recover a lost key.

The Console shows the full value once, and afterwards only a truncated form.

Test your Anthropic API key with curl

Export the key as an environment variable, then send a minimal message:

export ANTHROPIC_API_KEY="paste-key-here"

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-sonnet-5-5","max_tokens":64,"messages":[{"role":"user","content":"Say hello"}]}'

You pay almost nothing for this test, because the small max_tokens value caps the reply. The anthropic-version header pins the API version, so omitting it gets you an error.

A JSON reply containing generated text means the key, the billing and the model access all work.

This takes minutes, not a project: automate it in Activepieces free.

2. What an Anthropic API key can access and what it costs

Whichever of four current Claude models a request names is the one you pay for, because a key grants access to the documented endpoints inside its workspace, not to one model. Nothing in the key itself pins a model.

A typo in the model field is the only thing between a cheap call and an expensive one.

To pick by job before you look at price, start with the table below. It comes from Anthropic's models overview, checked on 2026-12-04, which lists four current Claude models, what each is for and the batch discount they share.

Model Documented role Batch discount
Claude Fable 5.2 Demanding reasoning and long-horizon agentic work 50%
Claude Opus 5.5 Long-running agentic coding and knowledge work 50%
Claude Sonnet 5.5 (claude-sonnet-5-5) Best combination of speed and intelligence 50%
Claude Haiku 5.5 Fast, high-volume, latency-sensitive tasks 50%

Prices and plan limits checked against docs.claude.com and claude.com and openai.com and gemini.google on December 4, 2026.

Read context windows and per-model prices from the models page rather than from memory, because they differ. Table figures go stale.

Anthropic API price per million tokens

Send a prompt to Sonnet 5.5 and the input costs $2 per million tokens. That's about what a few thousand pages of text costs to send.

Output costs $10 per million, five times the input rate, making output the dominant cost factor. A workflow that asks for long answers from short prompts is therefore billed mostly on what comes back, not on what you sent.

Short card goes into a machine; a huge paper scroll pours out.

Anthropic API batch and caching price discounts

Send the work as a batch and the rate halves, so Sonnet 5.5 input falls to $1 per million, and output to $5 by the same rule.

The catch is that batch work isn't answered in real time, so it suits overnight jobs and not a user waiting on a reply.

On Sonnet 5.5, caching has three prices:

  • Cache write, 5 minutes: $2.50 per million, a 25% premium over plain input. You pay it to store a prompt briefly.
  • Cache write, 1 hour: $4 per million, double the input rate. You pay it to keep the prompt longer.
  • Cache read: $0.10 per million, one twentieth of the input rate. Every later call that reuses the stored prompt costs this.

60% more is what the 1-hour write costs over the 5-minute write. It only pays off if the prompt is reused after the five minutes have lapsed.

A prompt reused once, within minutes, gains nothing from the longer window. A large system prompt reused hundreds of times a day gets 95% off the input rate on every read.

One original note surrounded by many cheap copies.

3. Send a minimal working request to the Anthropic API

Before caching can pay off, a plain request has to work, and that request is one POST to the messages endpoint with three headers and a JSON body.

Anthropic API curl request fields explained

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-sonnet-5-5",
 "max_tokens": 256,
 "messages": [
 {"role": "user", "content": "Say hello in one sentence."}
 ]
 }'

New variable dialog in Activepieces showing name and value fields for storing an API key securely.

x-api-key carries the key. It's read from an environment variable so it never lands in your shell history or a file you might commit. anthropic-version pins the API contract, and the request is rejected without it. content-type tells the server the body is JSON.

In the body, model picks the model, and max_tokens caps the reply. That way a runaway answer can't bill past the limit you set. messages is the conversation so far, and it must open with a user turn.

With the Python SDK, the same call looks like this:

import anthropic

client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment

message = client.messages.create(
 model="claude-sonnet-5-5",
 max_tokens=256,
 messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(message.content[0].text)
print(message.usage)

You get the version and content-type headers for free, because the SDK sets them and picks up the key from the environment.

If the variable is empty, the failure arrives as an authentication error rather than a clear "you forgot to export it." Check echo $ANTHROPIC_API_KEY before you suspect the account.

Reading the Anthropic API response and token usage

When a call succeeds, it returns HTTP 200 and a JSON object. The reply text sits in content, a list of blocks. The first block's text field holds the words.

stop_reason tells you why generation ended: end_turn means the model finished, and max_tokens means your cap cut it off mid-thought.

You bill against the usage object. It reports input_tokens for what you sent and output_tokens for what came back. Log both on every call from the first day.

When a bill surprises you, those two fields per request show whether the cause was a long prompt, a long reply or too many calls.

If you'd rather not write that usage logging yourself, describe it to the built-in chat in Activepieces: say you want the input and output token counts from each Claude call recorded, and it builds and publishes the flow, the same artifact a builder would otherwise assemble by hand.

You don't hire for this, you describe it, and MoneyGram and Moneypenny run Activepieces in production.

That published flow sits under the same RBAC and audit logs as every flow a person built, and each run leaves a trace anyone can read, showing the input, the response and any error, with no certification needed to follow it.

The later sections store the key as a connection.

When caching is in play, the usage object also breaks out cache reads and writes, so you can confirm the discount from the previous section is actually being applied.

You can follow the rest of this with the builder open. Start free, no card.

4. Anthropic API rate limits by tier and the errors they cause

Once real traffic arrives, the same code that passed a test can start failing, because Anthropic caps each organization by usage tier, in requests, input tokens and output tokens per minute.

The response's usage object, including the cache fields, tells you what each call consumed against those caps.

Anthropic API tier limits and moving up tiers

At the start, a new organization sits on the lowest tier, and each tier carries its own per-minute ceilings for requests, input tokens and output tokens.

Tiers rise as you buy credits, so a prototype that never topped up is still on starter limits when launch traffic hits.

Read your current figures in the Console before launch rather than assuming them.

Separately from those per-minute caps, request size has its own ceiling. The Messages API accepts 128 MB per request, according to the Anthropic API docs, so a few large base64 PDFs can exceed it.

A workflow execution interface showing a completed two-step Square OAuth token revocation flow with HTTP configuration

The Batch API accepts 256 MB, which suits bulk jobs. The Files API accepts 500 MB, so upload large documents there and reference them instead of inlining them.

401 and 403: key and permission problems

Retry only when the failure is temporary, because everything else fails identically until you change something. The table shows each error's type name, its cause, and whether retrying can help.

Status Type Cause Fix Retry?
400 invalid_request_error Malformed body or bad parameter Correct the request No
401 authentication_error Missing, mistyped or revoked key Check the x-api-key header and the key's status No
403 permission_error Key lacks access to the resource Use a key from the right workspace or organization No
404 not_found_error Wrong model name or endpoint Fix the identifier No
413 request_too_large Body exceeds the endpoint's size cap Shrink it or move files to the Files API No
429 rate_limit_error A per-minute limit was exceeded Wait for the retry-after header's value Yes
500 api_error Internal error on Anthropic's side Retry with backoff Yes
529 overloaded_error The API is temporarily overloaded Retry with backoff Yes

Largest request each Anthropic API endpoint accepts

Read the two as different refusals. A 401 means the key never identified you, and a 403 means it did but was refused. Both are permanent until you change the key or its access, so retrying only burns time.

When a 429 arrives, it carries a retry-after header giving the seconds to wait. Honor it exactly; retrying sooner just extends the block.

For 500 and 529, use exponential backoff with jitter and a retry cap. Beyond that, put a queue in front of the API so bursts drain at your tier's rate instead of being rejected.

When the balance is empty, it surfaces as a 400 invalid_request_error saying the credit balance is too low. It doesn't arrive as a 402 or 429.

A retry loop keyed to status codes will therefore treat it as a bad request and give up, which is correct. Alert on this message separately and top up the balance.

5. Keep an Anthropic API key out of code and repos

Keep the key in an environment variable or a secrets manager, never in source, because a key that leaks spends your balance down just as surely as heavy traffic does.

Store the key as an environment variable

Set ANTHROPIC_API_KEY in your shell, your deploy platform's settings or a secrets manager, and let the SDK read it. Your code never contains the string, so it can't be committed by accident.

Keep any .env file in .gitignore before you create it, not after the first commit.

Never put the key in browser or mobile code. Anything shipped to a client can be read by whoever opens the network tab, so route those calls through your own server.

In the USENIX Security study, three developers had leaked a code secret, so leaks aren't rare. Don't plan on never making the mistake. Plan on being able to recover from it quickly.

Developers who have had a code secret leak

One key per environment, rotated on a schedule

Create separate keys for development, staging and production, and name each one in the Console after where it runs. A leak from a laptop then means deleting one key, not taking production down with it.

Three differently tagged keys, one per environment, one removed

The name also tells you which key to delete when the usage page shows something odd.

Rotate on a calendar, not only after an incident. Create the new key, deploy it, confirm traffic has moved, then delete the old one. A rotation you've practised is the one you can do calmly at 2 a.m.

Set a spend limit in the Console as well, using the controls Anthropic documents. A leaked key can then burn only up to that ceiling, not through your whole balance.

If a key leaks

Work through these in order, and don't stop to investigate before the first step:

  1. Delete the key in the Console. This stops further use immediately.
  2. Create a new key with a fresh name.
  3. Update the secrets manager and redeploy anything that read the old value.
  4. Check usage for calls you didn't make, noting the dates and models involved.
  5. Purge the key from git history, and treat any clone or fork as still holding it.

The order matters because deletion is the only step that stops the damage. Removing the key from git history does nothing if the key still works, and anyone who cloned the repository already has a copy.

After that, the usage review tells you whether the leak cost money. If it did, raise it with Anthropic support, quoting the key name and the timestamps of the unfamiliar calls.

6. Use your Anthropic key in Activepieces without code

You can call Claude from Activepieces without writing code. Paste the key once as a stored connection, and every flow refers to the connection by name.

The key never appears in a script, a repository or a shared document, and since flows are unlimited on every plan, including free, one connection can serve as many of them as you build.

This is optional. Everything above works without it, and if you already call the API from your own code, nothing here replaces that.

What it changes is where the key lives. A key pasted into a connection is one you can find, replace and delete in one place, which is the same rotation exercise as before with fewer files to search.

Add the Anthropic connection

Create the key in the Anthropic console first, as described earlier, and copy it when it's shown, because you won't be shown it again. In Activepieces, add an Anthropic step to a flow and choose to create a new connection when prompted.

Creating a project variable

Bringing your own key is what the Plus plan, at $20 a month, covers: every AI step then costs 1 credit, and the model charge lands on your Anthropic bill.

Give it a name that says which key it holds, such as the project and the environment, so that a key you revoke later can be matched to the connection that uses it. Paste the key into the field and save.

Don't reuse a key you already ship in code. Make one for this purpose, so that revoking it breaks one automation and nothing else.

Run a first action

Start with the smallest flow that proves the connection works: a trigger, one Claude step, and an end.

The canvas below shows that shape, a schedule trigger labelled "Every Hour" feeding a single AI step and then an End node, with the step picker open and filtered by "sheet" to list the spreadsheet integrations you could add next.

Activepieces workflow builder showing a test flow connecting an Every Hour schedule trigger to an Ask ChatGPT action, with…

Read the canvas as a map of the pattern, not a recipe. The AI step in that capture is ChatGPT, and yours will be the Anthropic integration.

For the action, choose the Anthropic integration's "Ask Claude", select your connection, pick a model and write a short prompt. Run the test and open the run trace.

A success shows you the input and the response. A failure shows the step that failed and the error it returned, which is where the 401, 403 and 429 cases from the errors section turn up.

Even through Activepieces, Anthropic's rate limit still applies to your tier, and the trace is how you find out you hit it.

Activepieces keeps its own allowance separately: the free plan includes 1,000 credits a month, and when they run out, flows stay on and runs wait until the credits refresh.

On Monday, work through these:

  1. Confirm the key in use is one made for this job, named for it, and not shared with any code.
  2. Create the Anthropic connection in Activepieces and save it under a name that identifies the key.
  3. Build the single-step flow and run it once. Open the trace and confirm the response.
  4. Check your usage and limits in the console against what the flow will do on its schedule.
  5. Write down the date you'll rotate the key, and which connection to update when you do.
Share

Build it

Set this up in minutes.

No code required. Connect your accounts, and Activepieces runs it from there.

Start free Talk to sales