feat(xai): Grok Build OAuth (loopback PKCE) + pool-scoped models#574
Open
Yanzzp999 wants to merge 1 commit into
Open
feat(xai): Grok Build OAuth (loopback PKCE) + pool-scoped models#574Yanzzp999 wants to merge 1 commit into
Yanzzp999 wants to merge 1 commit into
Conversation
Implement grok-cli OAuth against auth.x.ai using the registered loopback redirect (127.0.0.1:56121/callback), PKCE, token refresh, and admin UI for browser login plus manual callback paste. xAI accounts live in pool "xai", separate from grok.com SSO pools. Expose only grok-build-0.1 and grok-composer-2.5-fast for OAuth chat; route Build via api.x.ai chat/completions and Composer via /responses with Chat Completions translation. Filter WebUI and /v1/models by available pools so xAI-only installs see two models while SSO accounts keep the full grok catalog. Hide OAuth pending rows in the admin token list.
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.
为 grok2api 增加 Grok Build / grok-cli OAuth(auth.x.ai)能力,与现有 grok.com SSO(basic / super / heavy)账号池分离。
OAuth 与账号
• 使用 xAI 注册的 loopback 回调:http://127.0.0.1:56121/callback,完整 PKCE(S256)流程。
• 管理后台支持浏览器登录、轮询完成、以及手动粘贴 callback URL / code。
• 账号写入 pool=xai,不参与 grok 选号、配额刷新与 runtime 热路径;登录成功后清理 _xai_oauth_pending 占位行,并在 token 列表中隐藏 pending 记录。
模型与上游
• OAuth 仅开放:grok-build-0.1、grok-composer-2.5-fast(已移除别名 grok-build)。
• grok-build-0.1 → https://api.x.ai/v1/chat/completions
• grok-composer-2.5-fast → https://api.x.ai/v1/responses,并在网关侧转换为 OpenAI Chat Completions 格式(含流式 SSE)。
列表过滤
• GET /v1/models 与 WebUI GET /webui/api/models 按当前可用账号池过滤:仅 xai 池时只显示上述 2 个模型;存在 SSO 池时仍显示完整 Grok 目录(Grok 4.20、Imagine 等)。
其它
• ModelSpec 增加 provider(grok | xai),OpenAI /v1/chat/completions 与 WebUI 聊天按 provider 分发。
• 新增 [xai] 配置段(config.defaults.toml)。
Testing
• [x] uv run python tests/test_xai_oauth.py — 16/16 通过(PKCE、authorize URL、callback 解析、模型白名单、Responses 转换等)
• [x] uv run python -m compileall 相关新增模块 — 无语法错误
• [x] 本地 granian + 仅 pool=xai 账号:
• GET /v1/models → 仅 grok-build-0.1、grok-composer-2.5-fast
• POST /v1/chat/completions(grok-build-0.1)→ 200,有正常回复
• POST /v1/chat/completions(grok-composer-2.5-fast)→ 200(经 /responses 转换)
• Composer 流式 SSE 可输出标准 data: {...} chunk(非 b'...' 字节串)
• [x] WebUI 模型下拉:仅 xAI OAuth 时只显示 2 个模型;有 SSO 池时仍显示完整列表
• [x] 密钥检查:data/、logs/、.env 未提交;源码无用户 token / JWT 硬编码(仅公共 grok-cli client_id)