Repository navigation
feat(providers): add weekly quota tracking for grok-web - #8127
Merged
diegosouzapw merged 3 commits intoJul 23, 2026
Merged
diegosouzapw merged 3 commits into
diegosouzapw merged 3 commits into
Conversation
Implements a bespoke QuotaFetcher for the grok-web provider that: - Reads OIDC tokens from ~/.grok/auth.json (local Grok CLI login) - Refreshes tokens via auth.x.ai OIDC if expired - Calls https://cli-chat-proxy.grok.com/v1/billing?format=credits - Returns a single 'weekly' window with creditUsagePercent and resetAt - Caches results with 60s TTL (matching codexQuotaFetcher pattern) - Supports GROK_AUTH_PATH env var override for testing - Registers in chat.ts before registerGenericQuotaFetchers Tests cover: missing auth, successful fetch with header verification, 401-triggered token refresh with retry, 60s cache TTL, and preflight integration. Closes cheaper-inference#6444
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Collaborator
|
Thanks, @apoapostolov! 🙏 Merged — weekly quota tracking for grok-web SSO. Rebased onto the current release tip, rebaselined chat.ts (own-growth). grok-quota-fetcher tests green. |
diegosouzapw
merged commit Jul 23, 2026
f3ed4a4
into
cheaper-inference:release/v3.8.49
2 of 5 checks passed
Merged
HouMinXi
pushed a commit
to HouMinXi/OmniRoute
that referenced
this pull request
Aug 2, 2026
…rence#8127) * feat(providers): add weekly quota fetcher for grok-web (grok.com SSO) Implements a bespoke QuotaFetcher for the grok-web provider that: - Reads OIDC tokens from ~/.grok/auth.json (local Grok CLI login) - Refreshes tokens via auth.x.ai OIDC if expired - Calls https://cli-chat-proxy.grok.com/v1/billing?format=credits - Returns a single 'weekly' window with creditUsagePercent and resetAt - Caches results with 60s TTL (matching codexQuotaFetcher pattern) - Supports GROK_AUTH_PATH env var override for testing - Registers in chat.ts before registerGenericQuotaFetchers Tests cover: missing auth, successful fetch with header verification, 401-triggered token refresh with retry, 60s cache TTL, and preflight integration. Closes cheaper-inference#6444 * chore(quality): rebaseline chat.ts for cheaper-inference#8127 own-growth --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…rence#8127) * feat(providers): add weekly quota fetcher for grok-web (grok.com SSO) Implements a bespoke QuotaFetcher for the grok-web provider that: - Reads OIDC tokens from ~/.grok/auth.json (local Grok CLI login) - Refreshes tokens via auth.x.ai OIDC if expired - Calls https://cli-chat-proxy.grok.com/v1/billing?format=credits - Returns a single 'weekly' window with creditUsagePercent and resetAt - Caches results with 60s TTL (matching codexQuotaFetcher pattern) - Supports GROK_AUTH_PATH env var override for testing - Registers in chat.ts before registerGenericQuotaFetchers Tests cover: missing auth, successful fetch with header verification, 401-triggered token refresh with retry, 60s cache TTL, and preflight integration. Closes cheaper-inference#6444 * chore(quality): rebaseline chat.ts for cheaper-inference#8127 own-growth --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
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.
Summary
Adds a bespoke
QuotaFetcherfor the grok-web provider (grok.com SSO/cookie connections). Surfaces the weekly credit-usage percentage from xAI billing in Health → Limits & Quotas, and enables quota-aware preflight switching between grok-web connections.Closes #6444.
Implementation
New file:
open-sse/services/grokQuotaFetcher.tsUses the same billing API already proven in production by pi-grok-usage and hermes-grok-usage:
Endpoint:
GET https://cli-chat-proxy.grok.com/v1/billing?format=creditsAuth: OIDC tokens from
~/.grok/auth.json(local Grok CLI login fromgrok login), with automatic refresh viaauth.x.ai/.well-known/openid-configuration→ token endpoint.Response mapped to
QuotaInfo:weeklywindow withpercentUsed = creditUsagePercent / 100resetAtfromcurrentPeriod.end(ISO timestamp)UsageSnapshot(not exposed in preflight but parseable)Key design decisions:
GROK_AUTH_PATHenv var override for testingnullwithout blocking requests when no local auth existsModified:
src/sse/handlers/chat.tsImports
registerGrokWebQuotaFetcherand calls it beforeregisterGenericQuotaFetchers()so the bespoke fetcher takes precedence over the generic path (which can't resolve grok OIDC auth from cookie-based connections).New test file:
tests/unit/grok-quota-fetcher.test.ts5 tests covering:
registerGrokWebQuotaFetcher()Future Work
xai-oauthprovider): Once that provider exists, it can reuse the same billing endpoint with its own OIDC token path. ThegetGrokBilling()core logic is separated from the auth resolution so it can be imported by a futuregrok-clifetcher.grokTlsClient.tscookies can be exchanged for an OIDC token that hits the same billing endpoint, the fetcher can be extended to extract tokens from the cookie connection itself (no CLI dependency). Currently the dependency on~/.grok/auth.jsonis documented in the file header.