(Note · · 5 min read)

The AI feature works. Now look at the bill

A feature that cost pennies in development becomes a line item nobody predicted, and the usual response is to look for a cheaper model. That is rarely where the money went. It went into the same call being made more often, with more attached to it, than anyone measured.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Measure per action, not per month

A monthly total tells you there is a problem and nothing about where. Record tokens and cost against each unit of work — this conversation, this document processed, this screening run — so you can say what a single action costs and multiply it by what you expect.

That number is also the one that matters commercially. It tells you whether the feature is viable at the volume you are promising, which is better discovered now than after launch.

Most of the bill is input you chose to send

Spend is dominated by what you attach, not what comes back. The usual growth is quiet: retrieved passages increased from five to fifteen, conversation history carried verbatim, a system prompt that accumulated instructions nobody removed.

Trim with the same test that improves quality: if this were removed, would the answer change. Fewer, better passages and a summarised history usually cost less and answer better, which is the rare case where the cheap option is also the good one.

Watch for work being done twice

Retries are the most common invisible multiplier. A call that times out client-side may still be running and billing, so a blind retry pays twice for one answer. Bound retries deliberately and make them conditional rather than automatic.

Caching is the other half. Repeated identical questions, re-embedding documents that have not changed, re-processing the same file — all of these are paid for again unless something stops them. On one chatbot an in-memory cache with a short lifetime was enough to stop repeated vector searches costing the same thing repeatedly.

A loop can spend without limit

Anything agentic can cycle: call a tool, dislike the result, try again. From inside the loop every iteration is reasonable, and nothing in the model stops it. Bound it from outside with a maximum number of steps, a cost ceiling per run and a wall-clock deadline, enforced by the code running the agent.

Where one agent calls another, the ceiling belongs to the whole run rather than to each participant, or the real total is the sum of several budgets nobody set.

Match the model to the step

Pipelines usually contain several steps with different difficulty: classifying, extracting, drafting, summarising. Routing the easy steps to a smaller model and reserving the capable one for the step that needs judgement is usually a larger saving than changing the model everywhere, and it costs less quality.

Decide that with your evaluation set rather than by impression, so you can see what each substitution actually costs in accuracy.

Common questions

Why did my LLM bill grow without usage growing?

Usually because input grew. More retrieved passages, conversation history carried verbatim and an accumulated system prompt all increase the cost of every call, and none of it shows up as more requests.

How should LLM spend be measured?

Per unit of work — per conversation, per document processed, per run — rather than as a monthly total. That gives you the cost of a single action, which is what you multiply by expected volume to know whether the feature is viable.

Do retries on timeouts cost extra?

They can cost double. A call that timed out on your side may still be running and billing at the provider, so an automatic retry pays twice for one answer. Bound retries deliberately rather than leaving them automatic.

Is switching to a cheaper model the best way to reduce cost?

Usually not the first move. Routing easy steps such as classification and extraction to a smaller model while keeping a capable one for the step needing judgement typically saves more at lower quality cost — and should be decided with an evaluation set rather than by impression.

Need something like this built?