Repository navigation
Guest quotas, AI budget before every AI call, blocked features (2/3) - #15
Merged
Merged
Conversation
Guests get a "guest" quota plan: 10,000 rows all-time (runs refused for size do not count), 5,000 rows per run checked in suggest-transforms before templates or AI, 3 uploads per guest and 10 per IP hash per 24 h via one capped INSERT that also refuses an expired session, and 5 pipelines. checkAiBudget(teamId, calls) replaces the pass-1-only spend check and runs before every Bedrock call: suggest-transforms on every pass and the 3-call auto-validate committee (which falls back to manual review when over budget). Users keep the monthly hard cap; guests get 10 calls/h, $0.25 each and $5/UTC day for all guests together, counted from bedrock_usage (new created_at index in 003). meterBedrockCall is now awaited so the next check sees the call. Rejected: Upstash counters (they fail open).
Guests cannot use chat-builder/generate-data, auto-clean, training export, Slack alerts, account deletion, templates or /api/admin: the middleware answers 403 for the API (redirects /templates to the dashboard) and each route also refuses guest ids, so a matcher mistake cannot expose them. A signed-in user with a stale guest cookie is unaffected. chat-builder and generate-data were neither metered nor capped. They now check the monthly AI cap first and record usage (streamText onFinish).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Oct 2, 2026
This branch was successfully deployed
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.
Stack: 2 of 3. This PR's base is
feature/guest-identity(#14). Merge #14 first, then retarget this PR tomain. #16 (guest demo) is stacked on this one.What
src/lib/guest-quota.ts,src/lib/billing.ts):suggest-transformsbefore templates or AI.INSERT. The same insert also refuses an expired session.checkAiBudget(teamId, calls)(src/lib/bedrock-meter.ts) runs before every Bedrock call:suggest-transformson every pass. This replaces the old pass-1-only spend check.team_id LIKE 'guest\_%', with a newbedrock_usage(created_at)index in 003).meterBedrockCallis now awaited, so the next check sees the call./templatespage) and/api/admin. The middleware answers 403 for API requests and redirects pages; each route also callsforbidGuest.streamTextonFinishmetering. generate-data is capped and metered the same way.Look hardest at
INSERT ... SELECTstatements.checkAiBudget's single query.Verified (locally)
tsc, lint (0 errors), vitest: 221 passed.guest-limits.test.tscovers:/templates, gets 403 on 6 blocked APIs, and gets 429 on the 4th upload.Caveat
Usage is recorded after a call, so concurrent requests can overshoot a cap by the cost of the calls in flight. This is documented in the README.