feat(ai): add xAI Grok subscription OAuth provider - #880
Open
teddytennant wants to merge 2 commits into
Open
Conversation
Adds an `xai-oauth` provider so SuperGrok and X Premium subscribers can sign in with /login instead of supplying a metered XAI_API_KEY. Login is authorization code + PKCE against the xAI OIDC issuer with a loopback callback on 127.0.0.1:56121, matching the flow xAI's own CLI uses. Endpoints come from OIDC discovery and are pinned to the x.ai origin so a tampered discovery document cannot redirect the token exchange. The token endpoint is stored with the credentials so refresh needs no discovery round trip. Models mirror the existing metered xAI catalog under the new provider, served over the Responses API. The metered `xai` provider is unchanged.
|
This is gold! I was already doing this PR. |
Resolve coding-agent changelog conflict by keeping both the xai-oauth login entry and the agent_message IPython cell UI change.
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 an
xai-oauthOAuth provider so SuperGrok and X Premium subscribers can sign in through/loginand use Grok models against their subscription, rather than a meteredXAI_API_KEY. xAI ships first-class OAuth for coding agents; this wires that flow into the existing provider registry.The metered
xaiprovider is untouched.Flow
Authorization code + PKCE against the xAI OIDC issuer (
https://auth.x.ai), with a loopback callback on127.0.0.1:56121— the redirect URI xAI's own CLI clients use. This is the same shape as the existing Anthropic and Codex providers, so the login dialog's browser-or-paste UX works unchanged (usesCallbackServer: true).x.aiorigin, so a tampered discovery document cannot redirect the token exchange elsewhere.refresh_tokenkeep the existing one.Models
generate-models.tsmirrors the metered xAI catalog intoxai-oauth, served over the Responses API (grok-build-0.1,grok-4.5,grok-4.3,grok-4.20-*,grok-code-fast-1). Deriving the list rather than hardcoding it means the two catalogs stay in sync on the next regeneration.grok-build-0.1is the provider default.Test plan
packages/ai/test/xai-oauth.test.tscovers registry registration, the PKCE code exchange with the loopbackredirect_uri, state-mismatch rejection on a pasted redirect URL, refusal of non-x.ai discovery endpoints, refresh against the stored token endpoint, and OAuth error propagation.npm run checkclean; existing OAuth, model-registry, and model-resolver suites pass.Notes
Device-code login would additionally cover headless and remote sessions without a pasteable redirect. Left out here to keep this to one flow; happy to add it in a follow-up if you want it.
Note
Add xAI Grok OAuth provider to support SuperGrok and X Premium subscriptions
xai-oauthprovider that authenticates via OAuth authorization code + PKCE flow against xAI, so users with SuperGrok or X Premium subscriptions can use Grok models without anXAI_API_KEY.x.ai, a loopback callback server for automatic code capture, PKCE exchange, and token refresh.xai-oauthmodel entries in models.generated.ts by cloning the existingxaicatalog with theopenai-responsesAPI.XAI_OAUTH_TOKENenv var to thexai-oauthprovider and setsgrok-build-0.1as its default model.Macroscope summarized 7afad24.