Skip to content

AI cost guards: daily ceiling, shorter answers, token log - #3

Merged
codephilip merged 1 commit into
mainfrom
feat/ai-cost-guards
Dec 2, 2026
Merged

codephilip merged 1 commit into
mainfrom
feat/ai-cost-guards

Conversation

@codephilip

Copy link
Copy Markdown
Owner

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.

  • Daily ceiling FORGE_AI_DAILY_MAX (default 50): billed answers per UTC day, for everyone together, counted in a new ai_usage table 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.
  • Shorter answers: FORGE_AI_MAX_TOKENS (default 4000, was a fixed 8000), thinking included. Answers are ~150 words.
  • Rate limit default 10 per 10 minutes (was 40). Behind Traefik all visitors share one IP, so it's a global limit; the docs say so now.
  • Visibility: every call logs model, item and input/output tokens; tokens are summed per day; /api/state has ai.used_today and ai.daily_max.
  • Default model claude-opus-5-5 (was claude-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.

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
codephilip merged commit f9d0f64 into main Dec 2, 2026
2 checks passed
@codephilip
codephilip deleted the feat/ai-cost-guards branch December 2, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant