feat: admin Swagger separation + per-user rate limit multiplier — MAIN#224
Merged
Conversation
feat: separate admin endpoints into dedicated Swagger page
feat: separate admin endpoints into dedicated Swagger page - TEST
feat: per-user rate limit multiplier with admin endpoints
eat: per-user rate limit multiplier with admin endpoints - TEST
nomadicrogue
approved these changes
Mar 10, 2026
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.
TL;DR
Two features shipping to production: (1) Admin billing endpoints are now isolated onto a dedicated Swagger page at
/admin/docs, removing them from the public API surface; (2) a new per-user rate-limit multiplier lets admins scale RPM/TPM limits up or down for individual users without redeploying.What Changed
1. Dedicated Admin Swagger Page (
/admin/docs)src/api/v1/billing/admin.py— all admin-protected billing endpoints (staking/settings,staking/refresh,credits/adjust,balance/reconcile, and the new rate-limit multiplier endpoints) have been extracted out of the public billing router into a standalone admin router./docsno longer exposes any admin-tagged endpoints. The OpenAPI schema is split at build time: public routes serve from/api/v1/openapi.json, admin routes serve from/admin/api/v1/openapi.json._build_swagger_html()helper to eliminate duplication and strip noisyconsole.logdebug statements from the OAuth2 flow./api-docslanding page.2. Per-User Rate Limit Multiplier
add_rate_limit_multiplier_to_usersadds arate_limit_multiplier FLOAT NOT NULL DEFAULT 1.0column to theuserstable.User.rate_limit_multiplieris now persisted, included in the Redis user cache, and deserialized correctly in all auth dependency paths (get_current_user,get_api_key_auth,_build_auth_from_cache,_build_auth_from_db).check_rate_limit()accepts amultiplierparameter. Limits are scaled at check time —2.0doubles RPM/TPM,0.5halves them, with a floor of 1 to prevent zero-limit lockout.POST /billing/rate-limit/multiplier(set) andGET /billing/rate-limit/multiplier/{cognito_user_id}(get), both behindX-Admin-Secret.RateLimitMultiplierRequest/RateLimitMultiplierResponseadded tosrc/schemas/billing.py.3. Cleanup
billing/index.py(moved, not deleted).secrets,Header,staking_service,user_crud, etc.) from the public billing module.Files Changed (11)
alembic/versions/2026_03_10_0001_add_rate_limit_multiplier_to_users.pysrc/api/v1/__init__.pybilling_adminroutersrc/api/v1/billing/admin.pysrc/api/v1/billing/index.pyadmin.py)src/api/v1/chat/index.pysrc/api/v1/embeddings/index.pysrc/db/models/user.pyrate_limit_multipliercolumnsrc/dependencies.pyrate_limit_multiplierin cache + deserializationsrc/main.py/admin/docs, refactor Swagger HTMLsrc/schemas/billing.pysrc/services/rate_limiting/rate_limit_service.pyRisk Assessment
1.0(no behavioral change for existing users).ADD COLUMN ... DEFAULT 1.0) — no data loss path.Test Plan
/docsno longer shows admin-tagged endpoints/admin/docsrenders and shows only admin endpointsPOST /billing/rate-limit/multipliersets value and invalidates cacheMade with Cursor