unicornAll work

Claude API basics

A structured request in, a structured response out — and picking a model by evals.

In short The API is how you reach Claude from your own code rather than a chat window. You send a structured request (which model, which messages, which tools) and get a structured response a program can parse. Plus — how to pick a model for the task, weighing smarts, speed and price.

Request model · messages tools · max_tokens system · temperature Claude Response text · stop_reason usage (tokens → cost) →→
Structure in — structure out.

Chat vs API

Chat is a conversation for a human; the thread ends when the tab closes. The API makes Claude a "part" of your application: the request goes out from code, the response comes back into code, a million times over for a million users. It's a different skill from prompting: what matters is the request structure, cost and limits.

The first request: messages.create

In the request you set: model (which model), messages (the dialogue as a list, each with a user/assistant role and content), max_tokens (the response cap in tokens — what a token is), optionally system (role and rules), tools, temperature (randomness).

Back comes a structured object: the text, the stop reason (stop_reason) and — important for cost — usage: how many tokens went in and out. That's what the bill is counted from.

Analogy: chat is a spoken question; the API is a filled-in form that returns a form answer a machine can read by fields.

Choosing a model

Models differ along smart ↔ fast ↔ cheap:

Model Profile
Opus the most capable, for the hardest tasks; pricier and slower
Sonnet balanced: strong yet fast/cheaper than Opus — the workhorse
Haiku the fastest and cheapest, for simple high-volume tasks
Fable another of the line for its own task profile

The rule: don't guess, measure. Take your real examples and run them — that's an eval: compare quality on YOUR task and see where a cheap model is already good enough. Often the expensive one isn't needed. Analogy: don't buy a truck to carry a carton of milk.

Cost and control

You pay per token — both input (prompt + context) and output (the answer). A long context = more expensive (agent context management). The Console has workspaces, limits and a Playground to keep spend predictable and try requests without code.

Where next

One request-response isn't an agent yet. To make Claude act (call tools, observe the result, decide the next step), requests are assembled into an agent loop → the agent loop and tools.

Related

The source is the Claude Platform 101 course. Related: the agent loop and tools, agent context management, next-token prediction.

All theory