ReleaseResearch Paper · For R&DHabr AI→ original

The LLM bot's usage log showed zero tokens everywhere, while a gpt-5-mini conversation cost 1–3 cents

In the Octery bot's database, the token total was 0, even though invoices from the providers kept arriving. The culprit was the expression `|| 0`: when there was no data on spending, the code wrote zero, and zero looks like a real measurement. According to the execution log, a dialogue of 7.6 messages cost 1–3 cents on gpt-5-mini and a fraction of a cent on nano. Store unknown spending as null and count every model call separately.

AI-processed from Habr AI; edited by Hamidun News
The LLM bot's usage log showed zero tokens everywhere, while a gpt-5-mini conversation cost 1–3 cents
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
One message triggers several callssearch, JSON repair, a note
Key metric #2gpt-5-mini costs 14–20 times more than nano: input is twice as long, output is five times pricier
Key metric #3The paper forecast overestimated input per message by 3–6 times compared with the measurement

Before a pilot with its first major client, the developer of the Octery bot decided to calculate how much one dialogue costs and discovered that the token sum in the LLM spending table was zero. A token here is the unit the provider charges for, roughly a piece of a word. It turned out the model had never been called, even though invoices kept arriving on schedule.

The zeros were written into the table by the code itself: the expression || 0 substituted zero every time there was no data on spending. When the real figures were pulled from the execution log, it became clear that a dialogue of 7.6 messages costs a fraction of a cent on gpt-5-nano and 1–3 cents on gpt-5-mini.

The story is useful for anyone building LLM products who plans to price a dialogue: an accounting error costs more than a prompt error.

Where the zero came from

The bot answers leads in amoCRM chats. A message arrives via webhook into the pipeline. The first stage decides whether a reply is needed and calls the second stage, where an AI agent runs: a model, a search over the knowledge base, and a parser for the structured response. As its last step, the first stage writes an analytics row to the API.

In that step stood the expression agentResult.tokenUsage?.totalTokens || 0. The agent's result never contained a tokenUsage field: usage stays inside the model step. The ?. operator honestly returned undefined, and || 0 turned it into zero. Had it been null, the sum in the query would have come back as NULL and the problem would have been visible at once. Zero, however, looks like a measurement result, so nobody questioned the table. In production there were 19 rows with a sum of 0, and on dev there were 794 rows (672 of them from a single day of testing), with a maximum of 0 as well.

What wasn't counted at all

Even with the expression fixed, this step would have seen less than half of the spending. One client message triggers several model calls:

  • the agent queries the knowledge base and comes back, which is a separate call;
  • if the model returned malformed JSON, the parser with autoFix makes one more call to repair it;
  • a parallel branch writes a note for the manager, and this second agent receives the entire dialogue history each time;
  • embeddings for search are computed by the API, and the batch request function took only the vectors from OpenAI's response and discarded usage.prompt_tokens.

None of these calls were recorded anywhere. The broken expression was just the most visible spot.

The real numbers

The pipeline stores execution data in its own database, and for model steps it holds promptTokens, completionTokens and totalTokens. The format is undocumented, so the author extracted the fields from the JSON with a regular expression, using a plain SELECT on dev.

A run on gpt-5-nano cost about $0.00011, while on gpt-5-mini it cost $0.0015–0.0022, which is 14–20 times more. There are two reasons: the average input on mini is more than twice as long, and an output token costs five times as much. Test runs on mini on October 15 raised dev's daily spending roughly eightfold, to almost a dollar. The average dialogue that day comprised 7.6 messages and cost a fraction of a cent on nano and 1–3 cents on mini.

There is a second zero trap, this time not the author's doing. For mini, the log records completionTokens: 0 and puts only the input into totalTokens. The author suspects this has to do with how the reasoning model's response is parsed, where output and reasoning are counted separately, but has not verified it. He estimated mini's output at 200–500 tokens per call.

Another surprise: there were about two runs with a model call for every incoming message (1,335 for 671). The excess came from the tester's repeats; in production it should be closer to one. If spending is divided by messages without knowing this, the cost of a dialogue comes out overstated by half.

Forecast versus fact

Before the measurement, the author had a paper estimate: about 7,800 input tokens per message and roughly $0.001 per message on a nano-class model. The dev measurement came in 3–6 times lower. The estimate had been made using the 90th percentile, and the pilot client's prompt turned out shorter than assumed. Now the forecast serves as an order-of-magnitude estimate, and the price for the contract is taken from the measurement. It depends on the length of the client's prompt, the number of knowledge-base queries, the model, and duplicate incoming messages.

What is changing

For now this is a specification, and the code is still in progress. The rules are these:

  • If the pipeline doesn't know the spending, the API receives and stores null. There is a dedicated scenario for this: if tokensUsed = 0 arrives, the database must end up with null.
  • Accounting moves to an llm_usage table, where one row corresponds to one provider call. It records the model, the call type (reply, note, JSON repair, embedding, transcription), the company, input and output tokens, and the cost according to the price table.
  • Calls from the API are written at the moment of the request. Calls from the pipeline are pulled from the execution log by an extractor, and when it meets an unfamiliar format it skips the call with a warning instead of writing a zero.
  • If no row arrives from the pipeline in a day while messages exist, an alert fires.

The practical takeaway: don't substitute || 0 where data may be missing, distinguish "zero" from "unknown," and count spending per call rather than per message. Such a scheme also answers questions the old table would not have settled even with correct numbers: how much the manager notes consume, how often the model breaks JSON, and which client is expensive because of a long prompt. The story has one limitation: the figures were taken from dev and test traffic, so production prices need to be re-verified on real dialogues.

Story

Key Questions Answered

Where the zero came from?

The bot answers leads in amoCRM chats. A message arrives via webhook into the pipeline. The first stage decides whether a reply is needed and calls the second stage, where an AI agent runs: a model, a search over the knowledge base, and a parser for the structured response. As its last step, the first stage writes an analytics row to the API. In that step stood the expression agentResult.tokenUsage?.totalTokens || 0. The agent's result never contained a tokenUsage field: usage stays inside the model step. The ?.

What wasn't counted at all?

Even with the expression fixed, this step would have seen less than half of the spending. One client message triggers several model calls: the agent queries the knowledge base and comes back, which is a separate call; if the model returned malformed JSON, the parser with autoFix makes one more call to repair it; a parallel branch writes a note for the manager, and this second agent receives the entire dialogue history each time; embeddings for search are computed by the API, and the batch…

What are the key details on The real numbers?

The pipeline stores execution data in its own database, and for model steps it holds promptTokens, completionTokens and totalTokens. The format is undocumented, so the author extracted the fields from the JSON with a regular expression, using a plain SELECT on dev. A run on gpt-5-nano cost about $0.00011, while on gpt-5-mini it cost $0.0015–0.0022, which is 14–20 times more. There are two reasons: the average input on mini is more than twice as long, and an output token costs five times as much.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Private AI Builders Community · Vibe Club

Ship AI Faster with Founders, Engineers & Weekly Architecture Reviews

Inside Vibe Club (hamidun.com/club) — weekly live masterminds with Zhemal Khamidun, Tech Radar, full LMS access, and 370+ production Claude Code skills.

Join Vibe Club →Explore Hamidun Academy
What do you think?
Loading comments…