Claude Haiku API Example

How to use claude-haiku-4-5 via the Anthropic Python SDK. Working code for classification, tagging, extraction, and high-volume tasks where Haiku's low cost matters.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

claude-haiku-4-5-20251001 is the go-to model for high-volume, cost-sensitive workloads. Same API, 3.75× cheaper than Sonnet.

Basic Haiku call

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-haiku-4-5-20251001",  # ← the key change
    max_tokens=256,
    messages=[
        {"role": "user", "content": "Classify this support ticket: 'My account was charged twice.' Category: billing, technical, account, other"}
    ]
)
print(response.content[0].text)  # "billing"

Model comparison table

ModelInput ($/M tokens)Output ($/M tokens)ContextBest for
claude-haiku-4-5-20251001$0.80$4.00200KHigh-volume, simple tasks
claude-sonnet-4-6$3.00$15.00200KMost workloads, balanced
claude-opus-4-7$15.00$75.00200KComplex reasoning only

Batch classification with Haiku (cost-optimised)

import anthropic
from concurrent.futures import ThreadPoolExecutor

client = anthropic.Anthropic()

CATEGORIES = ["billing", "technical", "account", "shipping", "other"]

def classify_ticket(ticket: str) -> str:
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=32,
        system=f"Classify the support ticket into exactly one of: {', '.join(CATEGORIES)}. Reply with only the category name.",
        messages=[{"role": "user", "content": ticket}]
    )
    return response.content[0].text.strip().lower()

tickets = [
    "I was charged twice on my credit card",
    "The app keeps crashing on iOS 17",
    "I forgot my password and can't reset it",
    "My package hasn't arrived in 3 weeks",
]

with ThreadPoolExecutor(max_workers=5) as pool:
    results = list(pool.map(classify_ticket, tickets))

for ticket, category in zip(tickets, results):
    print(f"{category:12} | {ticket}")

Structured extraction with Haiku + tool use

import anthropic, json

client = anthropic.Anthropic()

extract_tool = {
    "name": "extract_entities",
    "description": "Extract named entities from text",
    "input_schema": {
        "type": "object",
        "properties": {
            "people": {"type": "array", "items": {"type": "string"}},
            "organizations": {"type": "array", "items": {"type": "string"}},
            "dates": {"type": "array", "items": {"type": "string"}}
        },
        "required": ["people", "organizations", "dates"]
    }
}

response = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=512,
    tools=[extract_tool],
    tool_choice={"type": "tool", "name": "extract_entities"},
    messages=[{
        "role": "user",
        "content": "Elon Musk founded SpaceX in 2002 and acquired Twitter in October 2022."
    }]
)

for block in response.content:
    if block.type == "tool_use":
        print(json.dumps(block.input, indent=2))
# Output:
# {
#   "people": ["Elon Musk"],
#   "organizations": ["SpaceX", "Twitter"],
#   "dates": ["2002", "October 2022"]
# }

When Haiku is fast enough

Use the Cost Calculator to model Haiku vs Sonnet costs at your volume. See Python quickstart for the full API setup guide.

Frequently asked questions

What is Claude Haiku?
Claude Haiku is Anthropic's fastest and cheapest production-grade model. The 2025 version (claude-haiku-4-5-20251001) costs $0.80 per million input tokens and $4 per million output tokens. It's designed for high-volume, latency-sensitive tasks: classification, tagging, extraction, short-form generation, and real-time applications.
When should I use Haiku instead of Sonnet?
Use Haiku when: (1) you need sub-second response times, (2) you're running millions of requests/month and cost matters, (3) the task is simple enough that Haiku's quality is sufficient (classification, extraction, short generation). Use Sonnet when: the task requires reasoning, code generation, long outputs, or nuanced judgment.
How much cheaper is Haiku than Sonnet?
Haiku 4.5 costs $0.80/$4 (input/output per million tokens). Sonnet 4.6 costs $3/$15. Haiku is 3.75× cheaper on input and 3.75× cheaper on output. For a workload of 10M input + 1M output tokens/month: Haiku = $12, Sonnet = $45.
Does Haiku support all the same API features as Sonnet?
Yes. Haiku supports the same API features: tool use, streaming, vision, prompt caching, batch API, and the full 200K token context window. The only difference is model quality and speed — the API surface is identical.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript