Check my levelCoursesProgramsFor teamsPricing
UKSign inSign up
Check my levelCoursesProgramsFor teamsPricingClaude quizPromptsBlogFAQSearchSign upUK
AcademlCoursesClaude API from A to ZThe Messages API structure
A user message with two content blocks, text and image, and the model’s replyClaude Code terminal: the claude -p command with Read and Edit allowedRetries after a 429 error: each pause is twice as long, then success
Course

Claude API from A to Z

Module 1 · Getting Started
01Your first API call02The Messages API structure03Choosing a model
Module 2 · Prompt Engineering for Claude
04Designing system prompts05The 1M context window06XML tags in prompts07Few-shot prompting
Module 3 · Tool Use
08Tool Use basics09Tool patterns10Multi-turn conversations11Computer Use and Browser Use
Module 4 · Production
12Streaming13Message Batches API14Prompt Caching15Vision16Production patterns
Claude API from A to Z · Lesson 2

The Messages API structure

system/user/assistant roles, content blocks (text, image), multi-turn conversations with thinking blocks, mid-conversation system messages, and strict JSON through structured outputs instead of prefill.

22 min readUpdated Nov 23, 20262 questions in quizReady prompt included

Three roles

  • system — instructions and behavior for the whole conversation, set with the top-level system parameter.
  • user — the user's turns.
  • assistant — the model's replies. You add these back into history for the next turn.
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // reads ANTHROPIC_API_KEY

const res = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 1024,
  system: "You are a concise technical assistant. Get to the point.",
  messages: [
    { role: "user", content: "What is idempotency?" },
  ],
});

for (const block of res.content) {
  if (block.type === "text") console.log(block.text);
}

Current Claude models use adaptive thinking by default, so thinking blocks may come before the text in res.content. Look for the block of type text; reading res.content[0].text is unreliable here.

The rest of this lesson opens after a free sign-up

Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.

Sign up freeOr a trial lesson, no sign-up →
In this lesson
Three rolescontent can be a string or an array of blocksMulti-turn conversationA system instruction mid-conversationStrict JSON without prefillPracticeReady promptQuiz
CoursesLLM coursesFor teamsPricingFAQBlogAboutPrivacy
© 2026 AcademlDevelopment & promotion —MMIX — Marketing Mix
Get started free