All insights

Inference economics

How should a multi-provider AI gateway calculate gross margin when each route has different discounts and cache pricing?

A multi-provider AI gateway should calculate gross margin as revenue minus route-level cost of goods sold, divided by revenue, using the actual effective unit cost for each provider, model, token type, cache state, discount term, and time period. The safest operating pattern is to attribute cost at the request or route level first, then aggregate margin by customer, provider, model, cache state, workload, and billing period so blended averages do not hide unprofitable routes.

A multi-provider AI gateway should calculate gross margin as revenue minus route-level cost of goods sold, divided by revenue, using the actual effective unit cost for each provider, model, token type, cache state, discount term, and time period. The safest operating pattern is to attribute cost at the request or route level first, then aggregate margin by customer, provider, model, cache state, workload, and billing period so blended averages do not hide unprofitable routes.

Start with route-level gross margin, not blended provider averages

For AI gateway economics, gross margin is not simply “customer price minus average provider price.” A gateway can route the same product feature across different providers, models, cache states, and serving modes. Each path may carry a different input-token price, output-token price, cached-token rate, minimum charge, negotiated discount, committed-use term, or private-serving cost.

A practical definition is:

``text Gross margin % = (Revenue - Route-level COGS) / Revenue ``

Where route-level COGS should reflect the direct cost of serving the request through the actual route used. A route might be defined as a combination of customer, application, model, provider, endpoint class, cache state, region or deployment mode, and routing policy.

Blended provider averages are useful for high-level forecasting, but they are not precise enough for production margin control. If low-margin traffic is hidden inside a blended rate, finance may see acceptable aggregate margin while one customer, model route, or cache-miss path is consistently underwater. Route-level accounting helps product, finance, and platform teams answer better questions: which workloads are profitable, which routing policies need review, and which pricing plans need adjustment?

Normalize billable units before comparing provider and model routes

Before comparing routes, normalize what each provider or serving path actually bills for. AI inference is often described in “tokens,” but token accounting can vary across models, providers, and deployment modes. A gateway margin model should avoid assuming that all token counts mean the same thing.

Useful categories to track include:

  • Input tokens sent to the model.
  • Output tokens generated by the model.
  • Cached input tokens or cache-read tokens, where applicable.
  • Cache-write or cache-fill activity, where applicable.
  • Reasoning tokens or other internal billable units, where applicable.
  • Provider-specific minimums, request charges, tool-use charges, or non-token units, where applicable.

The operating goal is not to force every provider into an oversimplified token rate. The goal is to normalize cost telemetry into a consistent internal ledger so finance and engineering can compare routes without losing the underlying billable-unit detail.

For teams validating model demand before private deployment, Token Forge Cloud Managed Model APIs provide a lightweight API-first entry point for model access and usage data. As workloads become more predictable, that usage history can help teams decide whether deeper private deployment and serving-layer control are worth evaluating.

Apply the actual effective unit cost for each route

When discounts, committed-use terms, negotiated rates, private capacity, or provider-specific cache pricing apply, margin should be calculated from actual effective unit cost rather than public list price. List price may be a useful default for simulations, but it can misstate production economics.

A discount-aware route model should account for the conditions under which each rate applies. For example:

  • A provider discount may apply only to certain models, traffic tiers, accounts, or time periods.
  • A committed-use agreement may reduce unit cost but create unused-capacity exposure.
  • A private deployment may replace per-token provider charges with infrastructure, GPU capacity, orchestration, and operations costs.
  • A cache-hit path may have very different cost behavior from a cache-miss path.

The key is to version cost assumptions over time. If a discount changes mid-month, requests before and after the change should not be costed at the same rate. If a route falls back from a preferred provider to a more expensive route during an outage or capacity event, that request should carry the fallback route’s effective cost.

A practical internal cost table should be able to express: provider or deployment mode, model, token category, cache state, rate, discount rule, effective date, and expiration date. Even if the implementation is simple at first, preserving those dimensions keeps margin analysis from becoming a one-time spreadsheet exercise.

Separate cache reads, cache writes, storage, and uncached model calls

Cache pricing deserves separate treatment because caching changes both architecture and economics. A cache hit is not the same cost event as an uncached model call. A cache write may create cost now to reduce repeated work later. Cache storage and refresh behavior may also matter depending on how the cache is implemented and priced.

A margin model should separate the following categories when they apply:

  • Cache hit or cache read.
  • Cache write or cache fill.
  • Cache storage.
  • Cache refresh or invalidation.
  • Uncached model input and output.
  • Fallback to uncached inference when the cache cannot be used.

Averaging cached and uncached traffic into a single token rate can distort decisions. A route may look healthy when cache-hit traffic is high, but become unprofitable when cache misses increase. Another route may look expensive on first request but attractive for repeated prompts, retrieval-augmented workflows, batch enrichment, or high-volume internal assistants.

Token Forge Cloud helps enterprises improve control of inference economics by optimizing the serving layer with caching, routing, batching, quantization, and GPU scheduling. For margin planning, that makes cache-aware cost modeling especially important: the accounting model should reflect the serving policy, not just the final invoice total.

Use a request-level formula before aggregating margin

The most reliable method is to calculate cost at the request level, or at the most granular route level available, then roll up. That creates a clean path from operational telemetry to finance reporting.

A simple pseudocode pattern looks like this:

```text for each request: revenue = customer_price_for_request

route_cogs = input_tokens effective_input_rate(route, time) + output_tokens effective_output_rate(route, time) + cached_tokens effective_cached_rate(route, time) + cache_write_units effective_cache_write_rate(route, time) + cache_storage_units effective_storage_rate(route, time) + other_billable_units effective_unit_rate(route, time)

request_gross_margin = (revenue - route_cogs) / revenue ```

Then aggregate the results by the dimensions that matter to the business:

  • Customer or account.
  • Product feature or application.
  • Route and routing policy.
  • Provider, model, or private deployment pool.
  • Cache state: hit, miss, write, refresh, or bypass.
  • Time period: hour, day, invoice period, contract term.

Request-level attribution is especially useful when product and platform teams use dynamic routing. A single customer workflow may move between model routes based on latency, quality requirements, availability, policy, or cost. Without request-level attribution, the business may only know that aggregate inference spend increased, not which routing decisions drove the change.

Decide which shared serving costs belong in COGS versus overhead

Direct route COGS and shared operating costs should be defined separately, then reconciled according to finance policy. Not every cost must be forced into per-request COGS, but every material serving cost should have a clear treatment.

Direct COGS often includes the provider or infrastructure cost directly required to serve a request. Shared costs may include gateway operations, observability, private serving infrastructure, GPU capacity, routing overhead, capacity buffers, or support costs for specialized workloads. Some businesses allocate a portion of these costs into gross margin. Others track them below gross margin as operating overhead. The important point is consistency.

Private deployment changes this conversation. Instead of only buying per-token access, teams may operate dedicated or semi-dedicated serving capacity. That can introduce capacity planning questions: how much GPU capacity is needed, how much buffer is appropriate for latency-sensitive traffic, and how should idle or reserved capacity be allocated across customers or products?

Token Forge Cloud Private LLM Inference is designed around private deployment and serving-layer optimization for enterprise AI workloads. Token Forge Cloud treats latency-sensitive chat, batch enrichment, and agentic workflows as different serving-policy problems, which is relevant when teams decide how costs should be attributed across different workload classes.

Evaluate whether the gateway gives finance and operations enough cost telemetry

A multi-provider gateway is only as useful for margin control as the telemetry it makes available to finance, engineering, product, and operations teams. Buyers should evaluate whether the gateway can support the cost model they need before relying on it for pricing or margin decisions.

Important evaluation questions include:

  • Can usage be analyzed by request, route, customer, provider, model, cache state, and time period?
  • Can teams distinguish input tokens, output tokens, cached input tokens, cache writes, storage, and other billable units where those categories apply?
  • Can effective cost assumptions reflect discounts, negotiated rates, committed-use terms, private capacity, and date-based changes?
  • Can routing events, cache events, fallback behavior, and model selections be tied back to cost outcomes?
  • Can finance and operations teams reconcile gateway telemetry with invoices, internal chargeback models, or customer pricing plans?
  • Can policy-aware access and private routing requirements be aligned with cost observability requirements?

Token Forge Cloud is relevant for teams evaluating private routing, policy-aware access, telemetry under enterprise control, and serving-layer optimization. Token Forge Cloud Private LLM Inference is the closest fit when the goal is private deployment and operational control over model routing, caching, GPU scheduling, and inference cost behavior. Token Forge Cloud Managed Model APIs can also support teams that want an API-first path to validate model demand before deciding whether private deployment is appropriate.

FAQ

What is the basic gross margin formula for an AI gateway?

The basic formula is gross margin equals revenue minus route-level COGS, divided by revenue. For an AI gateway, route-level COGS should reflect the actual cost of the route used for the request, including provider or infrastructure cost, token category, cache state, effective discount, and applicable time period.

Why should margin be calculated per request before aggregation?

Per-request attribution prevents blended averages from hiding expensive routes, cache-miss paths, fallback events, or unprofitable customers. Once request-level cost is calculated, teams can roll up margin by route, customer, provider, model, cache state, product feature, and billing period.

How should cached tokens be handled in margin accounting?

Cached traffic should be separated from uncached inference. Cache hits, cache reads, cache writes, cache storage, cache refreshes, and uncached model calls can have different cost behavior. Treating them as one blended token rate can make a route look healthier or less profitable than it really is.

Should discounts be applied before or after margin aggregation?

Discounts should be applied at the level where they actually affect cost. If a discount applies to a specific provider, model, token type, route, account, or time period, the effective unit cost for that request should reflect it before aggregation. Applying discounts only after aggregation can distort route-level profitability.

Where does Token Forge Cloud fit in this decision?

Token Forge Cloud helps enterprises improve control over LLM inference economics through serving-layer optimization, including routing, caching, batching, quantization, and GPU scheduling. Token Forge Cloud Private LLM Inference is most relevant for teams evaluating private deployment and operational control, while Token Forge Cloud Managed Model APIs can support API-first validation before workloads become predictable enough for private deployment planning.

Contact us