Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.8 — Reasoning Models
LLM Engineering · Example 1 of 1

Hidden thinking uses the same token budget

The thinking sizes are made up. A real model decides by itself how long to think, within the effort you set.

Reasoning models write hidden thinking tokens before the visible answer. That helps on multi-step problems, and it costs time and money, and the thinking shares your max_tokens budget, which creates a classic trap: an empty reply with finish_reason: length.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write fake_call(needed, answer_tokens, max_tokens) that returns (reasoning_used, answer_used, finish) using the rules in the example. Print the result for (300, 25, 100) and (300, 25, 400).

02

Write min_budget(needed, answer_tokens) and print it for needed=120 and answer_tokens=25. Add a 10 percent safety margin, rounded up, and print that too.

Explain it without notes

01

Why do reasoning models help on multi-step problems?

02

What is the max_tokens trap and how do you avoid it?

03

When would you not use a reasoning model?

04

How do reasoning tokens show up in cost and latency?

Hidden thinking uses the same token budget
Sign in to run this example in your browser.

Expected output

effort=low    max_tokens=100 -> finish=stop   reasoning= 40 answer=25 (complete) cost=0.000130
effort=high   max_tokens=100 -> finish=length reasoning=100 answer= 0 (empty) cost=0.000200
effort=medium max_tokens=200 -> finish=stop   reasoning=120 answer=25 (complete) cost=0.000290
effort=high   max_tokens=320 -> finish=length reasoning=300 answer=20 (cut off) cost=0.000640
effort=high   max_tokens=400 -> finish=stop   reasoning=300 answer=25 (complete) cost=0.000650