Exempt read-only requests from demo-mode rate limit#8
Merged
Conversation
The demo HTTP catch-all counted every request except / and /api/outputs against the per-IP spend budget. But the limiter's job is to cap provider-key *spend*, and every key-spending REST endpoint is a POST (co_writer edit, voice tts/stt, book compile, partners chat) while chat spend is guarded per-message on the WebSocket loops. Read-only page-load GETs (/api/v1/settings, /tools, /knowledge/list, /settings/llm-options) spend nothing, yet each burned a token — so a single SPA page load fired several at once and normal browsing quickly 429'd on the reads it needed to render. Only count unsafe HTTP methods; exempt GET/HEAD/OPTIONS. Adds a regression test that read-only GETs are never limited even past the per-minute cap. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
On the public demo (
DEMO=true), normal browsing gets429d. A HAR from/homeshowed read-only GETs —/api/v1/settings,/api/v1/tools,/api/v1/knowledge/list,/api/v1/settings/llm-options— all returning429withRetry-After: 30.Root cause
The demo HTTP catch-all (
deeptutor/api/main.py) counted every request except/and/api/outputsagainst the per-IP budget (default 15/min). But the limiter exists to cap provider-key spend — and:/chatand/wsWebSocket loops.Read-only page-load GETs spend nothing, yet each burned a token. A single SPA page load fires several at once, so a couple of refreshes exhaust the minute budget and the app starts
429ing on the reads it needs to render.Fix
Only count unsafe HTTP methods in the demo catch-all; exempt
GET/HEAD/OPTIONS. The WebSocket per-message guard and the/+/api/outputsexemptions are unchanged, and the actual spend cap (all POST spenders) is preserved.Adds a regression test asserting read-only GETs are never limited even well past the per-minute cap.
🤖 Generated with Claude Code