Agent Harness Tutorial · Cost
How cost is measured
The harness prices every model response the moment it arrives, using a price table in the code. The running total for the turn goes on the trace and is checked against the turn's ceiling.
| Model | Per million tokens in | Per million tokens out |
|---|---|---|
| openai/gpt-oss-120b (used) | $0.15 | $0.75 |
| openai/gpt-oss-20b | $0.10 | $0.50 |
The prices are approximate, dated 1 September 2026. A model with no price fails at start-up; it is never priced as free. APIM also emits its own token counts per call (llm-emit-token-metric, namespace claims-fnol) into Application Insights, so there is a second, independent count.
Why our own meter? Azure bills by resource. Only our meter can say "this registered claim cost $0.00039".
Code view: input, process, output, the call stack, the classes
Goes ineach model call's token usage
What happensA fresh Meter per task looks up the model's price at startup, prices every call in Decimal, adds it up, and the loop stops before the next tool step once spend reaches the ceiling.
Comes outspend so far, cost per call, ceiling reached?
How it is done: the real code
Cut from the live repositories each time the site is built, so it always matches what runs.
agent_harness/cost/__init__.py:64The price tablePRICES: dict[str, Price] = {
"openai/gpt-oss-120b": Price(Decimal("0.15"), Decimal("0.75")),
"openai/gpt-oss-20b": Price(Decimal("0.10"), Decimal("0.50")),
"qwen/qwen3.8-27b": Price(Decimal("0.15"), Decimal("0.60")),
}agent_harness/cost/__init__.py:93The meter: one per turnclass Meter:
"""Accumulates spend across one run and answers whether the ceiling is past.
Constructed with the price resolved, so an unknown model fails when the run
is set up rather than three calls in.
"""
def __init__(
self,
model: str,
*,
ceiling_usd: float | Decimal,
prices: dict[str, Price] | None = None,
) -> None:
self.model = model
self.price = price_of(model, prices)
self.ceiling = Decimal(str(ceiling_usd))
self.spend = Decimal(0)
self.calls = 0
def record(self, usage: Usage) -> Decimal:
"""Price one call, add it, and return what it cost."""
amount = cost_of(usage, self.price)
self.spend += amount
self.calls += 1
return amount
@property
def exceeded(self) -> bool:
return self.spend >= self.ceiling
@property
def remaining(self) -> Decimal:
return max(Decimal(0), self.ceiling - self.spend)