← Claude Mastery Latent Shelf · Ch.19

Course Study Guide · Part 4 · Building on the Claude Platform

Building with the Claude API: Fundamentals

Everything you build on Claude starts here: a request with messages, a response you read back, and the handful of knobs that shape it.

— the foundation

Part 1 of the API course (an 85-lesson developer course, split across four chapters here). This chapter covers accessing the API and the Messages request, multi-turn conversations and system prompts, and controlling output with temperature, streaming, and structured data.

Messages APIsystem promptsstreaming & structured data15 quiz questions
01Get connected

Models, keys, and your first request

Claude comes in a family — Opus (deepest reasoning), Sonnet (balanced, the everyday workhorse), and Haiku (fastest and cheapest) — and you pick per request by model. To call the API you get an API key from the Console and pass it to the SDK (or the x-api-key header over REST).

Key concept · The Messages request

A request to the Messages API carries: model, max_tokens (a cap on the response), an optional system prompt, and messages — an array of {role, content} objects alternating user and assistant. The response returns content blocks (text and, later, tool-use blocks), a stop_reason, and token usage. That single call is the atom every later feature builds on.

02Shape the conversation

Multi-turn conversations and system prompts

The API is stateless — it doesn't remember prior turns. You create a conversation by resending the growing messages array each time.

Key concept · Append the history; set the role in the system prompt

Multi-turn: after each exchange, append Claude's assistant reply and the next user message to the array and send it again — the whole history is the context. System prompts are separate from the message list: they set Claude's role, tone, expertise, and rules ("You are a support agent for Acme; be concise and cite the policy"). A good system prompt is the cheapest, highest-leverage way to steer behavior consistently across every turn.

03Control the output

Temperature, streaming, and structured data

Three controls shape how the response comes back.

Key concept · Determinism, latency, and machine-readable output

Temperature (0–1) trades determinism for variety: low for consistent, factual, extraction-style tasks; higher for creative range. Response streaming returns tokens as they're generated (server-sent events) so a UI can show text appearing live instead of waiting for the whole reply — important for perceived latency in chat apps. Structured data: when you need machine-readable output, ask for JSON and steer it — describe the exact schema, use examples, and (a reliable trick) prefill the assistant turn with an opening { so Claude continues in JSON. This is what lets Claude's output feed the next step in your program rather than a human reader.

★Test yourself

Chapter 19 quiz

Fifteen questions on the request, conversations, and output control. Answer first, then expand Show answer.

Part A · Multiple choice

Q1

Which model family member is the fastest and cheapest?

  • A Haiku
  • B Opus
  • C Sonnet
  • D They're identical
Show answer

A — Haiku. Opus is deepest reasoning; Sonnet is balanced.

Q2

What does the messages array contain?

  • A {role, content} objects alternating user and assistant
  • B Only the system prompt
  • C API keys
  • D Model weights
Show answer

A.

Q3

What does max_tokens control?

  • A A cap on the length of Claude's response
  • B The temperature
  • C The number of conversations
  • D The API key length
Show answer

A.

Q4

The Messages API is stateless. To have a multi-turn conversation you:

  • A Resend the growing messages array each turn
  • B Rely on the server to remember
  • C Open a new key each turn
  • D Can't have multi-turn chats
Show answer

A. The whole history is the context.

Q5

Where do you set Claude's role, tone, and rules?

  • A The system prompt
  • B max_tokens
  • C The API key
  • D temperature
Show answer

A. Separate from the messages list.

Q6

For consistent, factual extraction, set temperature:

  • A Low
  • B High
  • C Above 1
  • D It has no effect
Show answer

A — low. Higher temperature adds variety/creativity.

Q7

What does response streaming give you?

  • A Tokens as they're generated, so a UI shows text appearing live
  • B A cheaper request
  • C A different model
  • D Guaranteed JSON
Show answer

A. Better perceived latency.

Q8

A reliable trick to get JSON output is to:

  • A Prefill the assistant turn with an opening {
  • B Raise the temperature
  • C Remove the system prompt
  • D Ask twice
Show answer

A. Plus describe the schema and give examples.

Part B · True or false

Q9

The API response includes a stop_reason and token usage.

Show answer

True. Plus content blocks.

Q10

You get an API key from the Anthropic Console.

Show answer

True. Passed via the SDK or the x-api-key header.

Q11

A system prompt is just another item in the messages array.

Show answer

False. It's a separate top-level parameter.

Q12

Structured output lets Claude's response feed the next step of your program.

Show answer

True. Machine-readable rather than for a human reader.

Q13

You choose the model per request.

Show answer

True. Via the model parameter.

Part C · Short answer

Q14

Name the four core parameters of a Messages request.

Show answer

model, max_tokens, system (optional), and messages.

Q15

Name the three output controls covered.

Show answer

Temperature, response streaming, and structured data.