Skip to content

12. Cost

This section gives the formula for what one analysis costs (12.1), a worked example with made-up prices (12.2) and the controls that keep spend bounded (12.3). Exact limits and edge cases are in the table "Details" at the end (12.4).

12.1. Formula

inference cost =
    uncached input tokens / 1,000,000 * input price
  + cached input tokens   / 1,000,000 * cached input price
  + output tokens         / 1,000,000 * output price

Count every call of an analysis: tool steps, retries and escalations. OpenAICompatible usage is untrusted: charge at least the input estimate, with a ceiling of input plus output bound and a rounded-up 10% margin. Above-ceiling reports are refused and charged that ceiling, and every attempt of a retried call that the endpoint may have billed is charged on its own (ADR-0042). Check how reasoning tokens and long context are billed for the chosen model. A call with unknown usage is counted at its upper bound, except a call the host refused before processing it, such as a Foundry 429, which is counted as 0 tokens (12.3).

12.2. Illustration (made-up prices, not a quote)

100 analyses a day for 30 days, each 6,000 input and 1,500 output tokens: 18 M input and 4.5 M output tokens a month.

Variant Input per 1 M Output per 1 M Result
A, cheaper 0.20 USD 0.80 USD 18 × 0.20 + 4.5 × 0.80 = 7.20 USD/month
B, stronger 2.00 USD 8.00 USD 18 × 2.00 + 4.5 × 8.00 = 72.00 USD/month

What the figures are. A single-call baseline for the model path, not an upper bound. Retries, tool steps and escalations add calls (12.1). Runbook matches make no model call and cost nothing.

With escalation. The common case is one call to A. Say a made-up 5% of analyses also escalate to B with the same context size: 7.20 + 0.05 × 72.00 = 10.80 USD/month. Real escalations cost more, because they also run tools.

12.3. Controls

Real prices

Real prices come from the model card, the deployment configurator and the Azure Pricing Calculator. Record them with the date checked.

What the app enforces

The app enforces maximum context, steps, output tokens, concurrency, analyses per day and a daily spend limit, with the gaps listed below. All are set in RemediationSettings (5.4): the count of analyses in spec.analysis.maxAnalysesPerDay, the others beside it in spec.analysis.

built The analysis loop (internal/analysis, 3.3) enforces steps, output tokens, concurrency and the count of analyses, a token bound per analysis, and maxTokensPerDay of each deployment within one analysis. The analyzer starts it only with --triage-model (#76); without it only the trigger reads the count (3.2). The context's total bound is maxContextBytes (#981), counted on the context text before escaping and wrapping, so the context sent can be several times that size (#1054); its section bounds are constants of the context builder (#372). Planned. The daily spend per deployment across analyses needs its counter (#208).

Why an Azure budget is not enough

An Azure budget only alerts. It does not stop usage (budgets).

Keeping calls down

  • Deduplication and cached diagnoses keep repeated calls down.
  • A failed or timed-out call is charged at its upper bound: the input estimate (the provider blocks sent back included) plus the most output the call can be billed, which is MaxOutputTokens, or for the Anthropic adapter MaxOutputTokens plus its thinking allowance (#728).
  • Two cases are charged 0 tokens because nothing of them was billed: a call that sent no request on any attempt, and a call whose every attempt the host refused before processing it. The second is a fact each adapter states about its host, never a status check in the budget code. Only the Foundry adapter states it, for a call answered with HTTP 429 on every attempt: Microsoft's Azure OpenAI FAQ says a request refused for exceeding the rate limit is not charged (#725). That source covers Azure OpenAI models. The adapter applies the rule to every deployment it calls on a host Microsoft operates, one whose name ends in .openai.azure.com, .cognitiveservices.azure.com or .services.ai.azure.com (an exact suffix match on the lower-cased host, never a substring). For other Foundry Models (partner models, which ADR-0016 notes may be billed through Marketplace) it is unverified. A call to any other host (a gateway, a proxy, a custom domain) keeps the upper bound: what sits in front of the model may bill a request and still answer 429. The status comes from the HTTP response the adapter received before the attempt's deadline, never from a body or from model output. Any other attempt in the same call (a timeout, a cut connection, 408, 5xx, a 200 that was billed) keeps the upper bound, since the host may have run the model. The Anthropic adapter keeps the upper bound for a 429 until the same is confirmed for its API. A throttled call still uses its analysis's unit of maxAnalysesPerDay, so a host that throttles every call cannot be retried for free without an end.

The daily count of analyses

The count lives in the ConfigMap shadewright-analysis-budget in the operator namespace. Only the analyzer and admins may write it.

  • A count that cannot be read or written, or that is missing, means refuse, not allow (section 3.2, #43).
  • built One unit is one claimed attempt, not a call and not money; see ADR-0025. The analysis loop reserves it before its first model call, when the analyzer runs with --triage-model (#76).

The spend limit

The spend limit is a count of tokens per model deployment and UTC day (maxTokensPerDay), not an amount of money. Until the daily counter exists it is a ceiling for one analysis, and the daily bound on spend is maxAnalysesPerDay times this ceiling. An analysis counts for the UTC day on which it starts, so one still running after midnight (at most 9 minutes) spends in the new day without a unit there: a day can pass that product by one ceiling for each analysis in flight at midnight.

  • Why tokens. Tokens are what the provider reports and bills, and they are whole numbers with no rounding. A money limit would need a price list in the settings that goes stale.
  • Why per deployment. The triage and escalation models differ in price.
  • No default. The admin sets it for each deployment.

The money it allows is at most that count times the deployment's highest price per token (12.1). That holds only if the counter reserves a call's upper bound (the input bound plus the most output the call can be billed) before calling, under one lock shared by concurrent analyses, and settles to the real usage afterwards.

Planned. That is a requirement on the counter (#208). Where it is counted is open (#208).

The lab

The lab itself (AKS node, Key Vault, storage, Foundry) is priced in shadewright-azure and runs only when needed (ADR-0008).

12.4. Details

Topic Detail
Illustration volume 100 analyses a day, 30 days, 6,000 input and 1,500 output tokens each
Illustration escalation rate 5% to variant B
Failed or timed-out call Charged at input estimate plus MaxOutputTokens (plus the thinking allowance with the Anthropic adapter); OpenAICompatible instead charges C = I + O + ceil((I + O) / 10)
Throttled call (Foundry 429 on every attempt, Microsoft host suffixes only) Charged 0 tokens, still uses its analysis's unit of maxAnalysesPerDay (#725); an Anthropic or OpenAICompatible 429 keeps the upper bound
Spend limit unit Tokens per model deployment and UTC day (maxTokensPerDay), no default
Budget ConfigMap shadewright-analysis-budget, operator namespace, writable by the analyzer and admins only
Count unreadable, unwritable or missing Refuse

For OpenAICompatible, missing or incomplete usage is refused with UsageUnknown and charged the ceiling C = I + O + ceil((I + O) / 10), where I is the input estimate and O is maxOutputTokens. A gateway's 429 is not assumed unbilled. The adapter lists every attempt the endpoint may have billed (each one that got a response or may have reached a connection; not a refused dial or an unreadable key file), and the loop charges each: C when its usage is unknown, max(I, R) when it reported R. The loop tells the adapter how many attempts its remaining analysis and daily budget covers at C, and the adapter retries no further, so one call cannot pass maxTokensPerDay. An endpoint that reports less than it billed is charged the larger of I and its report, so it can undercount by up to O per attempt. These counts feed the existing per-analysis deployment token bounds; persistent daily reservation across analyses remains planned (#208).