The API is the same Claude with a different meter and no interface. Use it when you want to automate a repeated task, build Claude into something, or when your usage is bursty enough that a subscription would bill idle weeks. Skip it if you just want to chat — a good client costs money and time, and Pro is simpler.
Three steps to a first call
- 1
Get a key
Create an account at the Anthropic Console, add a small amount of credit, and create an API key. Set a monthly spend limit while you are there; it is the cheapest insurance you will ever buy.
- 2
Send a message
Everything goes through one endpoint,
POST /v1/messages. You choose a model, set a maximum output length, and send a list of messages. - 3
Read the usage
Every response reports input and output tokens. Multiply by the model's rates and you know the cost of the call to the cent.
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-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "In three bullets, when is an API cheaper than a chat subscription?"}
]
}'import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "In three bullets, when is an API cheaper than a chat subscription?"}
],
)
for block in response.content:
if block.type == "text":
print(block.text)
u = response.usage
print(f"input={u.input_tokens} output={u.output_tokens}")
# Sonnet 5 at the time of writing: $2 / 1M input, $10 / 1M output
print(f"cost ≈ ${u.input_tokens * 2 / 1e6 + u.output_tokens * 10 / 1e6:.5f}")That call costs a fraction of a cent. The usage object is the whole cost-control story: every optimisation in lesson 8 is about making those two numbers smaller, or making the input tokens cheaper.
Two features to know before you build anything
- Prompt caching. Add
cache_controlto the stable part of a request — the system prompt, a big document, the tool list — and repeated calls read it from cache at about 10% of the normal input price. On a workload that re-sends the same 50,000-token document, that is the difference between a bill and a rounding error. Details: Anthropic's prompt caching docs. - Message Batches. Send up to thousands of requests as one batch, get results within a day, pay half price. Anything that does not need an instant answer — nightly reports, bulk classification, evaluations — belongs here. Details: Batch processing docs.
Knowledge check
Your app sends the same 40,000-token policy document with every user question. What cuts the bill most?