Lesson 2 of 6 in Foundations

Meet Claude — the API model

The API in one paragraph

You talk to Claude by sending an HTTP POST to the /v1/messages endpoint. The body includes a model name, a messages array (the conversation so far), and parameters like max_tokens. Claude responds with an assistant message. That's the whole API surface. Everything sophisticated is built on top of these two primitives: send messages, receive messages.

The messages array

A conversation is an ordered array of message objects. Each has a role and content. The array is stateless — YOU maintain the conversation history and re-send it every call. There is no server-side session. This means to have a multi-turn conversation, you append each new turn (user OR assistant) to the array and send the whole thing again next time.

Roles: system, user, assistant

System (a top-level parameter, not a message role): persistent instructions and role for Claude. User: what a human said (or a tool result). Assistant: what Claude said (or wants to do next). You'll only ever write user messages; assistant messages come back from the API and you store them in the array.

Good to know — In the Messages API, 'system' is a separate parameter, not an entry in the messages array. It's the same conceptual role you'd expect, just delivered separately.

A minimal API call (Python)

Here's the simplest possible call to Claude. In practice you'd use the anthropic Python SDK, but this is the raw shape.

import anthropic

client = anthropic.Anthropic()  # reads API key from env

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a helpful assistant.",
    messages=[
        {"role": "user", "content": "What's the capital of France?"}
    ]
)

print(response.content[0].text)
# → "The capital of France is Paris."

Response structure

Claude's response includes: content (an array of content blocks — usually text, sometimes tool_use), stop_reason (why the model stopped — end_turn, tool_use, max_tokens, stop_sequence), usage (input and output token counts, for cost tracking), and model / id metadata. The content is an array because a single response can mix text and tool_use blocks.

Key parameters

model: which Claude version. max_tokens: cap on output length (required). temperature: 0 to 1, controls randomness. system: the persistent system prompt. tools: tool definitions (for function calling). tool_choice: force a specific tool. stop_sequences: strings that halt generation early.

Takeaways

  • The API is stateless — you re-send full history each call
  • messages array holds the conversation; system prompt is a separate param
  • Response has content (blocks), stop_reason, usage
  • max_tokens is required and caps output length
  • Everything sophisticated builds on this simple shape
← PreviousNext →