Model cost accounting and per-agent budgets (Milestone C). Every model call records its token usage and dollar cost on the `model.call` audit event. This module is the math and the read side: price a call from a config rate table, roll spend up per agent over a time window, and r
"""Model cost accounting and per-agent budgets (Milestone C).
Every model call records its token usage and dollar cost on the `model.call`
audit event. This module is the math and the read side: price a call from a
config rate table, roll spend up per agent over a time window, and resolve an
agent's budget into an ok / warn / exceeded status. Enforcement lives in
`model_router.call_model` (the single chokepoint for model spend); it uses
`agent_budget` + `agent_spend` from here to hard-stop at the cap and the
`WARN_FRACTION` threshold to soft-warn on the way up.
Pricing and budgets are config, not code:
models:
pricing:
gpt-4o: {input_per_1k: 0.005, output_per_1k: 0.015}
default: {input_per_1k: 0.0, output_per_1k: 0.0}
budgets:
window: 3
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key