Skip to content

feat(ai-backend): add per-user AI quotas and provider usage budgets#453

Open
Nicks-19 wants to merge 2 commits into
MRIARC-08:mainfrom
Nicks-19:feat/ai-quotas-372
Open

feat(ai-backend): add per-user AI quotas and provider usage budgets#453
Nicks-19 wants to merge 2 commits into
MRIARC-08:mainfrom
Nicks-19:feat/ai-quotas-372

Conversation

@Nicks-19

@Nicks-19 Nicks-19 commented Jul 6, 2026

Copy link
Copy Markdown

Description

Addresses #372 by introducing a robust per-user AI quota management and usage budgeting system for the Python AI service.

Key Changes

  • Database Schema: Added UserQuotaPolicy, UserQuotaAssignment, UserUsageTracker, and AiJobReservation tables to track request/token usage and concurrency slots. Added Alembic migration 002 with default seeds.
  • Quota Manager: Implemented QuotaManager in quota.py utilizing database locks to prevent race conditions and concurrent requests from bypassing limits.
  • FastAPI Dependencies: Added header-based user context resolution (X-User-Id & X-User-Is-BYOK) and a quota enforcement dependency.
  • BYOK Support: Bypasses token limits for BYOK requests while still enforcing request-rate and concurrency controls.
  • Reservation & Reconciliation: Implemented token reservation for long-running jobs and reconciliation adjusting actual usage on completion, failure, or cancellation.
  • Unit/Integration Tests: Added a complete test suite covering boundaries, concurrency, and reset behaviors. All tests pass successfully.

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

@Nicks-19 is attempting to deploy a commit to the Adarsh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@MRIARC-08 MRIARC-08 added gssoc gssoc gssoc:approved GSSoC approved PR labels Jul 12, 2026
@MRIARC-08

Copy link
Copy Markdown
Owner

Hey! Thanks for the PR. It looks like there are some merge conflicts. Could you please resolve them so we can proceed with the merge?

@MRIARC-08 MRIARC-08 added type:feature Feature contribution level:advanced GSSoC difficulty: advanced area:ai-backend Python AI service, embeddings, retrieval, and LLM infrastructure and removed gssoc:approved GSSoC approved PR labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai-backend Python AI service, embeddings, retrieval, and LLM infrastructure gssoc gssoc level:advanced GSSoC difficulty: advanced type:feature Feature contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants