How to Get a Claude API Key: Console Steps, Billing, First Call and Live X (Twitter) Data

By TwitterAPI.io Team•18 min read
Diagram of the four Claude Console steps to get a Claude API key (sign in, add credits, create key, copy once), then using ANTHROPIC_API_KEY and pairing it with TwitterAPI.io for X data
Getting a Claude API key: four Console steps, one environment variable, and a second key for live X (Twitter) posts.

This page is about getting and using the key itself: where it lives in the Claude Console, which key type to pick, what has to be in place for billing, how to make the first call, and how to fix the errors that stop people. It is not a price list. For per-token model prices, batch and prompt-caching discounts, read our Claude API pricing guide, and for subscription plans and Claude Code limits read the Claude Code pricing guide. It is also a sibling of our Grok API key guide, which walks through the same steps for xAI.

Every Console path, key format, header and billing rule below was read this session from Anthropic's own documentation at platform.claude.com/docs and the Claude Help Center at support.claude.com, and the facts are listed at the bottom of the page. Where Anthropic's documentation does not say something (for example, a free starter credit for new accounts), we say that plainly instead of repeating what third-party blogs claim.

We also measured what developers actually post about the key. We pulled 900 recent X posts that mention a Claude or Anthropic API key, plus the timelines of @AnthropicAI and @claudeai, and report the aggregates: what people ask about, how often keys appear in public, and how many tokens an X post costs when you send it to Claude. The last part of the page shows the pattern most readers are here for: a Claude key on one side, live X (Twitter) data on the other.

01 — Section

How to get a Claude API key in the Claude Console (4 steps)

Anthropic's docs page "Get your Claude API key" describes the flow, and the Console is the only place a usable key comes from. The Admin API can list keys, but the docs state it never returns a key's secret, only a redacted hint, and it cannot recover a lost key.

Step 1. Sign in to the Claude Console. Go to platform.claude.com and sign in, or create an account. The Console is Anthropic's developer platform: the Help Center describes it as the place where you create API keys, add users to your team, set up billing and try Claude in the playground. API access is subject to Anthropic's Commercial Terms of Service, and the API is only available from the countries listed on the supported regions page (platform.claude.com/docs/en/api/supported-regions).

Step 2. Fund the organization. Open Settings, then Billing (platform.claude.com/settings/billing). The Help Center article for new Console organizations says that to use the API and the playground you add usage credits, which includes a short form about your organization and use case, then your payment details. Max, Ultra and Team subscribers can link the Console organization to their plan and claim a monthly credit with no payment method. More on this in the billing section.

Step 3. Create the key. Open the API keys page (platform.claude.com/settings/keys) and click Create key. Name it after the project or machine that will use it, select an expiration (presets of 3 hours, 1 day, 7 days or 30 days, a custom duration, or Never), set Linked account to yourself or to a service account, and optionally select a workspace to scope the key to. If the Create key button is disabled, your Console role does not allow key creation; an organization admin has to change the role or create a service account key for you.

Step 4. Copy it once and store it. The Console shows the full key, which starts with sk-ant- (the docs' examples use sk-ant-api03-...), only at creation. Put it in a secrets manager or a local .env file that is excluded from git. If you lose it, you cannot view it again: create a new key and delete the old one.

That is the whole process. The sticking points are almost never the four clicks; they are billing (a key on an unfunded organization fails), the key type, and where the key ends up afterwards. The next sections cover each.

02 — Section

Personal, service account, or workspace key: which one to create

When you create a key you choose who it acts as. Anthropic's Authentication docs list three types, and the choice decides when the key stops working.

Key typeActs asScopeStops working when
Personal keyYou, with your rolesOne workspace, or every workspace your role can useYou leave the organization
Service account keyA service account (CI, servers, agents)One workspace, or what the service account can reachThe service account is removed
Workspace key (legacy)No one: belongs to the workspaceThat workspaceOnly when disabled, deleted or expired

Our reading of the docs' advice. Use a personal key for your own development and scripts, and a service account key for anything shared, because a shared personal key acts as one person and breaks when that person leaves. Anthropic calls the workspace key a legacy type and prefers the identity-backed ones, which stop working automatically when their owner is removed.

The workspace header trap. A key that is not scoped to a single workspace must send an anthropic-workspace-id header on every Claude API request. Without it, the docs say the API returns a 400 invalid_request_error with a message telling you to add the header or use a workspace-scoped key. If you only want one project, scope the key to one workspace when you create it and the header is unnecessary.

For production. The docs describe Workload Identity Federation as the alternative to long-lived keys: a workload on AWS, Google Cloud, Azure, GitHub Actions or Kubernetes exchanges its own identity token for a short-lived bearer token, so there is no static key to leak. For a side project or a first test, a personal key with an expiration is the practical choice.

03 — Section

Billing: credits come first, and is there a free Claude API key?

The Help Center article "How do I pay for my Claude API usage?" says Claude API and playground usage is billed through prepaid usage credits: you buy credits before you use the API, and if you run out you can no longer call the API or use the playground until you add more. Purchased credits are available immediately, cover API access, playground usage and Claude Code, expire one year from the purchase date, and are non-refundable. Auto-reload can top the balance up when it falls below a threshold you set. Some organizations are on monthly invoicing through Anthropic's sales team instead.

Spend caps by tier. The Rate limits docs place every organization on a usage tier with a monthly spend cap: Start $500, Build $1,000, Scale $200,000; the Custom tier has none. New organizations can start in an Evaluation tier with lower limits while account history builds. When the cap is reached, requests return HTTP 429 until the first day of the next month at 00:00 UTC unless you request a higher tier on the Rate limits page (platform.claude.com/usage/limits). You can also set your own lower spend limit on the Billing page.

Is there a free Claude API key? Not in the sense most posts mean. We found no current Anthropic page that grants new Console accounts a free starter credit: the Help Center article for new organizations tells you to add usage credits, and an older Help Center URL about claiming free credits (article 8994925) returned a 404 when we checked it this session. The documented no-cost route is the monthly API credit that comes with some Claude subscriptions:

PlanMonthly Claude API credit
ProNone
Max$100
Ultra$200
Team, Standard seat$20 per seat (pooled, capped at $500)
Team, Premium seat$100 per seat (pooled, capped at $500)

The table comes from the Help Center article "Monthly API credits for Max, Ultra, and Team plans". You claim the credit by linking one Console organization to your plan; it is spent before any purchased credits, unused credit expires at the end of each billing cycle, and it cannot be used in Claude Code or the Claude apps. The article says the offer appears after you have been on an eligible plan for seven days.

Beware "free keys" on X. 15.6% of the X posts with text in our sample mentioned "free" next to the key terms. A key someone hands out for free is a key that bills someone else's organization: either it was leaked, or it will be revoked. The only safe key is one you created in your own Console.

04 — Section

Claude API key vs a Claude Pro, Max or Ultra subscription (and Claude Code)

This is the most common confusion behind the query, and Anthropic answers it in a dedicated Help Center article: Claude paid plans and the Claude Console are separate products. A paid plan gives you Claude on the web, desktop and mobile with more usage; the Console is the developer platform that issues API keys. A paid subscription does not include API access, so if you want both you sign up for the plan and separately set up Console access. The one bridge is the monthly API credit on Max, Ultra and Team.

You haveCan you call the API with a key?What pays for it
Claude Pro onlyOnly after you fund a Console organizationPrepaid Console credits
Claude Max or UltraYes, after linking a Console organization$100 or $200 monthly API credit, then purchased credits
Team planYes, after an owner links one organizationPooled seat credit (up to $500), then purchased credits
Console account, no planYes, once credits are addedPrepaid credits or monthly invoice

Claude Code and the key. Claude Code can run on a subscription login or on a Console API key. Its Authentication docs list the order it picks credentials in: cloud provider settings first, then ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY, then an apiKeyHelper script, then CLAUDE_CODE_OAUTH_TOKEN, then Anthropic profiles, and last the subscription login from /login. In interactive mode Claude Code asks once whether to use an ANTHROPIC_API_KEY it finds.

The practical consequence. If you have a Max subscription but also left ANTHROPIC_API_KEY in your shell profile, Claude Code uses the key once you approve it, and usage bills the Console organization instead of your plan. The docs say to run unset ANTHROPIC_API_KEY to fall back to the subscription and to check /status to see which credential is active. Purchased Console credits do cover Claude Code; the monthly plan API credit does not.

What X shows. Claude Code came up in 31.4% of the X posts with text in our sample, and subscription-versus-API questions in 8.0%. If you are reading this page because Claude Code asked about an API key, the decision is simply which bill you want the usage on.

05 — Section

Your first call: ANTHROPIC_API_KEY, curl and the Python SDK

Set the key as an environment variable rather than pasting it into code. Anthropic's quickstart uses export ANTHROPIC_API_KEY="your-api-key-here", and every official SDK reads that variable automatically. On Windows PowerShell the equivalent is $env:ANTHROPIC_API_KEY="sk-ant-..."; in a project, a .env file loaded by your framework works the same way.

Raw HTTP. The Messages endpoint is POST https://api.anthropic.com/v1/messages. The API overview lists the headers: Authorization: Bearer <key> (the current form; x-api-key: <key> is the legacy fallback and is still supported), anthropic-version (required; the overview's example is 2026-10-21, while the quickstart's curl still sends 2023-06-01), content-type: application/json, and anthropic-workspace-id when the key is not scoped to one workspace. The SDKs send the authentication, version and content-type headers for you.

SDK versions. Anthropic's client SDK page lists the latest releases: Python anthropic 2.3.0, TypeScript @anthropic-ai/sdk 1.3.0, Go 2.4.0, Java 3.3.0, Ruby 2.3.0, PHP 1.3.0, C# 13.3.0, and the ant CLI 2.4.0. PyPI confirms anthropic 2.3.0, which needs Python 3.10 or newer. Install with pip install anthropic.

Model ids. The models overview lists claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5 and claude-fable-5-1, each with a 1M-token context window and 128K max output. The examples below use claude-haiku-5-5 because it is the lowest-priced current model and a key test does not need more. Prices per million tokens are in our Claude API pricing guide.

The Python version of the first call is in the code block below; it prints the reply and the token usage, which is the fastest way to confirm the key, the billing and the model id all work. The curl version follows the same pattern.

python
import anthropic

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

message = client.messages.create(
    model="claude-haiku-5-5",
    max_tokens=300,
    messages=[{"role": "user", "content": "Reply with one sentence: is my API key working?"}],
)

for block in message.content:
    if block.type == "text":
        print(block.text)
print(message.usage.input_tokens, "input tokens,", message.usage.output_tokens, "output tokens")
06 — Section

Claude API key not working? Error codes and fixes

When the first call fails, the HTTP status tells you which of the earlier steps went wrong. The Errors page in Anthropic's docs defines each code; the fix column is our reading of the cause for a key that was just created.

Status and typeWhat it meansUsual fix
401 authentication_errorKey malformed, revoked or expiredCheck for a stray space or quote; create a new key
400 invalid_request_errorBad request, a spend limit you set, or a missing workspace headerAdd anthropic-workspace-id or scope the key
402 billing_errorBilling or payment problemAdd credits or fix the card on the Billing page
403 permission_errorKey lacks access to that resourceCheck workspace and role settings
429 rate_limit_errorRate limit or monthly spend cap reachedBack off; request a higher tier if it is the cap

401 after it used to work. An expired key returns 401 authentication_error, and the docs say expired keys cannot be reactivated, only replaced. Anthropic emails the key's creator before expiry (7 days ahead for keys with a lifetime of 14 days or more, 1 day ahead for keys of 7 days or more); short-lived keys expire without warning.

429 that never clears. A spend-cap 429 carries no retry-after header and keeps failing until access resumes, unlike a normal rate-limit 429. The docs also mention acceleration limits: a sharp jump in usage from a new organization can produce 429s, so ramp traffic up gradually.

500, 504 and 529. These are on Anthropic's side (api_error, timeout_error, overloaded_error). The official SDKs retry transient failures twice by default with exponential backoff, and max_retries changes that. The Help Center says failed requests are not charged.

Claude Code says the key is invalid. Usually an old ANTHROPIC_API_KEY from a disabled or expired organization is still set in the shell; Claude Code's docs name this exact cause. Unset it and log in again.

In our X sample, posts reporting errors or a key that does not work were a small share (5.6% of posts with text); setup questions about where the variable goes were nearly six times as common (32.2%).

bash
export ANTHROPIC_API_KEY="sk-ant-api03-..."   # from platform.claude.com/settings/keys

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

# Newer style, same key: -H "Authorization: Bearer $ANTHROPIC_API_KEY"
# Latest API version per the docs: -H "anthropic-version: 2026-10-21"
07 — Section

Keep the key safe: expiration, rotation, and what we found on X

Anthropic's Authentication docs give the hygiene rules: store keys in a secrets manager, rotate them periodically, and disable or delete any key you suspect has leaked. On the API keys page, Disable is reversible and Delete is permanent (the key is archived). An expiration set at creation limits how long a leaked key stays usable, and it cannot be changed afterwards; the docs add that expiration is not a substitute for secret hygiene.

What the X sample shows. Of the 900 posts we collected, 78 mentioned the sk-ant prefix at all, and 29 (3.2%) contained a string that starts with sk-ant- and runs on for 30 or more key characters without placeholder text such as xxxx or .... We counted these and did not store, test or try any of them; some may be fakes, truncated, or already revoked. But the pattern is clear enough: keys end up in screenshots, pasted terminal output and code snippets.

Leaks and exposure were the explicit topic of 6.0% of posts with text, and GitHub came up in 17.0%: repositories are where .env files and hard-coded keys usually escape. The chart breaks down all eight topics.

A short checklist. Give each project its own key with a name that tells you where it lives. Pick an expiration that matches the job (30 days for a prototype, Never only for a key in a secrets manager you rotate yourself). Keep .env in .gitignore. Blur keys in screenshots and terminal recordings before you post them. Scope keys to one workspace and set a workspace spend limit so a leaked key has a ceiling. If a key was ever pasted anywhere public, delete it and create a new one; disabling is for keys you might want back.

Bar chart of topics in X posts about the Claude API key: environment variable 32.2%, Claude Code 31.4%, GitHub 17.0%, billing or credits 16.5%, free key 15.6%, subscription vs API 8.0%, leaked or exposed key 6.0%, errors 5.6%
Topics in 665 X posts with text that mention a Claude or Anthropic API key, collected in 2026. 29 of all 900 posts carried a full-length sk-ant- string (counted, not stored).
08 — Section

Pair your Claude API key with live X (Twitter) data

Claude does not read X on its own. To summarize what people post about a product, classify replies, or watch a keyword, you fetch the posts with an X data API and hand them to Claude with your key. The two keys work side by side: ANTHROPIC_API_KEY for the model, and a TwitterAPI.io key sent in the X-API-Key header for the data. Reads need no X account.

What the data side costs. TwitterAPI.io's tweet endpoints, including /twitter/tweet/advanced_search, cost 15 credits per tweet returned, which is $0.15 per 1,000 tweets; a full 20-tweet page costs $0.003, and a request that returns nothing is billed the 15-credit minimum ($0.00015). The official X API pay-per-usage rate card (docs.x.com/x-api/getting-started/pricing) charges $0.005 per post read, which is $5.00 per 1,000 posts, about 33 times more, and caps pay-per-usage at 3 million post reads a month. New TwitterAPI.io accounts that pass the automatic bot check get up to $1 of free credits (at most 100,000 credits, no card, one per person or network, expiring after 31 days); purchased credits never expire.

What the model side costs. We measured the posts in our sample: an X post averages about 190 tokens of text, about 233 tokens as a 7-field JSON record, and about 1,133 tokens as the raw API object (all estimates at 4 characters per token). Sending raw JSON makes the input bill about five times larger, so trim each post to the fields the task needs before it reaches Claude.

Model (list price per MTok in / out)Claude cost, 1,000 postsTotal with TwitterAPI.ioTotal with official X API
Claude Haiku 5.5 ($0.10 / $0.50)$0.03$0.18$5.03
Claude Sonnet 5.5 ($2 / $10)$0.63$0.78$5.63
Claude Opus 5.5 ($4 / $20)$1.26$1.41$6.26

The estimate assumes 1,000 posts as 7-field records in 20 requests of 50, a 300-token instruction per request and 15 output tokens per post, at Anthropic's list prices with no batch or cache discount (the Batch API halves token prices; prompt caching cuts repeated instructions further). For a classification job, the model is a small part of the bill when the posts come from TwitterAPI.io, and the data is most of it when they come from the official X API.

Rate limits on the data side. TwitterAPI.io allows 0.2 requests per second before the first payment and 20 once paid (50 on Scale, 500 on Business). The example below makes at most three search requests, so it fits the free tier. Full endpoint parameters are on docs.twitterapi.io, and the complete working script is in the code block at the end of the page.

Stacked bar chart: fetching and classifying 1,000 X posts costs about $0.18 with Claude Haiku 5.5 and TwitterAPI.io versus $5.03 with the official X API; $0.78 vs $5.63 for Sonnet 5.5; $1.41 vs $6.26 for Opus 5.5
Fetch plus Claude classification for 1,000 X posts, estimated from token counts measured on 900 posts collected in 2026, at list prices.
09 — Section

How we collected this

Question. What do people on X run into when they get and use a Claude API key, how often do keys appear in public, and how many tokens does an X post cost when sent to Claude?

Sample. 900 posts from TwitterAPI.io's /twitter/tweet/advanced_search (Latest) for the query "claude api key" OR "anthropic api key" OR ANTHROPIC_API_KEY OR "sk-ant", reposts excluded, spanning about 193 days back from collection (about 4.67 matching posts a day, with 113 in the most recent seven days). 235 posts were link-only (X tags them with the zxx no-language code), which is why topic shares are computed over the 665 posts with text. Languages: English 54.2%, link-only 26.1%, Chinese 10.0%, Japanese 4.8%. 21.7% were replies. Median post: 8 likes and 1,210 views.

Official accounts. We also read the latest 160 timeline posts of @AnthropicAI and @claudeai. Both post about once every two days (0.53 and 0.55 own posts a day). Posts about the API, Console, SDK or developer platform were 5.7% of @AnthropicAI's 141 own posts and 16.1% of @claudeai's 149. On @AnthropicAI those few developer posts drew a median of 5,940,975 views against 1,011,176 for its other posts; on @claudeai the medians were close (12,792 likes vs 13,076). Developer news is a small part of what these accounts post, so the Console docs and release notes are the place to watch for key and billing changes, not the timelines.

Method. Topics were assigned by keyword rules (a post can match several), key-shaped strings by a pattern match that skips placeholders, and tokens by a characters-divided-by-4 estimate rather than a tokenizer call. Cost figures use the list prices on Anthropic's pricing page, read the day we built this page.

What the sample cannot show. It is the most recent slice X search returned, not every post; keyword rules miss sarcasm and context; a key-shaped string is not proof of a working key; and token counts vary by language, so treat the cost table as an estimate. The study used 61 API requests and cost about $0.18.

Privacy. Collected in 2026. Aggregates only. Search authors are private individuals and are never named; raw search pages stayed off the repository, and the published sample keeps only de-identified rows (language, reply flag, likes, views, length, topics). Key-shaped strings were counted and never written anywhere. Only the two official Anthropic accounts are named.

python
import json
import os

import anthropic
import requests

TWAPI = "https://api.twitterapi.io"
HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
claude = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY


def search_posts(query, max_pages=3):
    """Latest X posts for a query; 20 per page, follow next_cursor."""
    posts, cursor = [], ""
    for _ in range(max_pages):
        r = requests.get(
            f"{TWAPI}/twitter/tweet/advanced_search",
            headers=HEADERS,
            params={"query": query, "queryType": "Latest", "cursor": cursor},
            timeout=30,
        )
        r.raise_for_status()
        body = r.json()
        posts += body.get("tweets", [])
        if not body.get("has_next_page"):
            break
        cursor = body.get("next_cursor", "")
    return posts


def slim(t):
    """Keep the 7 fields the model needs (about 233 tokens a post, not about 1,133 for raw JSON)."""
    a = t.get("author") or {}
    return {
        "text": t.get("text", ""),
        "createdAt": t.get("createdAt"),
        "lang": t.get("lang"),
        "likeCount": t.get("likeCount"),
        "retweetCount": t.get("retweetCount"),
        "replyCount": t.get("replyCount"),
        "author_followers": a.get("followers"),
    }


posts = [slim(t) for t in search_posts('"claude api" -filter:retweets lang:en')]
msg = claude.messages.create(
    model="claude-haiku-5-5",
    max_tokens=600,
    messages=[{
        "role": "user",
        "content": "Group these X posts into the 3 most common problems developers report, "
                   "with a count for each:\n" + json.dumps(posts, ensure_ascii=False),
    }],
)
print("".join(b.text for b in msg.content if b.type == "text"))
10 — Questions

Questions readers ask

Is a Claude API key the same as an Anthropic API key?

Yes. Anthropic's docs page says API keys for the Claude API are also called Anthropic API keys. Both are created in the Claude Console at platform.claude.com/settings/keys, both start with sk-ant-, and the SDKs read either from the ANTHROPIC_API_KEY environment variable.

Can I get a Claude API key for free?

Creating the key costs nothing, but it cannot make requests until the Console organization has credits. We found no current Anthropic page offering new accounts a free starter credit. Max ($100 a month), Ultra ($200) and Team plans include a monthly API credit; Pro does not. Never use a key someone shares publicly: it bills another person's account and is likely leaked or about to be revoked.

Does Claude Pro include API access?

No. The Claude Help Center says paid Claude plans and the Claude Console are separate products and the API is billed separately. Pro subscribers who want the API fund a Console organization with prepaid credits. Max, Ultra and Team plans include a monthly API credit that you claim by linking a Console organization.

Where do I find my existing Claude API key?

You can see your keys, their names and expirations on the API keys page in the Console, but not the full secret: the Console shows it only once, at creation. If you lost it, create a new key, update your app, and delete the old one.

How do I set ANTHROPIC_API_KEY?

On macOS or Linux run export ANTHROPIC_API_KEY="sk-ant-..." (add it to your shell profile or a git-ignored .env file to keep it); on Windows PowerShell use $env:ANTHROPIC_API_KEY="sk-ant-...". The official SDKs pick it up automatically, so anthropic.Anthropic() needs no arguments.

Why does Claude Code ask me about an API key?

Claude Code found ANTHROPIC_API_KEY in your environment. If you approve it, usage bills your Console organization instead of your subscription, because the key ranks above the /login subscription credential. Run unset ANTHROPIC_API_KEY to use your plan, and check /status to see which credential is active.

Why does my Claude API key return 401?

A 401 authentication_error means the key is malformed, revoked or expired. Check for stray spaces or quotes in the variable, confirm the key still shows as active in the Console, and create a new one if it expired; expired keys cannot be reactivated.

Can I use my Claude API key to read X (Twitter) posts?

Not directly. Claude has no built-in X access through the API key, so you fetch posts with an X data API and pass them to Claude. With TwitterAPI.io, 1,000 posts cost $0.15 (the official X API rate card lists $0.005 per post read, $5.00 per 1,000), and classifying them with Claude Haiku 5.5 adds a few cents by our token estimate.

11 — Further reading

Continue

Sources & further reading
More from this series
Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key

Already building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.