Users Pricing

articles

Home Articles Tokens, Cost and Latency, Budgeting an AI Application – MindStick
Tokens, Cost and Latency, Budgeting an AI Application

Tokens, Cost and Latency, Budgeting an AI Application

Bhumi Pandya 1000 24 Nov 2026

A prototype that costs a few rupees a day can become a serious monthly bill once real users arrive. Many teams discover this after launch, when the finance team asks why the cloud invoice tripled.

The good news is that AI costs are predictable once you understand what drives them, and there are well-established techniques to cut them, often by more than half, without hurting quality. This article shows how to estimate, measure and optimise both cost and latency.

The unit of everything, the token

AI APIs charge by the token, a chunk of text roughly three quarters of an English word. Pricing is usually quoted per million tokens, with separate prices for:

- input tokens: everything you send, including system prompt, tools, history and documents
- output tokens: everything the model generates, including any reasoning or thinking tokens

Output tokens almost always cost several times more than input tokens, commonly around four to five times more. That single fact shapes a lot of optimisation work.

Prices vary enormously between models. Small, fast models can cost a small fraction of what the largest models cost. Within the Claude family, for example, Haiku models are priced far below Opus models, with Sonnet in between. Always check the provider's current pricing page, because prices change with new releases.

A simple cost formula

For a single request:

cost = (input tokens x input price) + (output tokens x output price)

For a feature:

monthly cost = requests per month x average cost per request

Let us take an illustrative example with round numbers. Suppose a support chatbot sends 6,000 input tokens and receives 500 output tokens per message, on a model priced at 3 dollars per million input tokens and 15 dollars per million output tokens.

- input: 6,000 x 3 / 1,000,000 = 0.018 dollars
- output: 500 x 15 / 1,000,000 = 0.0075 dollars
- total per message: about 0.0255 dollars

At 200,000 messages a month, that is about 5,100 dollars. Now you can make informed decisions about where to optimise.

Where tokens hide

When teams first log real token usage, they are often surprised. Common hidden costs:

- System prompts that grew to thousands of tokens over months of tweaks.
- Tool definitions sent on every request, sometimes 5,000 tokens or more for agents with many tools.
- Conversation history resent in full every turn, growing with each message.
- Retrieved documents in RAG, where 20 chunks of 500 tokens each add 10,000 tokens.
- Reasoning tokens from thinking modes, which are billed as output.
- Retries after errors, which double the cost of failed calls.
- Agent loops, where one user request triggers ten model calls.

Instrument every call. Log input tokens, output tokens, cached tokens, model and feature name. The API response includes usage figures, so this costs nothing to collect.

Understanding latency

Users feel latency in two ways:

- Time to first token (TTFT): how long before anything appears. Driven by queueing, input length and model size.
- Output throughput: how many tokens per second arrive after that. Driven mainly by model size and provider load.

Total time is roughly TTFT plus output tokens divided by throughput. Long outputs take longer, so asking for concise answers improves both cost and speed.

Thinking or reasoning modes add time before the visible answer begins, because the model generates reasoning first.

Optimisation 1, choose the right model for each task

Not every request needs the most capable model. A common pattern:

- use a small, fast model for classification, routing, query rewriting, simple extraction and short replies
- use a mid-tier model for most user-facing tasks
- reserve the top model for complex reasoning, difficult code and high-stakes analysis

A router, either rules-based or a small model, decides which model handles each request. Teams frequently cut costs by half or more this way with little visible quality change. Measure with evals before and after.

Optimisation 2, prompt caching

If many requests share the same beginning, such as a long system prompt, tool definitions or a reference document, prompt caching lets the provider reuse its processing.

With Claude, cache reads are billed at about one tenth of the normal input price. Writing to the cache costs a little more than normal input, about 1.25 times for the default five-minute cache and 2 times for the one-hour option. For prompts that repeat often, savings on input costs can be very large, and latency drops too. OpenAI and Google offer their own caching mechanisms with different rules.

To benefit, structure prompts so stable content comes first and variable content comes last.

Optimisation 3, batch processing

For work that does not need an instant answer, such as nightly summaries, bulk classification or content generation, batch APIs process requests asynchronously at a discount. Anthropic and OpenAI both offer batch processing at roughly half the normal price, with results typically returned within hours.

Optimisation 4, shrink the prompt

- Remove outdated or redundant instructions from the system prompt.
- Shorten tool descriptions and remove unused tools.
- Summarise old conversation turns instead of resending them.
- Retrieve fewer, better chunks by improving re-ranking.
- Send only the relevant parts of large documents.

Optimisation 5, control output length

Because output tokens are expensive and slow:

- ask for concise responses in the instructions
- set a sensible max tokens limit
- use structured output to avoid verbose prose when you only need data
- for reasoning modes, use the provider's controls to limit the thinking budget or effort where available

Optimisation 6, cache responses yourself

If many users ask the same question, cache the final answer in your own application, keyed by a normalised version of the question plus relevant context. Semantic caching, which matches similar questions using embeddings, extends this further, but be careful that cached answers stay correct and respect permissions.

Optimisation 7, stream for perceived speed

Streaming does not reduce total time, but it lets users see output immediately, which makes the application feel much faster. For chat interfaces, streaming should be the default.

Optimisation 8, reduce retries and loops

- Handle rate limits with exponential backoff rather than immediate retries.
- Validate inputs before calling the model.
- Set a maximum number of steps for agents.
- Detect and stop loops where an agent repeats the same tool call.

Building a budget

A practical budgeting process:

1. List features that call AI.
2. Estimate volume for each: requests per user per day times users.
3. Measure average tokens for each feature from logs or test runs.
4. Calculate cost with current pricing.
5. Add headroom of 20 to 30 percent for growth, retries and prompt changes.
6. Set alerts at spending thresholds.
7. Review monthly and optimise the biggest line items first.

Most providers let you set spending limits or usage alerts in their console. With Anthropic, for example, a spend limit that is reached causes requests to fail with a rate limit style error until the limit is raised, so monitor these limits closely.

Tracking cost per feature and per user

Tag every request with the feature and, where appropriate, the customer or tenant. This lets you answer questions such as:

- which feature is most expensive?
- which customers use the most AI?
- did last week's prompt change increase cost?
- is a free tier sustainable?

Observability platforms for LLMs, as well as simple database logging, can provide this. Our article on observability for LLM apps covers the tooling.

Latency budgets

Define acceptable latency per feature. For example:

- autocomplete: under 300 milliseconds to first token
- chat reply: under 2 seconds to first token
- document analysis: under 60 seconds total, with a progress indicator
- batch reports: hours are acceptable

Then pick models, prompt sizes and architectures that fit. Interactive features may need smaller models and aggressive caching; background jobs can use larger models and batch pricing.

Key takeaways

- Tokens drive both cost and latency; output tokens cost more than input.
- Log usage on every call, tagged by feature.
- Route simple tasks to small models.
- Use prompt caching, batching and shorter prompts.
- Control output length and agent loops.
- Budget per feature, add headroom and set alerts.

Cost optimisation is not about using the cheapest model everywhere. It is about spending tokens where they create value and nowhere else.

Related articles on MindStick

- Prompt Caching in Claude and How It Cuts Cost
- Choosing the Right Claude Model for Speed, Cost and Quality
- Cost Optimisation Architecture for High-Volume AI Workloads
- Context Windows Explained and Why They Limit What AI Can Do

Prices and discounts in this article are illustrative and change frequently. Always use each provider's current pricing page for real budgeting.


Bhumi Pandya

Network Security Engineer

I am a Network Security Engineer at Quick Heal Technologies, with 2 years of experience in firewall, VPN and network security operations. I completed my BCA from Gujarat University, Ahmedabad and MCA from Symbiosis International University, Pune. I am originally from Ahmedabad, Gujarat. Outside work I enjoy travelling to new places and playing chess.


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md