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?
Does Claude Code have its own API?
Why is Claude Code ignoring my subscription and charging my API key?
Can I point Claude Code at a different endpoint?
Get an API key — no Anthropic account or waitlist required.
Get your API keyAI 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.