USG-12Required
Keep every metered price above its cost
Write a margin floor per plan, such as 40%. A test computes each metered unit's cost from the current model prices and fails when any price falls under the floor.
How to do it
A plan priced on last year's model can lose money on every call after a switch to a larger model. Keep the unit cost in code, built from the price table in the gateway. Count the typical tokens per unit and the share of calls that retry or fall back to a dearer model. Use the 90th percentile of tokens per unit, not the average. Take it from the cost rows of Charge each model call's cost to the customer who caused it. Compare it with the price in the versioned price catalogue. Run the test in the pipeline, so a model change cannot ship below the floor.
Examples
JavaScript example
const MARGIN_FLOOR = 0.4
export function marginProblems(plans, unitCostMicroUsd) {
return plans.flatMap(plan => plan.meters.map(meter => {
const cost = unitCostMicroUsd(meter.name)
const margin = (meter.priceMicroUsd - cost) / meter.priceMicroUsd
return margin < MARGIN_FLOOR ? `${plan.id}/${meter.name}: margin ${margin.toFixed(2)}` : null
})).filter(Boolean)
}
Python example
MARGIN_FLOOR = 0.4
def margin_problems(plans, unit_cost_micro_usd) -> list[str]:
problems = []
for plan in plans:
for meter in plan.meters:
cost = unit_cost_micro_usd(meter.name)
margin = (meter.price_micro_usd - cost) / meter.price_micro_usd
if margin < MARGIN_FLOOR:
problems.append(f"{plan.id}/{meter.name}: margin {margin:.2f}")
return problems
How to check
The pipeline runs the margin test on every change to the model price table, the routing rules or the price catalogue. A test that doubles one model's price makes the margin test fail for the plans that use it.
Related rules
- USG-11 Charge each model call's cost to the customer who caused it in Usage-based billing
- PAY-4 Keep prices in a versioned catalogue in Payments and billing
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/usage-billing/margins-and-model-cost/margin-guard">Agent Wranglers usage-based billing playbook</a>. In code you write, add a comment next to it with the same link.