Repository navigation
AI cost guards: daily ceiling, shorter answers, token log - #3
Merged
Merged
Conversation
A billed answer now claims one of FORGE_AI_DAILY_MAX (default 50) per UTC day, stored in the database. Answers are capped at FORGE_AI_MAX_TOKENS (4000, was 8000), the default rate limit drops to 10 per 10 minutes, and each call's tokens are logged and summed per day. Default model moves to claude-opus-5-5, same tier at a lower price.
codephilip
force-pushed
the
feat/ai-cost-guards
branch
from
December 2, 2026 17:10
a26b37d to
45ce79b
Compare
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.
Forge only calls the AI when someone asks: the ✦ explain button (cached per item and state) or a question in Ask Forge. Nothing runs in the background. What was missing was a ceiling.
FORGE_AI_DAILY_MAX(default 50): billed answers per UTC day, for everyone together, counted in a newai_usagetable so a restart doesn't reset it. Cached explanations don't count. Past it, the chat says the limit is used up until midnight UTC.FORGE_AI_MAX_TOKENS(default 4000, was a fixed 8000), thinking included. Answers are ~150 words./api/statehasai.used_todayandai.daily_max.claude-opus-5-5(wasclaude-opus-5): same tier, $4/$20 per MTok instead of $5/$25.Rough worst case at the defaults: 50 answers × ~4k input + ≤4k output tokens on Opus 5.5 ≈ $5/day; a typical day is a handful of questions, cents.
Tests:
tests/test_ai_limits.py(ceiling, day rollover, token sums). All 19 tests pass.