Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Claude
  • CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
  • Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
  • One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
  • Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
  • Hooks That Block Destructive Actions: a PreToolUse Gate That Allows, Asks or Denies
  • Choosing a Claude Code Extension: Skill, Hook, Rules File, Subagent, Slash Command or Plugin
  • Rolling Out Claude Code to a Team: Settings Precedence, dontAsk in CI, a Hook for Every-Time Rules and a Plugin for Five Repos
  • A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Configuring MCP Servers in Claude Code: A Command or a URL, Three Scopes, and Three Moves When One Breaks
  • The Claude Messages API: Your First Call, Field by Field
  • Claude Tool Use: How tool_use and tool_result Work in the Messages API
  • Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
  • Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
  • Claude Streaming Events: The Event Order, message_stop, Tool Arguments, Stop Reasons and a WebSocket Relay
  • Images, PDFs and Thinking Blocks in the Claude Messages API: Typed Blocks In, Typed Blocks Out
  • Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
  • Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives
  • Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back
  • Claude Cost Tracking From usage: Count Before, Cap During, Read After, Then Find the Line That Drives the Bill
  • Claude Cache Breakpoints: Where to Put cache_control, How to Move It With the Chat, and Why the Reads Stay at Zero
  • Claude Message Batches or Real Time: Choose by Who Is Waiting, Match by custom_id, Resend Only the Failures
  • Calling Claude Through Amazon Bedrock, Google Cloud and Microsoft Foundry: Same Call, Different Door
  • The Life Cycle of a Claude App: Six Phases, a Model That Retires, and a Release Gate for Every Change
  • Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
  • Content Boundaries and Schema Design for Claude: Fence the Input in a Tag, Let the Output Say I Don't Know
  • The Agentic Loop and stop_reason: Keep Turning on tool_use, Stop on end_turn, Cap the Turns
  • The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
  • Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line
  • Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service
  • Agent SDK Hooks for Deterministic Actions: PreToolUse, PostToolUse, and Four Hooks That Fail Silently
  • Memory and Context-Window Patterns for Claude Agents: Context Editing, Compaction and the Memory Tool
  • Reading an Agent Trace: Five Signatures, Five Missing Patterns, and How Long a Fact Must Live
  • Tool Descriptions for Claude: How Claude Picks a Tool, and How to Stop It Picking the Wrong One
  • Tool Input Schemas and Error Responses for Claude: Required Fields, Enums, is_error and a Retry Flag
  • Tool Response Shaping and a Lean Tool Set: Give Claude a Sticky Note, Not the Filing Cabinet
  • Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
  • Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
  • Built-in Tool, Custom Tool, Skill or MCP Server? Pick the Lightest One That Fits
  • System Prompt or User Turn: Where Each Instruction Goes, and Output Limits Your Code Enforces
  • Refine the Prompt One Line at a Time, Then Clean and Fence the Customer's Text
  • Prompt Revision Driven by Evals: Name the Cause, Change One Thing, Rerun the Whole Suite
  • Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
  • Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line
  • Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
  • Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
  • Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
  • Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
  • Six Ways a 200 Can Still Be Wrong: Hallucination, Refusal, Under-Acting, Context Loss, Format Drift and Inconsistency
  • Fix the Cause, Not the Symptom: Four Recovery Drills for an LLM App, Each Checked on a New Input
  • Integration Layer or Model Output? Three Taps and Three Questions to Find Where a Wrong Answer Lives
  • Which Test Layer Owns the Failure? Unit, Functional, Integration and End-to-End Tests for a Claude App
  • Designing an Overnight Document Pipeline on Claude: Batch Lane, Live Lane, a Cached Prefix and a custom_id Reconcile
  • Proving a Model Upgrade Is Ready: A Frozen Golden Set, a Calibrated Judge, the Right Layer and a Release Gate
  • From Requirement to Design for a Claude App: Eight Requirements, Five Elements and a Trace With No Gaps
  • Build a Claude Refund App: the Messages API, Two Tools, an MCP Server and a Hook in One Loop
  • Ship a Claude App: an Eval Gate, Two Guardrail Layers, a Cost Check From usage and a Pinned Model
  • Lab: a 30-Case Golden Set, a Calibrated Judge and a Per-Slice CI Gate on a Claude Refund App
  • Lab: Cut a Claude App's Bill by 62 Percent With Usage Data, Layered Cache Breakpoints and a Batch Job
  • Lab: Three Planted Bugs in a Claude App, a Vague Prompt, a Mistyped Tool Schema and a Broken Stream Handler
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Lab: Harden a Claude App, an Uncalibrated Judge, a Retry Loop That Retries Everything and a Hook Matcher With a Gap
  • Lab: Turn a Claude App Into a Reusable Template, One Pinned Model Id, No Key in Code and Evals Built From Data
  • Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
  • MCP Transports: stdio or Streamable HTTP, and Who Starts the Server
  • Deploying and Authenticating an MCP Server: Environment Keys for stdio, Bearer Tokens and Scopes for HTTP
  1. Blog
  2. /
  3. Claude
  4. /
  5. Building with the Claude API

Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives

A support agent stops sending every job to one model: routing goes to Haiku, replies to Sonnet, a twelve-step review to Opus. Then the same four old settings are sent to all three models to show why a model swap is a code change.

Chaand Sheikh

·27 November 2026Building with the Claude API

What you will learn

  • Match Haiku, Sonnet and Opus to a job by its latency, steps and cost
  • Write a simple first-guess model picker in Python
  • Spot request settings that newer models reject with an HTTP 400
  • Read a reply by block type so a leading thinking block doesn't break your code

Before you start

  • The Claude Messages API: your first call
  • Basic Python

A support agent works through tickets all day: it routes them, writes replies, and now and then reviews a refund policy, which takes twelve steps. Until now it has sent every job to one model, Opus, the most capable of the three.

It works at first. Then routing is slow because it waits on a big model, the simple jobs pay for depth they never use, and a new release arrives and the old request comes back with an HTTP 400. Two lessons sit in that story: pick the model per job, and when the model changes, the request can change with it.

A kitchen with three cooks

  • The prep cook is quick and handles many small jobs. That's Haiku, built for classification, extraction and routing.
  • The line cook makes the main dishes, fast. That's Sonnet, the best mix of speed and intelligence.
  • The head chef takes the long, hard recipe. That's Opus, for long-running agentic coding and knowledge work.

You wouldn't ask the head chef to chop every onion. And when the kitchen gets a new stove, you check how it works before you cook.

Each tier wins a different row

Haiku 5.5Sonnet 5.5Opus 5.5
Best forClassification, extraction, routingMost work: speed plus intelligenceLong-running agentic work
Latency (Models overview)FastestFastModerate
Price, input / output per million tokens$0.10 / $0.50$2 / $10$4 / $20
ThinkingAdaptiveAdaptiveAdaptive, always on
Default effortmediumhighmedium

Prices are first-party API list prices for prompts up to Haiku's 100K-token tier; check the Claude docs Pricing page before you rely on them. The point of the table is the shape: no tier wins every row, so the job decides. You steer depth on all three with the effort level, covered in adaptive thinking and effort.

picker.py: a first guess per job

"""Pick a Claude model for each job (Models overview page)."""
from stand_in import HAIKU, SONNET, OPUS

LATENCY = {HAIKU: "Fastest", SONNET: "Fast", OPUS: "Moderate"}

JOBS = [{"name": "route", "latency": "tight", "steps": 1},
        {"name": "reply", "latency": "normal", "steps": 1},
        {"name": "review", "latency": "normal", "steps": 12}]


def pick(job):
    """A first guess. Your own evals decide if cheaper is enough."""
    if job["steps"] > 3:
        return OPUS
    if job["latency"] == "tight":
        return HAIKU
    return SONNET

Long, multi-step work goes to Opus. A tight latency need with a single step goes to Haiku. Everything else gets Sonnet. The docstring says the important part: this is a first guess, and your own evals decide whether a cheaper model is good enough. For routing in production, with a classifier or a cascade judged on cost per win, see LLM model routing.

The same setting, three models

Now the part that surprises people. Take four settings that older Claude models accepted and send each one, alone, to Haiku, Sonnet and Opus 5.5:

  • temperature: 0
  • a manual thinking budget, {"type": "enabled", "budget_tokens": 1024}
  • an assistant prefill: a last assistant message that starts the reply with {
  • a forced tool choice, {"type": "tool", "name": "lookup"}
"""Old settings, and a request that works today."""
import anthropic

ASK = [{"role": "user", "content": "Where is my refund?"}]
TOOL = {"name": "lookup", "input_schema": {"type": "object"}}
THINK = {"type": "enabled", "budget_tokens": 1024}
PRE = {"role": "assistant", "content": "{"}
FORCE = {"type": "tool", "name": "lookup"}

OLD = {
    "temperature": {"temperature": 0},
    "thinking budget": {"thinking": THINK},
    "prefill": {"messages": ASK + [PRE]},
    "forced tool": {"tools": [TOOL], "tool_choice": FORCE},
}


def send(client, model, **extra):
    """Send one old setting. Return the status."""
    try:
        client.messages.create(
            model=model, max_tokens=512, messages=ASK,
            extra_body=extra)
        return 200
    except anthropic.BadRequestError:
        return 400


def current(client, model):
    """No sampling, no thinking field, no prefill."""
    return client.messages.create(
        model=model, max_tokens=512, messages=ASK,
        output_config={"effort": "medium"})


def first_block(resp):
    return resp.content[0].text


def text_of(resp):
    return next(b.text for b in resp.content if b.type == "text")

A rejected setting comes back as an HTTP 400, and the SDK raises it as BadRequestError. The request that works today has no temperature, no thinking budget and no prefill; effort sets how deeply the model thinks.

Old settings against the 5.5 models Haiku Sonnet Opus temperature 0 thinking budget_tokens assistant prefill forced tool_choice 400400400 400400400 400400400 200400400
Same request, different model, different answer.

What the run printed

The project runs against a stand-in: the Anthropic SDK on an httpx mock transport that answers 400 for the settings the migration guides say each model rejects. The reply text is scripted, so it is a test reply, not a live Claude answer.

python run_all.py
picker
route   -> claude-haiku-5-5   | Fastest
reply   -> claude-sonnet-5-5  | Fast
review  -> claude-opus-5-5    | Moderate
old settings, one at a time
setting         haiku  sonnet  opus
temperature     400    400     400
thinking budget 400    400     400
prefill         400    400     400
forced tool     200    400     400
current request -> end_turn, first block is thinking
first_block: AttributeError
text_of: test model reply: your refund was sent on Monday.

Read it from the top:

  • One model per job: Haiku for routing, Sonnet for the reply, Opus for the review.
  • Temperature, the thinking budget and the prefill fail on all three models.
  • Forced tool choice is the odd one out: only Haiku accepts it. On Sonnet 5.5 and Opus 5.5, use tool_choice auto with strict: true on the tool, or structured outputs.
  • The current request works, but its first block is a thinking block. Reading content[0].text fails; finding the block whose type is text returns the reply.

A model swap is a code change, not a config change. Each model ID is a pinned snapshot. Before you change it, read the migration guide for the new model, remove what it rejects, and run your evals on the new model.

Common mistakes

  • The biggest model for every job. Routing waits on Opus, and the bill pays for depth the job never uses.
  • The cheapest model by price alone. A cheap model that fails the review job costs more in rework. Let evals decide.
  • Changing only the model ID and shipping. Old settings such as temperature, budget_tokens, prefill or a forced tool can turn into 400s.
  • Reading the reply by position. With thinking on, content[0] may not be the text. Read by type.

Quick recap

JobModelWhy
Tight, simple, high volume (routing, tagging)HaikuFastest and cheapest
Most jobs, where speed and quality both matterSonnetBest mix of the two
Long, hard, multi-step workOpusMost capability
Any new releaseRead the migration guideThe request can change with the model

Try it yourself

Add a fourth job to JOBS: a nightly summary of all tickets, three steps, nobody waiting. Which model does pick() choose, and would you trust that guess without an eval? Then write the eval you'd run before moving it to a cheaper model.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in Claude · 18 of 66

Previous
Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
Next post
Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Related posts

The Claude Messages API: Your First Call, Field by Field

One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.

Claude Tool Use: How tool_use and tool_result Work in the Messages API

Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.

Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared

Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.

Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move

Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.

On this page

  • A kitchen with three cooks
  • Each tier wins a different row
  • picker.py: a first guess per job
  • The same setting, three models
  • What the run printed
  • Common mistakes
  • Quick recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.