feat(ai): add xAI subscription OAuth - #754
Conversation
|
Independent reproduction of the core mechanism, for reviewer confidence (2026-08-07, different machine/account, SuperGrok Heavy, Two observations from that testing, posted in more detail on #678:
One suggestion regardless of shape: whatever error surfaces when the stored token is expired/revoked, make it actionable (name the provider and the fix) rather than a raw HTTP 401 — subscription users will hit it on a schedule, unlike API-key users. |
|
Thanks @ss251. I checked the current Fixed in
Verification:
|
Preserve the xAI OAuth changelog entries under Unreleased while incorporating v0.7.1 (closes PrimeIntellect-ai#678). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Description
Prime Agent exposes xAI only through
XAI_API_KEY, so users with a SuperGrok or X Premium subscription cannot authenticate from/loginwithout separate API billing.This adds xAI as a built-in OAuth provider using the RFC 8628 device-code flow already accepted upstream in earendil-works/pi#6651, including the prefilled verification URL behavior from earendil-works/pi#6734. The port targets Prime Agent's existing
utils/oauthregistry rather than copying Pi's newer provider architecture.The flow validates browser-bound URLs as HTTPS, waits for the server polling interval, handles
authorization_pending,slow_down, denial, expiry, and cancellation, preserves unrotated refresh tokens, and refreshes before token expiry. Grok 4.5 becomes the xAI default and is routed through/responseswith the supported low/medium/high reasoning levels and encrypted reasoning continuity. Other xAI models retain their existing transport, andXAI_API_KEYremains available alongside subscription login.Closes #678.
Steps to Reproduce Bug and Validate Solution
Reproduce
XAI_API_KEY./login.Validate
/loginand selectxAI (Grok/X subscription).xaiauth key and can refresh automatically.https://api.x.ai/v1/responses.PR Checklist
Does This Introduce a Breaking Change?
Testing
cd packages/ai && npx tsx ../../node_modules/vitest/dist/cli.js --run test/xai-oauth.test.ts test/xai-responses.test.tscd packages/coding-agent && npx tsx ../../node_modules/vitest/dist/cli.js --run test/model-resolver.test.ts test/oauth-selector.test.tsnpm run checkPOST https://api.x.ai/v1/responseswith Grok 4.5, includingreasoning.summary: "auto"and encrypted reasoning content; no token material was logged.Other Information or Known Dependencies
This is intentionally scoped to authentication and avoids the unrelated Ollama Cloud and generated model-catalog changes currently combined in #652. It uses xAI's public Grok CLI OAuth client contract, matching the implementation accepted by Pi upstream.
Note
Medium Risk
Touches authentication and default model/API routing for xAI; OAuth and token refresh are security-sensitive but well-tested and scoped.
Overview
Adds SuperGrok / X Premium sign-in via RFC 8628 device-code OAuth (
loginXai, registry entry, token refresh, cancellation, HTTPS-only verification URLs, and RFC-correctslow_downpolling).XAI_API_KEYAPI billing remains; stored OAuth credentials take precedence after/login.Grok 4.5 is now the default xAI model and uses the OpenAI Responses API (
/responses) with low/medium/high reasoning andreasoning.encrypted_contenton xAI requests; other Grok models stay on completions.Docs, changelogs, coding-agent provider docs, and tests cover OAuth, model routing, and login selector behavior.
Reviewed by Cursor Bugbot for commit db04718. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add xAI subscription OAuth with device-code flow and route
grok-4.5via Responses APIxai.ts, registered as a built-in provider sogetOAuthProvider("xai")works out of the box.grok-4.5through the OpenAI Responses API (instead of Completions) withreasoning.encrypted_contentalways included and a thinking level map that suppresses explicit effort for off/minimal modes.XAI_API_KEY.grok-4.20-0309-reasoningtogrok-4.5.grok-4.5via the Responses API rather than the previous default via Completions.Macroscope summarized dfeb0a7.