feat(ai): SuperGrok usage tracking via billing API#4874
Conversation
|
Review fallback: GitHub rejected the batched inline review after staged comments included stale line positions, and the review staging buffer is not clearable from this read-only session. Concrete findings:
Rank applied: Verification: |
dd827a3 to
b5213ea
Compare
|
Thanks for this — this is the right fix for #5065 on the core Quick scope note so we don’t double-track:
So: don’t treat this as “Grok Build chat is done” — this is quota visibility for SuperGrok OAuth. That’s still very useful and should land. If useful as a tiny follow-up after merge: allow the same billing Prototype extension for the Build chat path (not competing with this usage PR): https://github.com/ART1KZ/omp-grok-build |
40eabd5 to
b92246b
Compare
|
any updates on this one ? :) |
@IntegralMedia01 I don't think this would make sense anymore, since the xAI provider on OMP draws from API usage instead of the subscription quota and there are no plans for supporting this. @metaphorics mentioned he would implement Grok Build provider as an extension. I have the full chain of requests from grok-cli captured locally though, so I may publish this as a plugin for full parity once I have some spare time... PS: oh, here it is, https://github.com/metaphorics/oh-my-pi-plugin-grok-build, I'm gonna check it out as well. However, as of now there's no clean way of adding new usage providers via extensions, so I may open a PR here to address this. And then, also open a PR for @metaphorics plugin adding the usage provider. |
|
Live verification of this PR against a real SuperGrok OAuth account — I hit every symptom from #5065 (xai-oauth invisible in Environment: macOS arm64, branch built from source (
CI: the two red checks look unrelated to this change — This fixes #5065 and I'd love to see it land. If it helps, I'm happy to shepherd: rebase onto current main, address review leftovers, or carry a successor PR with you as co-author — whichever you prefer, @any-victor. |
b92246b to
3c83f7e
Compare
|
@bnivanov rebased! |
|
Thank you!! Kimi K3 did a good job lol, I am glad we are making progress on this as I am intending to push grok to its limits ha. Appreciate the help @any-victor! |
dab28d1 to
ace9b80
Compare
Reject bearer-token redirects so OAuth credentials cannot reach an unvalidated host.
Keep optional identity enrichment bounded and let the dedicated bearer fall back past incompatible stored keys.
Rebase onto 16.4.0 landed the entry under the released section; keep release intent under Unreleased until the next cut.
Document why xai-oauth usage skips generic api_key env fallbacks, pin billing URLs to https grok.com hosts, and keep weekly windows visible across period rollover so /usage does not go blank mid-refresh.
Move the changelog entry back under Unreleased after the 16.4.1 cut, and send X-XAI-Token-Auth: xai-grok-cli on CLI billing so usage polls match the official Grok CLI host fingerprint.
Prior run failed streamPiNative + codex SSE timeout under parallel load; all SuperGrok usage tests passed. Empty commit to re-run checks.
Rebase onto 16.4.2 landed the entry under the released section; keep release intent under Unreleased until the next cut.
Rebase onto current main left the entry under the already-released 16.4.3 section; keep release intent under Unreleased until the next cut.
b6ced5f to
1dd1ec6
Compare
|
@roboomp Addressed in the current head. The SuperGrok usage provider is OAuth-only: |
can1357#4874 only parsed weekly ?format=credits (creditUsagePercent). Unified accounts often omit those fields or mark isUnifiedBillingUser while the default /v1/billing payload still exposes monthlyLimit/used, so omp usage reported "no usage data". Fall back to and merge the monthly shape.
#4874 only parsed weekly ?format=credits (creditUsagePercent). Unified accounts often omit those fields or mark isUnifiedBillingUser while the default /v1/billing payload still exposes monthlyLimit/used, so omp usage reported "no usage data". Fall back to and merge the monthly shape.
Summary
xai-oauthUsageProviderthat polls SuperGrok subscription usage fromGET https://cli-chat-proxy.grok.com/v1/billing?format=credits.XAI_OAUTH_TOKENonly when no usable stored OAuth credential exists. SharedXAI_API_KEYcredentials are never sent to the SuperGrok billing host (supports()is OAuth-only;AuthStorageskips api_key material for this provider).Authorization: Bearer …plus the official CLI gate headerX-XAI-Token-Auth: xai-grok-cli(same host fingerprint as Grok Build CLI traffic).GrokBuild,Api, and any other product that reports a percent) plus a positive on-demand cap; product rows withoutusagePercent(e.g. liveGrokChat) are skipped. Enriches usage metadata from OIDC userinfo when an older credential lacks an email.*.grok.com(separate from OIDC*.x.aihost validation)./usagedoes not blank across rollover.Fixes #5065
Not in this PR
metadata.planType/ JWTtierdisplay (billing has no plan string; optional follow-up).GrokBuild% under/usagedoes not mean inference is on the Build path. Official CLI chat usescli-chat-proxy.grok.com/v1/responseswith full CLI fingerprint headers; OMPxai-oauthstill chats onapi.x.ai. That belongs in a separate provider/routing PR (discussion Vouch request + design: native Grok Build CLI provider (Build quota path, #4945) #5092 / ART1KZ prototype), not here.Test plan
bun test packages/ai/test/xai-oauth-usage.test.ts packages/ai/test/auth-storage-xai-oauth-usage.test.ts packages/ai/src/registry/oauth/__tests__/xai-oauth.test.tsmain(17.0.5)omp usage --provider xai-oauth --jsonreport shape