mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-05 14:02:18 +01:00
app/api/demo/chat is public and unauthenticated, and app/api/custom-bots/[id]/chat lets anonymous callers chat with public bots billed to the bot OWNER's API key. Neither had a limit. Nothing failed, because nothing was checking. Both are closed. The custom-bot limit is scoped per bot id so one hot bot cannot drain another's budget. The reason they drifted is that each route hand-rolled the same block: read the IP, call checkRateLimit with inline magic numbers, return a 429 written slightly differently each time. So the budgets now live in one place (RATE_LIMITS) behind one helper (enforceRateLimit), and the seven existing copies were migrated onto it -- removing three different 429 response shapes and a hand-rolled copy of getClientIp. Never-twice: tests/__tests__/api/rate-limit-coverage.test.ts reads every route file and fails if one imports the LLM client without enforcing a limit, or calls checkRateLimit directly with its own numbers. Verified by mutation -- removing a limit makes it fail and name the file. verify: format, lint, typecheck, 240 tests, build -- all green. Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>