Repository navigation
Dollar budgets: count unpriced calls and sub-agents, fail closed (#222) - #227
Merged
Merged
Conversation
A dollar budget could quietly never trigger: calls on a model with no price added nothing to the spend, a database error while summing counted as $0, and an agent's budget left out its sub-agents' spend. - TokenUsageService.get_spend_since returns (dollars, unpriced calls), or None on a database error; it replaces get_cost_since. Agent scopes can include the agent's sub-agents (parent_agents), as can get_agent_tokens_since. - rate_limit_config gets block_unpriced and include_sub_agents (V043, off by default). block_unpriced treats unpriced calls in the period as over the dollar budget; include_sub_agents widens an agent's daily token limit and dollar budgets to its sub-agents. - A block dollar budget refuses the request when its spend can't be read. - Rate Limits page: both switches in the form; Usage vs Limits warns when the scope had unpriced calls. - Dollar budget alerts say how many calls had no price, and skip a round whose spend can't be read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #222.
A dollar budget could quietly never trigger, for three reasons:
Changes
TokenUsageService.get_spend_sincereplacesget_cost_since.(dollars, unpriced calls), orNoneon a database error.agents_config.parent_agents.get_agent_tokens_sincecan do the same.rate_limit_configgets two new columns,block_unpricedandinclude_sub_agents(migration V043 for SQLite, PostgreSQL and MySQL). Both are off by default.block_unpriced: unpriced calls in the period count as over the dollar budget.include_sub_agents: an agent's daily token limit and its dollar budgets also cover its sub-agents. The API forces it to false for any scope other thanagent, and refuses non-boolean values with a 400.blockdollar budget now refuses the request when the spend can't be read. Before, it allowed it.Docs
docs/user/rate-limits.md,docs/user/alerts.md,docs/dev/alerts.md, the generateddocs/reference/database.md, andCHANGELOG.md.gen_docs.py driftalso lists three guides. They still hold because none of them describes the changed parts:docs/user/usage-and-audit.mdcovers the Usage page, not dollar spend per scope.docs/dev/database-and-migrations.mdcovers the migration mechanics, which didn't change.docs/dev/template-format.mddoesn't touch rate limits.Testing
python -m unittest discover -s shared/test): 1483 tests, 1 skipped.test_usd_budgets.pyhas new cases for unpriced calls, the sub-agent tree, fail-closed on a database error, and validation of the switches.python scripts/gen_docs.py --checkpasses.Generated by Claude Code