Claude API · Caching, batches and tokens
Submit a batch
Process many requests asynchronously at half the price. Each request needs a custom_id.
from anthropic.types.message_create_params import MessageCreateParamsNonStreaming
from anthropic.types.messages.batch_create_params import Request
batch = client.messages.batches.create(requests=[
Request(
custom_id=f"request-{i}",
params=MessageCreateParamsNonStreaming(
model="claude-opus-5-5",
max_tokens=16000,
messages=[{"role": "user", "content": prompt}],
),
)
for i, prompt in enumerate(prompts)
])
Official Claude API documentation
More caching, batches and tokens commands
- Cache a large prompt
- Check that caching works
- Count tokens before sending
- Wait for a batch and read results
All caching, batches and tokens commands · Claude API cheatsheet