Home / Learn / The Claude Code API, Explained

The Claude Code API, Explained

Claude Code is a terminal agent, but under the hood every action is a call to the same Anthropic Messages API you can use directly. That has a useful consequence: you control which endpoint it talks to, which key it bills against, and therefore what a session costs. This page explains the moving parts and links to the detailed setup guides.

What “Claude Code API” Actually Means

There is no separate product called the Claude Code API. Claude Code authenticates either through a Claude subscription (Pro/Max) or through an API key, and in API mode it sends standard Messages API requests - system prompt, conversation, tool definitions and tool results - to whatever endpoint its environment points at.

That endpoint is configurable. Two environment variables control everything: ANTHROPIC_BASE_URL (where requests go) and ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY (whose account pays). Point them at Anthropic directly, or at an Anthropic-compatible gateway, and Claude Code behaves identically.

Using Your Own API Key with Claude Code

Set the two variables in your shell profile or in ~/.claude/settings.json and start claude as normal. The full walkthrough with settings.json examples lives in our <a href="/learn/claude-code-api-key-setup/">Claude Code API key setup guide</a>.

One gotcha worth knowing: if ANTHROPIC_API_KEY is set in your shell, Claude Code bills at API rates even when you also have a subscription - the environment variable wins. Unset it if you intend to use your Pro/Max plan.

What a Claude Code Session Costs

Agentic sessions are token-heavy: every file read, tool result and diff lands in context. A focused hour can consume millions of input tokens, which is why prompt caching matters so much - repeated context is re-read from cache at a fraction of the price on supported endpoints.

We break down real per-session numbers, cache behaviour and how to keep long sessions affordable in the <a href="/learn/claude-code-api-costs/">Claude Code API costs guide</a>.

Direct Anthropic vs a Gateway

Direct Anthropic API access gives you usage-based billing and first-party support - the right default for teams with steady budgets. Independent gateways such as AI Prime Tech (not affiliated with or endorsed by Anthropic) resell access at flat or discounted rates and expose the same wire format, so Claude Code works by changing only the base URL and key.

Whichever route you choose, verify streaming works end-to-end and that the models you need are available under the exact IDs Claude Code requests - see <a href="/learn/use-claude-api-with-claude-code/">using the Claude API with Claude Code</a> for the full checklist.

# Claude Code with your own key + custom endpoint
export ANTHROPIC_BASE_URL="https://aiprimetech.io"
export ANTHROPIC_AUTH_TOKEN="sk-your-key"
claude

# or persist in ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://aiprimetech.io",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key"
  }
}

Frequently asked questions

Can I use Claude Code with my own API key?
Yes. Set ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) and optionally ANTHROPIC_BASE_URL in your environment or ~/.claude/settings.json, then launch claude. It will bill that key instead of a subscription.
Does Claude Code have its own API?
No - it uses the standard Anthropic Messages API. Anything that speaks that format, including Anthropic-compatible gateways, can serve Claude Code.
Why is Claude Code ignoring my subscription and charging my API key?
If ANTHROPIC_API_KEY is set in the shell, it takes priority over subscription auth. Unset the variable to use your Pro/Max plan.
Can I point Claude Code at a different endpoint?
Yes, via ANTHROPIC_BASE_URL. This is how gateways, proxies, and enterprise routing setups work with Claude Code unchanged.
Start using Claude in minutes

Get an API key — no Anthropic account or waitlist required.

Get your API key

AI Prime Tech is an independent API gateway. It is not affiliated with, endorsed by, or a reseller of Anthropic. Claude and related model names are trademarks of their respective owners.