← Blog

How to Get a Claude API Key (and How to Use It)

2026-08-31 · 5 min read · SubToAPI Team

If you want to build with Claude programmatically, you need a Claude API key — a credential that authenticates your requests to Anthropic's API instead of the claude.ai chat interface. This guide walks through how to get one, what it costs, how to use it in code, and what to watch out for.

There are two separate ways people end up needing "Claude access": a personal claude.ai subscription for chatting in the browser, and an API key for calling Claude from your own application. They are billed differently and serve different purposes, which is the source of most confusion around this topic.

Getting a Claude API key from Anthropic

  1. Go to console.anthropic.com and sign up or log in.
  2. Navigate to the API Keys section of the console.
  3. Click Create Key, give it a name (e.g. production-backend), and copy the value immediately — Anthropic only shows it once.
  4. Add billing details. Anthropic's API is pay-as-you-go, priced per million input/output tokens, separate from any claude.ai Pro or Max subscription you might have.
  5. Store the key in an environment variable, never in source code.
export ANTHROPIC_API_KEY="sk-ant-..."

A basic request looks like this:

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-4-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Explain what a REST API is"}]
  }'

That's the direct path: create a key, fund it, call the endpoint.

Why a plain API key isn't always enough

An Anthropic API key is a single, flat credential. That's fine for a prototype, but it creates friction once you're building a real product:

For a side project, none of this matters. For a team shipping a product on top of Claude, it usually does.

Using SubToAPI instead of (or alongside) a raw API key

SubToAPI turns your existing Claude access into a proper HTTPS API layer, with application-level keys instead of one shared secret. You get:

A request through SubToAPI looks nearly identical to the direct Anthropic call, just pointed at a different host with your sub_live_ key:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Explain what a REST API is"}]
  }'

If you're already paying for Claude and just want a clean, key-based API in front of it — with per-app keys and usage tracking instead of managing raw Anthropic credentials yourself — /docs/quickstart walks through setup in a few minutes, and /docs/messages covers the request format in detail.

Securing your Claude API key

Whether it's a raw Anthropic key or a SubToAPI key, treat it like a password:

// server.js — never expose this key to the browser
const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "claude-sonnet-4-5",
    max_tokens": 1024,
    messages: [{ role: "user", content: "Summarize this ticket" }],
  }),
});

(Fix the typo above in real code — max_tokens should not have a stray quote.)

Choosing the right approach

Either path gets you talking to Claude programmatically — the right one depends on whether you're shipping a quick script or a product with real users behind it.

Questions

Is a Claude API key the same as a claude.ai login? No. A claude.ai login is for the web chat interface; an API key authenticates programmatic requests and is billed separately, per token.

How much does a Claude API key cost? There's no fee for the key itself — Anthropic charges per million input/output tokens consumed, varying by model. SubToAPI instead offers flat monthly pricing starting at €9 (Solo), see /pricing.

Can I use one API key across multiple apps? You can, but it's not recommended — it makes usage tracking and revocation harder. Per-app keys, like SubToAPI's sub_live_ keys, keep environments and applications isolated.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →