AI article

This LLM cost function looks right. Can you spot the bug?

Community description: OpenAI counts reasoning tokens inside output_tokens, and Gemini counts thinking tokens separately. A short puzzle, the answer, and code you can run.

Dev.to | Nov 9, 2026 | Samuel Ochaba

Automated excerpt

So estimate_cost counts the reasoning twice. Adding the reasoning field counts tokens twice on OpenAI, and leaving it out drops tokens on Gemini. Some providers report cached tokens inside the input count.

Selected automatically from source text; not independently written or fact-checked. Read the original for full context.

Read the original article

Read next

AI briefing: recent picks

More stories to explore