Conversation
The docs chat on chat.codercops.com had no global budget, so its bill had no ceiling. Cap it at 5M tokens a day (about 2,000 answers) and lower the per-IP default from 2M to 250k tokens (about 100 answers), so one script can't use up the day for everyone.
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.
What
The docs chat at chat.codercops.com (
website/src/pages/api/chat.ts) now has a daily budget:globalPerDay: { tokens: 5_000_000 }. Before this it had none, so the OpenAI bill had no ceiling.perIpPerDay: { tokens: 250_000 }. The default per-IP budget is 2M tokens, which is 40% of the new daily cap, so two scripted IPs could close the chat for everyone.A docs answer in the eval recordings averages about 2,000 tokens in and 500 out. That makes the daily cap about 2,000 answers and the per-IP cap about 100. Past the daily cap, the widget shows "The assistant has reached its limit for today" until midnight UTC. The 200-reply-per-conversation default still applies.
No changeset: this only touches the website.
How I tested this
budgetsobject againstchatcopsCloudflareHandler's config type withtsc --strict.createBudgetGuardwith these budgets and 2,000-in/500-out answers: one IP is refused after 100 answers (budget_exceeded, scopeip), and the whole site after 2,000 (scopeglobal).A hotfix PR into
productioncarries the same change, so it goes live without releasing the 20 changesets waiting ondev.