Skip to content

feat(ai): add xai-oauth SuperGrok device-code login - #1639

Closed
GratefulDave wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
GratefulDave:feat/xai-oauth-upstream
Closed

feat(ai): add xai-oauth SuperGrok device-code login#1639
GratefulDave wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
GratefulDave:feat/xai-oauth-upstream

Conversation

@GratefulDave

@GratefulDave GratefulDave commented Aug 22, 2026

Copy link
Copy Markdown

Summary

  • Add xai-oauth as a built-in provider for SuperGrok / X Premium+ device-code login (auth.x.ai).
  • Keep API-key xai unchanged. OAuth inference uses the OpenAI-compatible https://api.x.ai/v1 endpoint with X-XAI-Token-Auth: xai-grok-cli.
  • Clone the live xAI catalog onto xai-oauth (default model grok-4.6).
  • Flatten exclusive-required MCP object-root anyOf fragments before send; leftover object-root unions quarantine that one tool instead of 400ing the turn.

/login shows "xAI Grok OAuth". Optional env: XAI_OAUTH_TOKEN (auth.json key: xai-oauth).

Validation

  • packages/ai: test/xai-oauth.test.ts, test/openai-completions-xai-root-union.test.ts (25 passed)
  • npm run check passed on the v0.8.0 overlay branch before this cherry-pick

Notes

Note

Add xai-oauth SuperGrok device-code login and fix xAI tool schema handling

  • Adds a full xai-oauth OAuth provider in xai.ts implementing RFC 8628 device-code login against auth.x.ai, token refresh, endpoint validation restricted to https://*.x.ai, and modifyModels that pins SuperGrok models to XAI_API_BASE_URL with XAI_OAUTH_API_HEADERS
  • Registers xaiOAuthProvider in index.ts via BUILT_IN_OAUTH_PROVIDERS, adds 'xai-oauth' to KnownProvider in types.ts, maps it to XAI_OAUTH_TOKEN in env-api-keys.ts, and sets default model grok-4.6 in model-resolver.ts
  • Mirrors all xAI models into a xai-oauth namespace in models.generated.ts via generate-models.ts, adding grok-4.6 and header {"X-XAI-Token-Auth":"xai-grok-cli"}
  • Fixes xAI 400 errors in openai-completions.ts by passing provider into convertTools, dropping tools whose object-root anyOf/oneOf schemas xAI rejects (via xai-tool-schema.ts), and removing tool_choice when it references a dropped or nonexistent tool
  • Behavioral Change: shouldDropToolChoice now deletes params.tool_choice when tools are empty with tool_choice set to 'none'/'required'/object, or when a tool_choice object references a function absent from params.tools; convertTools now omits individual tools with unfixable root unions for xai and xai-oauth providers instead of sending the full set and failing the request

Macroscope summarized 5778cad.

Add a separate xai-oauth provider for SuperGrok / X Premium+ device-code auth against api.x.ai, clone the xAI catalog onto that provider, and flatten exclusive-required MCP object-root unions so xAI does not 400 the whole turn.
@github-actions

Copy link
Copy Markdown

Hi @GratefulDave, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/PrimeIntellect-ai/prime-agent/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Aug 22, 2026
@GratefulDave

Copy link
Copy Markdown
Author

Opened a Feature Request so this can go through the documented intake: #1640

Branch remains at GratefulDave:feat/xai-oauth-upstream if a maintainer wants to invite the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants