Sub topic 2
Setting a Thinking Token Budget
Assume you can call an LLM API, understand tokens and output limits, and read basic Python. A thinking token budget is the maximum number of internal tokens a reasoning model may use before producing its answer. A larger budget can help with difficult tasks, but it usually increases cost and latency.
Set the budget
Anthropic’s Messages API enables extended thinking with budget_tokens. The max_tokens value must be larger than the thinking budget because the response also needs space for its final answer.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=4096,
thinking={"type": "enabled", "budget_tokens": 2000},
messages=[
{"role": "user", "content": "Is 3599 a prime number? Explain briefly."}
],
)
for block in response.content:
if block.type == "text":
print(block.text)A budget of 2,000 does not force the model to use exactly 2,000 tokens. It sets an upper limit.
Output limits share the budget
When reasoning and the final response use the same output allowance, a large thinking budget can leave too little room for the answer. For example, max_tokens=1,000 and budget_tokens=900 leaves at most about 100 tokens for the visible response.
The exact accounting rules differ by provider. Check the selected model’s API documentation before comparing settings.
See reasoning summaries and thinking blocks
Some APIs return thinking blocks, while others return only a summary or token count. Treat these fields as diagnostic output. They can help explain usage, but they are not a reliable transcript of every internal step and may vary by model.
Weigh cost and latency
More thinking tokens generally increase processing time and billed usage. Use a small budget for routine classification or extraction. Use a larger budget for debugging, multi-step mathematics, or planning with many constraints.
| Setting | Typical use | Trade-off |
|---|---|---|
| Low budget | Simple, familiar tasks | Lower cost and latency |
| High budget | Hard, error-prone tasks | Better reasoning potential, higher cost |
Exercise
Why can increasing budget_tokens reduce the space available for the final answer?
Show answer
Thinking tokens and answer tokens can share the max_tokens output limit, so more reasoning can leave fewer tokens for visible text.