The bill that breaks the business model
The first big invoice for a new AI feature always lands like a gut punch. It shows up weeks after the money's already spent, as a single, unexplained number — say, $14,200 charged by an LLM (a large language model, the kind of AI system behind chatbots and text tools) API (an "application programming interface," the channel your software uses to send requests to that AI over the internet). The bill doesn't say which feature caused it: the summarization tool? The chatbot? One heavy user, or a badly written instruction that quietly costs you a little extra on every single request? The invoice can't tell you, and if you haven't built tracking in advance, neither can you.
This is the moment many teams realize their old assumptions about software costs no longer hold. For decades, once you'd built a piece of software, serving one more user cost almost nothing extra — the "marginal cost" of each additional user was close to zero. LLMs break that rule. Every time a user does something that triggers a call to the model, you pay a real, variable expense.
That's not just a new line on the cloud bill. It's a different kind of unit economics — the cost and value tied to one single unit of usage, like one summary or one chat reply. An AI feature can be wildly popular and wildly unprofitable at the same time, quietly eating into your margins with every click. The only way to avoid that trap is to stop learning about your costs from invoices after the fact, and instead work out, before you ship, exactly what a single user action will cost you. That's the cost model almost nobody builds until it's already too late.
Your invoice is a lagging indicator of failure
Traditional cloud cost management fails for AI workloads because it was built for a different world. A standard bill shows a spike in GPU instance usage or a large line item for a model provider, but it cannot connect that spend to the business activity that caused it. The invoice tells you what you spent; it has no idea why.
To understand the "why," you have to dissect the anatomy of an LLM call. Unlike a virtual machine that costs money per hour whether it's busy or idle, an API-based model's cost is driven by usage, specifically by the number of "tokens" it processes. A token is a piece of a word, roughly four characters of English text. You pay for the tokens you send in (the input) and the tokens the model sends back (the output).
This seems simple enough to estimate, but the reality is more complex. As one analysis from Shanku Kuehn points out, the input portion of your bill is often a "five-headed" monster, with each head representing a different cost driver you must control:
The User's Query: The direct text or data the user provides.
The System Prompt: The instructions you give the model to guide its behavior. This is sent with every call unless you use specific caching features.
Conversation History: For a chatbot, the entire preceding conversation is often re-sent to maintain context.
Retrieval-Augmented Generation (RAG) Context: Documents or data retrieved from a vector database to ground the model's answer in facts.
Tool or Function Schemas: If you're using the model to call other functions, the definitions of those functions are included in the prompt.
An engineer might estimate the cost based on the user's query alone, forgetting that a long, unoptimized system prompt and a deep conversation history can multiply the token count — and the cost — of every single interaction. This is how estimated costs diverge so sharply from billed costs. You thought you were paying for a sentence but were actually paying for a five-page document on every turn.
For teams running their own open-source models, the currency changes from tokens to GPU hours, but the principle holds. The primary cost becomes the expensive, specialized GPU infrastructure needed for inference. Without a mechanism to attribute those GPU cycles to a specific feature or customer, you face the same problem: a massive, inscrutable bill that offers no path to optimization.
The metric that matters: Cost per user action
The central mistake teams make is tracking cost_per_api_call. This metric is a trap. It tells you nothing about the value created or the business context. The metric that matters is cost_per_user_action.
This is the core idea of unit economics: connecting your infrastructure spend to the business metrics that drive decisions. Instead of a raw cloud bill, you report actionable figures: cost per document summarized, cost per report generated, cost per active customer. This reframes the entire conversation from "How do we lower the AI bill?" to "Is this feature profitable at its current price and usage patterns?"
For a SaaS company, infrastructure costs are part of the Cost of Goods Sold (COGS). Healthy spend typically lands between 8-12% of revenue. Once it crosses 15%, investors start seeing it as architectural debt — a sign that your platform doesn't scale efficiently. AI features with unmanaged unit costs are a primary source of this debt. Trending your cost per user action over time turns a static infrastructure report into a live signal for your pricing, product, and engineering strategy.
But to calculate cost_per_user_action, you first need a working cost allocation layer: a way to divide your total AI spend and attribute it to a specific workload, team, customer, or feature. According to a 2026 report from Cast AI, 68% of organizations see their Kubernetes costs rising year-over-year, yet most engineering teams can't pinpoint which features are driving that growth. This is the gap where margin leaks.
Building the allocation layer
Attribution is the hard part, but there are two main paths.
For containerized workloads, like self-hosted models on Kubernetes, the foundation is rigorous labeling. By assigning consistent labels to namespaces and other resources, you can create a logical map between infrastructure and the business unit it serves. For example, all resources for the "Smart Summarizer" feature might get the label feature: smart-summarizer. Cost allocation tools can then ingest cloud billing data and use these labels to report the cost per feature.
For API-based models, the work happens in your application code. You need to wrap every call to an LLM provider with logging that includes:
A Feature Identifier:
feature: "chatbot"A User or Tenant ID:
customer_id: "cust_1a2b3c"A Unique Request ID:
request_id: "uuid-..."Token Counts: The input and output tokens reported by the API response.
Cost: The calculated cost for that single call, based on the provider's pricing.
This data stream becomes your source of truth. It allows you to aggregate costs and answer questions like, "What was the total cost for customer_1a2b3c last month?" or "What is the average cost of a chatbot interaction?"
A more advanced, though less common, approach bypasses manual instrumentation entirely. As described by DoIT International, it's possible to use an eBPF sensor in the kernel to extract unit cost metrics directly from runtime, correlating network traffic to specific processes without needing manual tagging or data pipelines. This promises a future where allocation is automatic, but for most teams today, the path is through deliberate instrumentation.
A worked example: Costing a "Smart Summarizer"
Let's make this concrete. Imagine a feature that summarizes uploaded documents. A user uploads a 5,000-word article.
Step 1: Estimate Input Tokens A common rule of thumb is that one token is roughly 0.75 words.
5,000 words / 0.75 ≈ 6,667 tokens for the user's document.
Our system prompt, which instructs the model to be a "world-class business analyst," is 500 tokens long.
Total Input Tokens: 6,667 + 500 = 7,167 tokens.
Step 2: Estimate Output Tokens We ask for a 300-word summary.
300 words / 0.75 ≈ 400 tokens.
Step 3: Calculate the Cost Let's use some plausible, generic 2026 pricing for a capable model:
Input: $3.00 per million tokens ($0.000003 per token)
Output: $15.00 per million tokens ($0.000015 per token)
The cost for this single user action is:
Input Cost: 7,167 tokens * $0.000003/token = $0.0215
Output Cost: 400 tokens * $0.000015/token = $0.0060
Total Cost per Summary: $0.0275
This number, $0.0275, is your unit cost. Now you can make business decisions. If you expect 100,000 summaries per month, your estimated feature cost is $2,750. If your pricing model can't support that, you need to either change the price or reduce the cost.
The pre-flight check: From modeling to control
Modeling is passive. Control is active. The most powerful step you can take is to check the estimated cost before you execute the API call. By aborting requests that are predictably expensive, you cap your financial exposure.
This is especially critical for features that handle variable user input. What if the user uploads a 150,000-word dissertation instead of a 5,000-word article?
150,000 words / 0.75 ≈ 200,000 tokens.
Input Cost: (200,000 + 500) * $0.000003 = $0.60
Total Cost: ~$0.61
This single request costs over 22 times more than the average. Ten such users could blow your feature's budget for the month.
The solution is a pre-flight check in your code. Before you send the request to the LLM, you perform the same cost calculation.
# Pseudocode for a pre-flight cost check
# Define model pricing and a cost ceiling for this action
INPUT_TOKEN_PRICE = 0.000003 # $3/M
OUTPUT_TOKEN_PRICE = 0.000015 # $15/M
ACTION_COST_CEILING = 0.10 # $0.10 per summary
def get_summary(document_text: str, system_prompt: str) -> str:
# 1. Estimate token counts
input_tokens = estimate_tokens(document_text) + estimate_tokens(system_prompt)
# Assume max possible output tokens for a conservative ceiling check
estimated_output_tokens = 2000
# 2. Calculate the estimated cost
estimated_cost = (input_tokens * INPUT_TOKEN_PRICE) + \
(estimated_output_tokens * OUTPUT_TOKEN_PRICE)
# 3. Enforce the ceiling
if estimated_cost > ACTION_COST_CEILING:
# Abort the request before it happens
raise CostExceededError(
f"Estimated cost ${estimated_cost:.4f} exceeds ceiling of ${ACTION_COST_CEILING}"
)
# 4. If cost is acceptable, proceed with the actual API call
# response = llm_client.create_completion(...)
# log_actual_cost(response) # Log the real cost for reconciliation
# return response.completionThis check transforms cost from an observability problem into a control problem. Instead of being a victim of your bill, you are setting the terms. It allows the system to fail gracefully, perhaps by asking the user to shorten their document, rather than generating a bill you can't afford. It also creates opportunities for optimization. For that expensive system prompt, techniques like prefix caching — where the provider processes the prompt once and reuses it for subsequent calls — can deliver cost reductions of up to 90% on the cached input, as noted in documentation for providers like Anthropic.
The case against this model (and why it fails)
When I propose this level of instrumentation, I hear three common objections.
1. "It's too complex. We'll just watch the total bill and optimize later." This is the most common and most dangerous objection. It assumes that "the bill" is a useful optimization target. It's not. By the time the invoice arrives, the money is spent, and you have no granular data to guide your actions. You are left with blunt instruments: turn the feature off, rate-limit all users, or switch to a cheaper, dumber model. Attributing cost at the point of action is the only way to perform surgical optimization, like identifying that 90% of your cost comes from 2% of your users who are re-summarizing the same long documents.
2. "We move too fast to build this. It will slow down product development."
This is like saying you're too busy driving to check the fuel gauge. Building without a cost model isn't moving fast; it's accumulating a hidden form of debt. As SaaS Capital and Bessemer have pointed out, when your infrastructure COGS crosses the 15% threshold, you have a fundamental architectural problem that compresses your gross margin. An unprofitable AI feature is technical debt with interest payments charged directly to your credit card. Taking the time to build a cost_per_action function is an investment that pays for itself the first time you prevent a single budget-breaking user session.
3. "This is for API models. We run our own, so we don't pay per token."
This objection mistakes the unit of payment for the unit of cost. If you self-host, you don't get a per-token bill, but you absolutely have a per-token cost. It's just obfuscated. The cost is in the amortization of your expensive GPU servers, the power they consume, and the engineers you pay to maintain them. The principle of unit economics is even more critical here. You must connect that fixed infrastructure spend to the business activity it supports. This requires the same allocation layer — using Kubernetes labels, eBPF, or other methods — to determine what fraction of a GPU's time was spent on feature-A versus feature-B. Without this, you cannot know if your self-hosting strategy is actually cheaper than paying a vendor.
What would change my mind
My argument is that, given how AI models are priced and built today, working out the cost of every single user action isn't optional — it's a basic requirement for building a product that can actually turn a profit.
Two changes could make this argument outdated.
The first is a shift in how AI providers charge for their models. If a major provider offered a genuinely affordable flat-rate or unlimited-use plan for a powerful model, the need to track every token would fade. The cost would become one predictable number in your budget, and the problem would shrink back down to ordinary capacity planning — how much infrastructure you need overall, not how many tokens each individual user burns.
The second is a shift in what cloud and AI platforms build in by default. If providers began offering real-time, per-request cost tracking — automatically tagged with information about which feature or customer triggered each call — teams wouldn't need to build this instrumentation themselves.
Until either of those happens, the responsibility sits with the people building the product. An invoice only tells you what already happened; it can't help you decide what to do next. To control what your AI feature actually costs, you have to work it out in advance, one user action at a time.
References
The Unit Economics of AI (2026): Why Most Startups Will Fail Without This Strategy ↗
Kubernetes Unit Economics: How to Track Cost per Customer, Feature, and Workload ↗
A C-Level Guide to LLM Unit Economics: Calculating Your Cost-Per-Token ↗
Understanding Token Cost Anatomy: The Five-Headed Bill Nobody Budgeted For ↗

