| name | anth-performance-tuning |
| description | Optimize Claude API performance with prompt caching, model selection,
streaming, and latency reduction techniques.
Use when experiencing slow responses, optimizing token usage,
or reducing time-to-first-token in production.
Trigger with phrases like "anthropic performance", "claude speed",
"optimize claude latency", "anthropic caching", "faster claude responses".
|
| allowed-tools | Read, Write, Edit, Grep |
| version | 1.6.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","ai","anthropic"] |
| compatibility | Designed for Claude Code |
Anthropic Performance Tuning
Overview
Optimize Claude API latency and throughput via prompt caching, model selection, streaming, and request optimization. The biggest wins come from prompt caching (90% input cost reduction) and model selection (Haiku is 4x faster than Sonnet).
Prompt Caching (Biggest Win)
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are an expert on the following 50-page document: ...<long document>...",
"cache_control": {"type": "ephemeral"}
}
],
messages=[{"role": "user", "content": "What does section 3.2 say?"}]
)
print(f"Cache read tokens: {message.usage.cache_read_input_tokens}")
print(f"Cache creation tokens: {message.usage.cache_creation_input_tokens}")
print(f"Uncached input tokens: {message.usage.input_tokens}")
Cache requirements: Minimum 1,024 tokens for Sonnet/Opus, 2,048 for Haiku. Cache lives for 5 minutes (refreshed on each hit).
Model Selection for Speed
| Model | Speed | Cost (per MTok in/out) | Best For |
|---|
| Claude Haiku | Fastest |