Codex/UI redesign#55
Conversation
…redit-check Allow chats when free-plan credits remain by removing post-generation hard block
✅ Deploy Preview for tera-ai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c85779b506
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const tokenCost = Math.max(1, generationResult.usage.totalTokens || 0) | ||
|
|
||
| // Enforce token credit limit before returning content if request exceeded remaining balance | ||
| if (tokenCost > creditsRemaining) { | ||
| const cap = getPlanCreditCap(userProfile.subscriptionPlan) | ||
| const resetLabel = resetDate | ||
| ? new Date(resetDate).toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) | ||
| : 'in 30 days' | ||
| const errorMessage = `You've reached your monthly credit cap (${cap}). Upgrade your plan now, or wait until your credits reset on ${resetLabel}.` | ||
| return { | ||
| answer: errorMessage, | ||
| sessionId: sessionId, | ||
| chatId: chatId, | ||
| error: errorMessage | ||
| } | ||
| } | ||
|
|
||
| const currentSessionId = sessionId || crypto.randomUUID() |
There was a problem hiding this comment.
Block responses that exceed remaining credits
After this change, the only credit gate is creditsRemaining <= 0 before generation, so a user with a small positive balance can still receive a response whose tokenCost is much larger than their remaining monthly credits (e.g., 1 remaining credit, 400-token response). Because incrementUserCredits in lib/free-plan-credits.ts always records the full cost and does not reject overages, this effectively bypasses the monthly cap by one arbitrarily large request and can create unbounded spend versus the configured plan cap.
Useful? React with 👍 / 👎.
No description provided.