A feature can look healthy in a product dashboard while quietly becoming more expensive every time a customer uses it.
That is the trap with AI features. A team sees rising usage, a good demo, and a familiar subscription price. Meanwhile, inference, retries, vector retrieval, tool calls, and human review pile up beneath the surface. The feature is popular—but its economics may be moving in the wrong direction.
AI-adjusted gross margin makes that visible. It treats customer-facing AI costs as part of the cost of delivering the product, then connects those costs to the tenant, feature, and outcome that created them. This guide shows how to calculate it, instrument it, and use it without turning a small engineering team into a finance department.
The practical payoff: you will know which AI workflows are worth scaling, which need a cheaper architecture, and which need a different pricing or usage boundary before margin erosion becomes a surprise.
Why normal gross margin misses the important part
Traditional software margins are attractive partly because an additional customer often adds little delivery cost. AI changes that shape. Each successful user action may trigger variable work:
- input and output tokens
- model hosting or inference requests
- embeddings and vector retrieval
- reranking, OCR, speech, image, or browser actions
- workflow orchestration, tracing, and evaluation
- human review or support caused by weak outputs
A model bill is not the whole story. A low-cost call that causes two retries and a support ticket is not cheap. Conversely, a higher-cost workflow can be excellent economics if it completes a valuable job on the first pass.
The core question is therefore not, “What did we spend on models?” It is:
“After every direct AI delivery cost, does this feature still produce the margin we expect?”
That question matters now because agentic workflows expand the number of billable steps. Current developer tooling emphasizes orchestration, web context, agents, and observability; each can be useful, but each can also create more variable cost. Recent AI finance guidance has also started separating AI-specific COGS from general operating spend. Builders need the same discipline at implementation level.
The AI-adjusted gross margin formula
Use a consistent definition before collecting data:
AI-adjusted gross margin =
(AI feature revenue − traditional delivery COGS − AI delivery COGS)
÷ AI feature revenue × 100
Where:
- AI feature revenue is revenue you can reasonably attribute to the feature, plan, or usage tier.
- Traditional delivery COGS includes direct hosting, payment processing, and support costs already recognized as delivery costs.
- AI delivery COGS includes direct customer-facing inference and AI infrastructure costs.
Here is a small monthly example:
| Item | Amount |
|---|---|
| Attributed AI feature revenue | $20,000 |
| Traditional delivery COGS | $2,000 |
| Model inference | $4,800 |
| Embeddings and vector search | $550 |
| Tool and workflow execution | $900 |
| AI observability and evaluation | $450 |
| Human review directly required by the feature | $1,300 |
| AI-adjusted gross margin | 50% |
Calculation:
($20,000 − $2,000 − $4,800 − $550 − $900 − $450 − $1,300) / $20,000
= 50%
Do not use this number to judge an entire company on day one. Start with one feature or workflow. A document extraction queue, research assistant, support copilot, or AI-generated report is a workable unit.
Decide what belongs in AI COGS
Consistency matters more than a perfect universal rule. Work with whoever owns finance and keep a short written policy.
| Include as direct AI COGS | Usually exclude or allocate separately |
|---|---|
| Production inference used for a customer request | Experimental model research |
| Per-request embeddings, reranking, OCR, speech, or image generation | General engineering salaries |
| Customer-facing vector database reads and storage when material | Internal developer AI subscriptions |
| Per-run browser, data, or tool API fees | Broad brand marketing |
| Production workflow and observability charges tied to use | One-time architecture work |
| Required human review per delivered result | Unrelated support work |
Two judgment calls deserve care.
First, do not put every engineering expense into a per-feature margin calculation. That makes the metric noisy and hides the variable levers engineers can actually change. Second, do not pretend AI observability is free if it scales directly with production workload. If traces are required to operate the service safely, they are a delivery cost.
Start with an event ledger, not invoices
Vendor invoices arrive late and rarely explain why a tenant became expensive. Build an event ledger at request time instead. Each AI workflow should emit a normalized cost event after every metered step.
A useful minimal record looks like this:
type AiCostEvent = {
occurredAt: string;
tenantId: string;
workflowId: string;
runId: string;
feature: "report" | "assistant" | "extractor";
provider: string;
model?: string;
costType: "inference" | "embedding" | "tool" | "vector" | "review";
quantity: number;
unitCostUsd: number;
estimatedCostUsd: number;
outcome?: "accepted" | "retry" | "failed" | "escalated";
};
export function recordCost(event: AiCostEvent) {
return db.aiCostEvents.insert({
...event,
estimatedCostUsd: Number(event.estimatedCostUsd.toFixed(6)),
});
}
The runId is vital. It joins a model call to tool use, retries, a user acceptance signal, and any review task. Without it, teams only see a provider total and start guessing.
Use an estimated rate during the request, then reconcile it against provider invoices later. Keep both values. Estimate is for fast controls; billed cost is for accounting accuracy.
Attribute cost to the right customer and feature
A single model gateway makes attribution easier, but it is not required. The rule is simple: every customer-facing AI call receives a tenant ID, feature ID, run ID, and cost center before it is dispatched.
Avoid these common shortcuts:
- One shared “AI” bucket. It cannot tell you whether search, chat, or extraction is causing erosion.
- Only logging tokens. Tool APIs, retrieval, retries, and review can matter as much as tokens.
- Using user ID alone. A user may belong to multiple workspaces; billable ownership is often the tenant.
- Treating a retry as a separate success. Retries are part of the cost of the original job.
For shared platform costs, pick a transparent allocation key. Examples include successful workflows, retrieval requests, stored vectors, or active tenants. Document the key and avoid changing it every week; otherwise trend comparisons become meaningless.
Add outcome quality to the margin view
Margin without outcome quality creates a perverse incentive: make the answer cheaper even if customers have to repair it.
Track at least these four companion metrics:
| Metric | What it reveals |
|---|---|
| Cost per successful outcome | The true delivery cost of accepted work |
| Retry rate | Whether cheap first attempts create expensive loops |
| Escalation rate | Human labor hidden behind automation |
| AI-adjusted gross margin by tenant cohort | Whether heavy users improve or damage unit economics |
For example, Workflow A may cost $0.08 per request and Workflow B $0.18. If A succeeds 40% of the time and B succeeds 90% of the time, their cost per accepted outcome is $0.20 and $0.20 respectively—before support effort. The “cheaper” option is not automatically better.
This is the practical gap in many margin explainers: they describe the formula but stop before showing engineers how to connect cost to a real accepted outcome.
Build a margin dashboard engineers can act on
A useful dashboard should answer a decision, not decorate a board slide. Start with five cuts:
- Feature: Which workflow produces or loses margin?
- Tenant cohort: Are trials, paid plans, or power users behaving differently?
- Model and route: Is a fallback or reasoning route driving spend?
- Outcome: Are retries and escalations concentrating in one step?
- Time: Did a prompt, model, retrieval, or pricing release move the trend?
A compact query could look like this:
SELECT
feature,
date_trunc('week', occurred_at) AS week,
SUM(estimated_cost_usd) AS ai_cogs,
COUNT(DISTINCT run_id) AS runs,
COUNT(*) FILTER (WHERE outcome = 'accepted') AS accepted_events,
SUM(estimated_cost_usd) /
NULLIF(COUNT(*) FILTER (WHERE outcome = 'accepted'), 0) AS cost_per_accepted_event
FROM ai_cost_events
GROUP BY 1, 2
ORDER BY week DESC, ai_cogs DESC;
This is not the final finance report. It is an engineering control surface. Pair it with a revenue table and your stated allocation policy to calculate the full AI-adjusted gross margin by feature.
Use margin controls before usage becomes a bill shock
Once cost is observable, put guardrails near the workflow—not only at the invoice stage.
Set a budget per run
Give each run a maximum cost based on task value and plan. The budget should include the expected fallback and tool path, not just the first model call.
if (ledger.runCost(runId) > policy.maxRunCostUsd) {
workflow.pause(runId, {
reason: "budget_exceeded",
nextAction: "return_partial_result_or_request_approval",
});
}
A pause is often better than a hard error. It lets a customer choose a lower-cost answer, wait for approval, or narrow the request.
Route by task, not by habit
Use the smallest reliable model and retrieval path for each task class. A classification, extraction, long-form reasoning task, and tool-driven workflow do not deserve the same default. Evaluate quality before changing routes, then watch cost per successful outcome—not raw token cost—after rollout.
Cache stable work carefully
Prompt caching, embedding reuse, deterministic extraction results, and tool-result caching can reduce direct AI COGS. Cache only when tenant permissions, source freshness, and personalization are preserved. A cheap stale answer can create more expensive correction work.
Put limits on fan-out
Agent workflows can multiply cost through parallel searches, repeated tools, and self-repair loops. Set explicit caps for tool calls, retrieved chunks, retries, and model turns. Log the cap that stopped a run so you can distinguish a true product limit from a model failure.
Review the metric on a useful cadence
Daily alerts are for fast failures: a route regression, runaway tenant, or tool loop. Weekly reviews are for engineering choices. Monthly reviews are for pricing, packaging, and capacity decisions.
A strong weekly review asks:
- Which feature had the largest AI COGS increase, and why?
- Did success rate change with cost?
- Which tenants exceeded their expected usage envelope?
- Did a model, prompt, or retrieval change improve cost per successful outcome?
- Is a temporary promotion, trial, or free tier masking the steady-state margin?
Do not automatically restrict the highest-cost tenant. First see whether the tenant is also the most valuable, whether their workflow is unusually successful, and whether the problem is a product design issue such as unlimited retries.
A practical rollout plan
Start small and improve the data in layers.
Week one: define. Pick one paid AI workflow, define revenue attribution, write the COGS policy, and name an accepted outcome.
Week two: instrument. Add the cost event ledger at the model gateway and major tools. Capture tenant, feature, run, route, quantity, and estimated cost.
Week three: reconcile. Compare estimated provider totals with billed totals. Fix rate cards, rounding, and missing events.
Week four: control. Add per-run budgets, retry caps, and a feature-level margin dashboard. Test limits with representative customer flows.
The goal is not perfect accounting. It is a trustworthy feedback loop that informs product and architecture decisions while there is still time to make them.
Where this fits in a production AI architecture
AI-adjusted gross margin belongs in the production AI architecture pillar, alongside model routing, observability, evaluation, and outcome measurement. It is a middle-funnel implementation topic: readers are past the prototype and need an operating model.
Useful companion topics include an LLM gateway control plane, an AI outcome conversion metric, agent observability, and agent cost forecasting. Together they form a content cluster around reliable AI economics: route work well, measure the full cost, verify the outcome, and act on the signal.
FAQ
What is AI-adjusted gross margin?
AI-adjusted gross margin is gross margin after subtracting direct AI delivery costs such as inference, embeddings, retrieval, tools, evaluation, and required review from attributed feature revenue.
How is AI-adjusted gross margin different from cost per request?
Cost per request measures one technical event. AI-adjusted gross margin connects all direct delivery costs to revenue. It can reveal that a cheap request is unprofitable after retries, support, and related AI infrastructure.
Should AI observability be included in AI COGS?
Include it when the cost scales directly with production AI usage and is necessary to operate the customer-facing feature. Keep the policy consistent and separate broad, fixed engineering tooling where appropriate.
How do I calculate AI revenue for a bundled feature?
Use a documented attribution rule, such as a separate add-on price, usage revenue, a plan allocation, or a controlled cohort comparison. The goal is a stable decision metric, not false precision.
What is a good AI-adjusted gross margin?
There is no universal target. Compare the metric with your product’s required margin, the value created for customers, and the trend over time. A lower margin can be acceptable for a high-value workflow; an unexplained downward trend is not.
Can small teams measure this without a finance system?
Yes. Start with an event ledger, a simple revenue export, and monthly invoice reconciliation. One well-instrumented workflow is more useful than a broad dashboard built on guessed allocations.
Why track cost per successful outcome too?
It protects quality. Without it, teams can optimize for cheaper model calls that generate more retries, edits, and human escalations. Successful outcomes connect cost to the work customers actually value.
Top comments (0)