Skip to content

fix API user quota logic flaw#56

Open
Sudhanshu-NITR wants to merge 1 commit intosugarlabs:mainfrom
Sudhanshu-NITR:fix-quota-logic
Open

fix API user quota logic flaw#56
Sudhanshu-NITR wants to merge 1 commit intosugarlabs:mainfrom
Sudhanshu-NITR:fix-quota-logic

Conversation

@Sudhanshu-NITR
Copy link

Summary

Prior to this fix, the application bypassed quota incrementation for brand new API key requests. When a new API key was used, it returned True immediately without falling through to the proper count increment logic. This essentially gave new users an extra uncounted API request on their first use.
This fix removes the early return for new keys, initializes the quota tracking dictionary properly, and allows the execution to smoothly fall through to the proper increment logic at the bottom of the function.

Screenshots

image As seen in the screenshot, before this fix the UI shows "100/100" remaining quota even after the user successfully received a RAG response to their first prompt, clearly demonstrating the bypassed increment.

After Fixing

image It can be seen from the screenshot that now the quota is updated for the first api request as well

Prior to this fix, the application bypassed quota incrementation
for brand new API key requests. This assigns the dictionary and
allows it to fall through to the proper count increment logic.
Copilot AI review requested due to automatic review settings March 3, 2026 18:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an API quota accounting bug where a brand-new API key’s first request was not being counted, causing the UI and quota enforcement to show an incorrect remaining quota after the first successful request.

Changes:

  • Removed the early return in check_quota() for new API keys so first use properly increments the request count.
  • Ensured newly seen API keys initialize quota tracking and then fall through to the shared increment/limit logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants