Claude API · Caching, batches and tokens

Count tokens before sending

Estimate the input size and cost of a request without running it.

count = client.messages.count_tokens(
    model="claude-opus-5-5",
    system=system,
    messages=messages,
)
print(count.input_tokens)

Official Claude API documentation

More caching, batches and tokens commands

All caching, batches and tokens commands · Claude API cheatsheet

Was this page helpful?