Billing Ledgers
Billing LedgersGross Margin Modeling for AI Inference Products

Gross Margin Modeling for AI Inference Products

A practical guide to tracing inference costs by customer and pricing for heavy users.

· 9 min read

Gross margin modeling for AI inference products begins before pricing is set. The decisive work is to measure cost per task, separate median customers from heavy users, and map those costs to a pricing structure that can withstand token-price swings. Routing improves the economics, but customer-level metering and billing make those economics manageable.

Why AI inference margin is structurally different from SaaS margin — and why the gap is not closing on its own

With traditional SaaS, the marginal cost of each new user is close to zero, while AI inference products pay for every query, agent step, and document they process. The thousandth customer is not nearly free to serve. More importantly, two customers paying the same subscription can generate very different compute bills, so an aggregate P&L can conceal accounts whose usage erodes the margin earned elsewhere.

The gross margin formula is still (Revenue − COGS) ÷ Revenue. What changes is the behavior of COGS. Lower token prices can improve the economics, but they do not remove the link between usage and expense. Doximity’s written response to the SEC committed to enhanced disclosures regarding the impact of AI-related expenditures on cost of revenue and gross profit beginning with its 2026 Form 10-K. That disclosure addresses the company-level picture, while managing the underlying variation requires costs to be traced to individual customers.

What actually belongs in AI cost of goods sold — and what gets misfiled

Misclassification is the first margin error, before pricing or routing enters the calculation. The practical classification test is what triggers the expense. When customer usage triggers a cost, it belongs in cost of revenue, while employee use of internal tools belongs in operating expense. Training runs and experiments are usually R&D, but production inference that serves paying customers is COGS. The label on the invoice does not tell teams where the cost belongs.

That distinction requires teams to examine expenses that resemble generic infrastructure. Cloud AI services can arrive inside a cloud invoice, while vector databases and embedding pipelines can look like storage until their activity is traced to customer queries. Model routing and gateway compute can disappear into the same line as application services. Each needs a deliberate classification decision. For evaluation runs supporting shipped, customer-facing features, the emerging practice treats the expense as COGS when the product cannot function without them.

The same delivery test applies to hosting, retrieval pipelines, and attributable human review. Leaving these expenses out produces only an inference estimate. Free credits introduce another distortion. Teams should model COGS at list prices, keeping cloud or model credits out of the cost assumption. Otherwise, the apparent margin expires with the subsidy, leaving renewal or fundraising discussions to expose the gap.

How to build a per-customer cost-to-serve model across median and heavy-usage cohorts

Once costs are classified, the modeling unit should be the completed customer task. Its inference cost is (input tokens × input price) + (output tokens × output price) − savings from caching and batch discounts. Token counts and quoted prices must be in the same units. For an agent, that calculation must include every model call required to complete the request, including the call that produces the visible answer. Agent overhead belongs in the task total.

A contract-review agent illustrates how to turn that unit into a customer model. First, calculate the inference cost of a review across its model calls, including input and output consumption and applicable savings. Then multiply that task cost by the account’s review volume over the modeled period. Repeat the calculation for accounts with different usage levels. Where task costs vary, the customer total should reflect those task-level costs rather than assume every review consumes the same resources.

The model should put median, P75, and P90 users in separate groups. The median is the customer the pricing was designed for, P75 is the engaged customer, and P90 is the stress test. Each needs a separate cost-to-serve figure. Adding the other delivery costs to each cohort’s inference total produces its COGS, which can then be compared with the revenue that cohort generates. The resulting margins show whether greater engagement remains profitable or turns into an unfunded service obligation.

P90 should not be dismissed as an outlier. In the contract-review example, routing and prompt caching reduce the average seat’s inference cost by roughly two-thirds and lift gross margin from 36% to roughly double that figure. Yet the power user is still close to break-even on inference alone, before other COGS. Teams should therefore assess whether the heaviest users can erase the margin earned by the rest even when the average account is profitable.

How model routing, prompt caching, and batch processing change the cost model — and by how much

Diagram: Routing and Caching Lift Gross Margin Across Usage Cohorts. Visualizes: Show three customer cohorts — Median, P75 (engaged), and P90 (power user) — and how their gross margin changes before and after applying model routing and prompt…

The lesson for improving that model is to change the cost per task before assuming that every shortfall requires a higher price. Model routing sends high-volume, lower-complexity work, including classification, extraction, and summarization, to smaller or fine-tuned models. Judgment-intensive tasks escalate to frontier models. The spread between model tiers makes this a substantial lever. In the contract-review example, the roughly two-thirds inference reduction comes from routing a large majority of tasks to a small model, with the remainder using a frontier model, and caching shared prompt content.

That combined result is not a routing-only estimate. Separating the levers prevents a model from counting the same savings twice. With prompt caching, teams pay cache-read prices instead of full input prices for repeated system instructions, retrieved context, or shared document content. Agents can benefit disproportionately because many calls share a large prompt portion while changing only the content needed for the next step. The savings apply only to that shared portion.

Batch processing offers a different trade-off. Tasks that do not require real-time responses can be queued for processing at the significant discounts most model providers offer relative to real-time calls. Response caching goes further for repeated queries with the same output, serving the answer without another model call and reducing latency as well as cost.

Teams should model conservative routing gains, treating vendor claims of very large reductions cautiously. Routing fixed the median. Even after optimization, the P90 account remained near break-even on inference alone. Cost engineering changes how teams need to price the product, but they still need to charge for unusually heavy usage.

How to map cost-to-serve cohorts to a pricing structure that holds across token-price swings

The pricing choice follows from the distance between P90 cost-to-serve and the proposed price. Flat per-seat pricing absorbs usage variance into gross margin and works when that variance is narrow enough to preserve the intended margin. It fails when a power user’s cost approaches or exceeds the seat price. The cohort model establishes which condition applies. A profitable median is not sufficient evidence for an unrestricted seat plan.

Usage-based pricing instead ties revenue to the cost driver, so customers pay more when they run more tasks. With charges aligned to task costs, higher consumption need not dilute the margin percentage. The trade-off is variable revenue and the possibility that customers throttle usage. Credit-based pricing gives customers a usage budget upfront while keeping what they use tied to what it costs. It provides more predictability without treating all accounts as equally expensive to serve.

A hybrid structure combines a subscription floor covering median usage with charges above a threshold. That threshold should come from the cohort model, establishing an economic boundary between P75 and P90 usage so most customers remain within the flat component while heavier users pay incrementally. Customer visibility into consumption is also necessary to avoid bill shock when usage crosses it. A usage floor or minimum commitment provides a revenue commitment against the COGS a customer will generate rather than leaving heavy early consumption unsupported.

Teams need a separate stress test for token-price swings. A scheduled change in model prices can cut multiple margin points overnight when the prices customers pay stay the same. After establishing an unsubsidized list-price baseline, teams should therefore cost the product using a forward price assumption. That assumption belongs in each cohort calculation because a price change affects heavy consumers more sharply in absolute cost. A pricing structure that works at the current model price may fail before customer contracts can change.

Outcome-based pricing provides another way to separate customer value from raw consumption. Revenue is tied to a delivered result, so a model-layer cost reduction can flow to margin while customer prices stay the same. The constraint is whether the outcome can be measured and attributed. This structure changes what the customer buys while leaving the cost of delivering it unchanged and preserving the need to model inference expense, especially when costs rise.

What the billing infrastructure must do to keep cost-to-serve visible at the customer level

Operationalizing these prices requires usage events and their associated costs to enter the metering process together. Consumption alone cannot reveal customer margin without a later reconciliation. The model needs a live customer-level view. Event ingestion must handle agent workflows that make many calls per minute, and meters for each customer must update without reading the full event log each time. Otherwise, the cohort model remains a planning artifact rather than an instrument for managing delivery economics.

Idempotent ingestion uses event IDs to deduplicate retries, preventing network failures or agent retries from inflating recorded usage. Customers need real-time balances and threshold visibility before an invoice arrives. Those records also support overages, credit wallets, and enterprise commitments. A row-per-event relational database approach is insufficient at AI inference event volumes, where production metering requires stream aggregation and periodic snapshots for billing accuracy.

Flexprice is one purpose-built option, ingesting usage events at millisecond speeds, attaching cost metadata during aggregation and rating, and maintaining real-time per-customer meters. It supports prepaid credit wallets and postpaid invoicing on the same engine, as well as on-premises deployment for customers with data residency requirements. The distinction between capturing cost at ingestion and attaching metadata during aggregation remains important when evaluating the complete data path. Continuous visibility from consumption through cost and billing is required throughout the month.

The alternatives are to extend subscription billing with usage infrastructure or build the metering and billing system internally. Subscription billing covers the fixed component, but hybrid plans also need consumption records that can enforce thresholds and calculate overages. Separate billing codepaths create reconciliation work. Building internally means owning API call recording, aggregation, credits, commitments, and concurrent pricing structures. Multiple pricing dimensions, including tokens, GPU-minutes, audio minutes, and model tier, make that engineering commitment part of the pricing decision.

How to migrate existing customers to cost-reflective pricing without destroying retention

New customers should enter the new pricing immediately, producing 60–90 days of conversion and bill-size data before existing accounts move. A voluntary migration wave can follow with an incentive for participating customers. Their bill sizes, usage patterns, and retention show what to expect as more customers move to the new pricing.

Mandatory migration should begin with customers who are overpaying under the old structure because their actual usage falls well below its assumptions. Timing is part of the design. Existing pricing should remain in place for a defined grandfathering period, with the new structure taking effect at renewal.

The billing engine must support old and new pricing concurrently throughout that period. Otherwise, the move to new pricing adds separate codepaths and a risk of errors in reconciliation just when the team needs customer data it can compare. The cohort model guides the sequence. It shows which customers should move first, what prices their costs support, and whether the revised structure preserves margin as usage changes. As routing, caching, and model prices evolve, those same customer-level records become the basis for pricing adjustments before an annual review.

More in SaaS Finance Metrics