feat(xai): 为xAI渠道添加/v1/responses支持 - #2897
Conversation
WalkthroughAdds xAI channel support for OpenAI "responses" relay mode, updates xAI model list, removes "-medium" reasoning-suffix handling, and replaces direct json.Unmarshal with a common JSON helper in streaming text handling. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Adaptor as xAI Adaptor
participant Handler as OAI Responses Handler
participant Upstream as Upstream API
Client->>Adaptor: Send /v1/responses request
Adaptor->>Adaptor: ConvertOpenAIResponsesRequest (default model from info if empty)
Adaptor->>Handler: Route to OaiResponsesHandler or OaiResponsesStreamHandler (based on IsStream)
Handler->>Upstream: Forward adapted request
Upstream-->>Handler: Streamed/Non-streamed response
Handler-->>Adaptor: Return formatted response stream or JSON
Adaptor-->>Client: Relay response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@relay/channel/xai/constants.go`:
- Around line 3-18: Update the ModelList slice in constants.go to match the
current xAI API: remove the deprecated "grok-4-0709" and the unavailable
"grok-imagine-image-pro", and add the missing models "grok-4", "grok-2-1212",
"grok-vision-beta", "grok-beta", and the video model "grok-imagine-video";
ensure the list keeps language models grouped together and image/video models
grouped together and that the variable ModelList is updated accordingly so
callers of ModelList use only supported model names.
| var ModelList = []string{ | ||
| // grok-4 | ||
| "grok-4", "grok-4-0709", "grok-4-0709-search", | ||
| // grok-3 | ||
| "grok-3-beta", "grok-3-mini-beta", | ||
| // grok-3 mini | ||
| "grok-3-fast-beta", "grok-3-mini-fast-beta", | ||
| // extend grok-3-mini reasoning | ||
| "grok-3-mini-beta-high", "grok-3-mini-beta-low", "grok-3-mini-beta-medium", | ||
| "grok-3-mini-fast-beta-high", "grok-3-mini-fast-beta-low", "grok-3-mini-fast-beta-medium", | ||
| // image model | ||
| "grok-2-image", | ||
| // legacy models | ||
| "grok-2", "grok-2-vision", | ||
| "grok-beta", "grok-vision-beta", | ||
| // language models | ||
| "grok-4-1-fast-reasoning", | ||
| "grok-4-1-fast-non-reasoning", | ||
| "grok-code-fast-1", | ||
| "grok-4-fast-reasoning", | ||
| "grok-4-fast-non-reasoning", | ||
| "grok-4-0709", | ||
| "grok-3-mini", | ||
| "grok-3", | ||
| "grok-2-vision-1212", | ||
| // image generation models | ||
| "grok-imagine-image-pro", | ||
| "grok-imagine-image", | ||
| "grok-2-image-1212", | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
xAI grok API supported models 2026
💡 Result:
As of February 2026, the xAI (Grok) API supports these model IDs (as shown in xAI’s API models/pricing UI and docs):
Language (text) models
grok-4-1-fast-reasoning[1]grok-4-1-fast-non-reasoning[1]grok-4-fast-reasoning[1]grok-4-fast-non-reasoning[1]grok-code-fast-1[1]grok-4[1]grok-3(aliases includegrok-3-latest,grok-3-beta,grok-3-fast,grok-3-fast-latest,grok-3-fast-beta) [2]grok-3-mini[1]grok-2-vision-1212[1]grok-2-1212[1]grok-vision-beta[1]grok-beta[1]
Image generation
grok-2-image-1212[1]grok-imagine-image[3]
Video generation
grok-imagine-video[4]
Source list: xAI API models/pricing page [1], xAI Grok-3 model doc (aliases) [2], xAI Image Generations guide [3], xAI Video Generations guide [4].
Remove unsupported models and update to match current xAI API.
Two models in this list are not currently supported by the xAI API and will cause request failures:
grok-4-0709(deprecated)grok-imagine-image-pro(not available; onlygrok-imagine-imageis supported)
Additionally, the following currently available models are missing:
- Language models:
grok-4,grok-2-1212,grok-vision-beta,grok-beta - Video generation:
grok-imagine-video
Update this list to reflect the current xAI API as of February 2026.
🤖 Prompt for AI Agents
In `@relay/channel/xai/constants.go` around lines 3 - 18, Update the ModelList
slice in constants.go to match the current xAI API: remove the deprecated
"grok-4-0709" and the unavailable "grok-imagine-image-pro", and add the missing
models "grok-4", "grok-2-1212", "grok-vision-beta", "grok-beta", and the video
model "grok-imagine-video"; ensure the list keeps language models grouped
together and image/video models grouped together and that the variable ModelList
is updated accordingly so callers of ModelList use only supported model names.
|
@funkpopo 为啥要移除思考预算后缀和 -search 的处理嘞 |
修改时主要参考的 grok 4 / grok 4.1 ,忽略了还有个使用到思考预算参数的 grok-3-mini ,很抱歉,我想我应该回退,让 grok-3-mini 支持使用 reasoning_effort: low / high 参考x.AI文档说明关于搜索需要转向参数控制 searchParameters: {mode: "on"} ,是我考虑不周。我单方面以为应该由客户端通过标准的 Tool Use 或参数来控制,但忽略了各类不支持自定义参数的客户端,为了保持向下兼容性,我会 revert 掉移除后缀处理的代码。 非常感谢您的提醒,我会立即更改,并在未来提交时更注意项目的向下兼容性。 |
* main: (21 commits) fix: normalize search pagination params to avoid [object Object] fix: ignore header passthrough during channel tests fix(token-search): use TrimPrefix for sk- token normalization fix: rename bulk test action to skip manually disabled channels fix: support numeric status code mapping in ResetStatusCode 优化: 任务日志查询速度并显示用户详情 (QuantumNous#2905) Merge pull request QuantumNous#2916 from worryzyy/feature/add-quota-amount-input feat: Improve backend multilingual support feat: add OpenRouter pricing support to upstream ratio sync feat: refactor request body handling to use BodyStorage for improved efficiency feat(xai): 为xAI渠道添加/v1/responses支持 (QuantumNous#2897) chore: remove deprecated Docker badge from README feat: refactor extra_body handling for improved configuration parsing Update README feat: logs cache field (QuantumNous#2920) feat(localization): added zh_TW (QuantumNous#2913) fix: update README files to improve link formatting and readability feat: add Aion UI link to README files chore(deps): bump axios from 1.12.0 to 1.13.5 in /web simplify language selector display to use text-only labels ... # Conflicts: # web/src/components/layout/headerbar/LanguageSelector.jsx
* feat(xai): 为xAI渠道添加/v1/responses支持 * Add video generation model to constants * fix: 修正先前更改中对于grok-3-mini的思考预算和"-search"设计
xAI官方文档提出可使用/v1/responses接口。
但本PR之前的实现仅兼容/v1/chat/completions接口。
参考 https://docs.x.ai/developers/quickstart#step-3-make-your-first-request ,实现了对于官方x.AI渠道的/v1/responses格式兼容
Summary by CodeRabbit
New Features
Bug Fixes / Behavior