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.
claude-haiku-4-5-20251001 is the go-to model for high-volume, cost-sensitive workloads. Same API, 3.75× cheaper than Sonnet.
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 | Input ($/M tokens) | Output ($/M tokens) | Context | Best for |
|---|---|---|---|---|
| claude-haiku-4-5-20251001 | $0.80 | $4.00 | 200K | High-volume, simple tasks |
| claude-sonnet-4-6 | $3.00 | $15.00 | 200K | Most workloads, balanced |
| claude-opus-4-7 | $15.00 | $75.00 | 200K | Complex reasoning only |
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}")
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"]
# }
Use the Cost Calculator to model Haiku vs Sonnet costs at your volume. See Python quickstart for the full API setup guide.