Claude AI API: A Practical Guide for Developers
What the Claude AI API Actually Is
The Claude AI API is Anthropic's programmatic interface to the Claude family of models — Claude Opus, Sonnet, and Haiku. Instead of chatting with Claude through a web browser, you send HTTP requests to an endpoint, and the model returns text, structured output, or tool calls that your application can use directly. It's the same underlying models that power claude.ai, but exposed as a JSON-in, JSON-out service you can wire into a backend, a CLI tool, a mobile app, or an automation pipeline.
If you're searching for "claude ai api," you're probably trying to do one of three things: get access for the first time, understand how requests and pricing work, or find a faster/cheaper way to call Claude from your own product. This article covers all three, plus a working code example you can copy right now.
How to Get Access
There are two practical paths:
- Anthropic's Console directly. You sign up at Anthropic's developer console, verify your account, add billing, generate an API key, and start making calls. This is the standard route and gives you direct access to every model Anthropic ships, at their listed per-token rates.
- A managed API layer on top of Claude. If you already have a Claude subscription (Pro or Max) and don't want to manage a separate Anthropic billing account, tools like SubToAPI convert that access into a standard HTTPS API with its own key, so you skip a second signup and a second bill.
Either way, once you have a key, the request shape is the same: you POST a JSON payload with a model name, a list of messages, and a max token limit, and you get back a completion.
Sending Your First Request
Here's a minimal request against the standard Messages format, which is what most Claude-compatible APIs (including Anthropic's own and SubToAPI) use:
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": "Summarize the plot of Dune in three sentences."}
]
}'
The response includes the generated text, a stop_reason, and token usage metadata so you can track cost per request. That last part matters more than it sounds — most production issues with the Claude API aren't about prompt quality, they're about not tracking usage until the bill arrives.
Streaming, Tools, and Real Applications
Two features come up constantly once you move past a demo:
Streaming. For chat interfaces, you don't want to wait for the full response before showing anything. The API supports server-sent events so tokens arrive incrementally and you can render them as they're generated. This is table stakes for any chat UI built on Claude.
Tool use (function calling). Claude can be given a set of tool definitions — JSON schemas describing functions your app exposes — and it will respond with structured calls to those tools instead of freeform text when appropriate. This is how you build agents that query a database, call an internal API, or run calculations, with the model deciding when a tool is needed.
A tool-enabled request looks like this:
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,
tools: [
{
name: "get_weather",
description: "Get current weather for a city",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"]
}
}
],
messages: [{ role: "user", content: "What's the weather in Lisbon?" }]
})
});
const data = await response.json();
console.log(data);
This example targets SubToAPI's endpoint specifically — the shape of the request is compatible with the standard Messages API, so if you already have code written against Anthropic's API, switching the base URL and key is usually the only change needed. See /docs/tools and /docs/streaming for the full parameter reference.
Understanding Cost and Access Models
The Claude API is priced per token — input tokens and output tokens are billed separately, and rates vary by model tier (Haiku is cheapest, Opus is most expensive, Sonnet sits in between). For teams already paying for Claude Pro or Max seats, running a separate pay-per-token API account means paying twice: once for the subscription, once for API usage.
This is the specific gap SubToAPI fills. It turns your existing Claude subscription into an API you can call with a sub_live_... key, so there's no separate per-token billing account to manage. Plans are Solo at €9/month for individual use, Team at €19/seat for shared projects with multiple keys, and Scale at €49/seat for larger teams that need usage metadata and centralized seat management. There's a free trial at signup, and every request returns the same usage data you'd expect from a production-grade API — token counts, model used, and stop reason — so you can monitor cost without building your own logging layer.
If you're evaluating whether to go direct through Anthropic or through a layer like this, the deciding factor is usually simple: are you already paying for Claude access, and do you want one bill or two? Check /pricing for the current breakdown, or start with the /docs/quickstart guide to see the exact request format before committing.
Getting Started Checklist
- Decide whether you need direct Anthropic API access (best for pure pay-per-token, high-volume production use) or a subscription-based API (best if you already pay for Claude and want to avoid duplicate billing)
- Generate an API key and store it as an environment variable, never in client-side code
- Test a basic Messages request before adding streaming or tools
- Add usage tracking from day one — token costs compound quickly once you're in production
- Read /docs/messages or Anthropic's own docs for the full parameter list before shipping
Questions
Is the Claude AI API the same as using Claude in the browser? It's the same underlying models, but accessed programmatically via HTTP requests instead of a chat UI. You control the prompt, parameters, and how the response gets used in your application.
Do I need a separate account to use the Claude API if I already have Claude Pro? Not necessarily. Anthropic's direct API uses separate token-based billing, but services like SubToAPI let you use your existing subscription as the API's backing access, avoiding a second account entirely.
What's the difference between streaming and non-streaming responses? Non-streaming returns the full completion in one response after the model finishes. Streaming sends tokens as they're generated via server-sent events, which is what you want for any real-time chat interface.