A company-wide margin can look healthy while a few customers cost more to serve than they pay. AI products are especially exposed when a fixed subscription funds variable inference, tool calls, and human review. A per-customer report shows where pricing and delivery costs no longer fit.
This guide focuses on customer allocation and operational decisions. For the broader cost-of-revenue framework, read how to calculate AI SaaS gross margin. The examples below are illustrative, not industry benchmarks.
What is the AI gross margin formula?
Customer gross profit = recognized customer revenue − customer cost of revenue
Customer gross margin % = customer gross profit / recognized customer revenue × 100Use the same reporting period for both sides. Customer cost of revenue includes directly attributable costs plus the customer’s allocated share of applicable shared delivery costs. The Stripe SaaS gross margin guide explains the underlying revenue-minus-cost-of-revenue calculation.
Margin after AI cost is a narrower measure. Subtracting only model spend can help with daily decisions, but it does not become full gross margin until the other applicable delivery costs are included. Gross profit also does not deduct every company expense, so it is not net profit.
Step 1: match revenue to the customer and period
Choose a stable paying-account ID. An end user, workspace, and billing customer can be three different entities. Map activity to the party responsible for the revenue before comparing it with costs.
Use recognized revenue for accounting gross margin. Cash collected and invoices issued are different measures. For example, if a $12,000 annual service contract is recognized evenly over twelve months under your policy, its monthly revenue is $1,000, even if payment arrived in the first month.
Handle discounts, refunds, credits, and contract changes consistently with the revenue policy. An operational allocation of a credit pack to actions is useful for product analysis, but it is not automatically the accounting recognition schedule. Keep the operational view reconcilable to finance’s recognized revenue.
Step 2: capture all direct costs of serving the customer
| Cost | How to attribute it | Common omission |
|---|---|---|
| Production inference | Model usage linked to customer and execution IDs | Charged retries, failures, cache writes, and background work |
| External tools and data | Paid searches, OCR, speech, retrieval, or API events | Non-LLM steps inside an agent workflow |
| Dedicated infrastructure | Customer-specific compute, storage, and serving resources | Capacity reserved while requests are idle |
| Delivery labor and support | Applicable time records or a documented allocation | Human review needed to finish the service |
| Other cost of revenue | Relevant licenses, fees, or amortization under your policy | Costs recorded outside the usage pipeline |
AI delivery can include compute and human intervention as well as model calls, as discussed in Bessemer’s AI pricing playbook. Classify expenses by purpose: production inference and an internal research experiment should not automatically share the same treatment.
Count real charged attempts once each. Deduplicate telemetry retries without deleting genuine model retries. If a gateway report and a provider bill describe the same inference charge, use one as the cost and the other as reconciliation evidence.
Worked example: AI gross margin for three customers
Assume the following monthly amounts use the same recognized-revenue basis and include all applicable cost of revenue for this illustrative product. There are no unallocated costs in this example.
| Item | Acme | Beacon | Cedar | Total |
|---|---|---|---|---|
| Recognized revenue | $1,000 | $2,000 | $500 | $3,500 |
| Model inference | $250 | $300 | $350 | $900 |
| Tools and external APIs | $100 | $100 | $50 | $250 |
| Allocated infrastructure | $150 | $200 | $100 | $450 |
| Delivery support and review | $100 | $200 | $100 | $400 |
| Total cost of revenue | $600 | $800 | $600 | $2,000 |
| Gross profit | $400 | $1,200 | −$100 | $1,500 |
| Gross margin | 40% | 60% | −20% | 42.9% |
For Acme, the calculation is ($1,000 − $600) / $1,000 × 100 = 40%. Subtracting only its $250 model bill would show 75% remaining after inference, overstating full gross margin by 35 percentage points.
Cedar loses $100 at the gross-profit level even though the portfolio makes $1,500. Review Cedar’s model mix, retries, contract allowance, and human-review workload before deciding whether to optimize delivery or change pricing.
Calculate the portfolio margin from totals: $1,500 / $3,500 × 100 = 42.9%, rounded. Do not take the simple average of 40%, 60%, and −20%, which is 26.7%. Different revenue weights make that average misleading.
Step 4: reconcile the customer report
The report should explain both allocated and unallocated amounts. Compare customer revenue with the recognized-revenue source. Compare cost pools with provider, infrastructure, and delivery-cost records using the same period and currency.
- Unassigned usage: show it separately until you have a supported mapping.
- Provider adjustments: preserve discounts, credits, and corrections rather than treating list-price estimates as invoices.
- Zero revenue: show dollar costs and losses; gross margin percentage is undefined.
- Prepayments: distinguish cash timing from revenue recognition.
- Delayed records: label provisional periods and refresh them when late costs arrive.
Use the AI margin review workflow to organize that review. An operational dashboard can guide decisions before period close, provided its cost coverage and revenue basis are explicit.
Step 5: improve AI gross margin without losing the outcome
Fix the largest verified driver for the affected customer or workflow. Shorten unnecessary context, reduce duplicate tool calls, or route suitable tasks to a cheaper model. Re-run the acceptance checks so lower inference spend does not create more human rework.
When usage grows under fixed pricing, evaluate included allowances, overage terms, or a different plan. Model the customer impact before changing the contract. See whether your AI subscription pricing is profitable and why growing AI usage can reduce profit.
For a target margin of 60% and stable monthly cost of revenue of $600, the required revenue is $600 / (1 − 0.60) = $1,500. This is a planning calculation, not proof that a customer will accept that price or that costs remain fixed as usage changes.
There is no universal AI gross margin target. Compare similar delivery models and accounting boundaries. Track customer and plan distributions alongside the total so a few profitable accounts do not conceal a structurally loss-making segment.
How can Ganivra help track customer margin?
Ganivra connects recorded usage and costs with customer and revenue context to show margin after those costs. Send stable customer IDs with supported model and tool events, supply the relevant revenue data, and include additional delivery costs where applicable.
Start with a margin review, follow the AI margin review workflow, or use the integration guide to inspect the event contract. For selecting a measurement stack, compare AI cost tracking tools.
Keep the label honest: if hosting, support, or recognized-revenue adjustments are missing, the result is margin after recorded costs. Full accounting gross margin requires complete cost coverage and reconciliation to the ledger.
Frequently asked questions
Select a question to read the answer.
How do you calculate AI gross margin per customer?
Subtract the customer’s direct and allocated cost of revenue from recognized revenue for the same period. Divide the difference by that revenue and multiply by 100. Use a consistent allocation policy and reconcile customer totals to company reporting.
Is revenue minus LLM cost the same as gross margin?
No. Revenue minus LLM cost shows what remains after that cost category. Gross margin also includes other costs classified as cost of revenue, such as applicable hosting, delivery labor, support, and third-party services.
How do I allocate shared AI infrastructure costs?
Choose a documented driver that reflects consumption, such as measured compute time, storage, or weighted requests. Allocate the shared pool once, and keep idle capacity or unresolved costs visible according to your policy. Revenue share is a fallback allocation, not a measurement of resource use.
Should failed requests and retries count toward AI customer cost?
Include charged attempts used to deliver that customer’s service, including retries and failed requests. Deduplicate repeated telemetry records, but do not discard genuine separately charged attempts. Keep internal experiments and development activity in their appropriate cost categories.
Can AI gross margin be negative?
Yes. If a customer has $1,000 of recognized revenue and $1,100 of cost of revenue, gross profit is negative $100 and gross margin is negative 10%. A negative result can reveal a pricing or delivery-cost problem; confirm attribution before acting.
What is a good AI gross margin?
There is no universal target. Compare businesses with similar delivery models, service intensity, and cost classification. Set a target that supports your operating expenses and business plan, and monitor customer-level variation rather than relying only on a company average.
What happens when customer revenue is zero?
Gross margin percentage is undefined when revenue is zero. Show the cost and gross loss in dollars and label the percentage not applicable. Track trial, free-tier, and internal usage separately so it does not disappear from the reconciliation.
Can Ganivra calculate my full accounting gross margin?
Ganivra shows margin after the revenue and costs recorded or allocated in its reporting. It represents full accounting gross margin only when the revenue basis, all applicable cost-of-revenue categories, and allocations are complete and reconciled. It does not replace the accounting ledger.