Skip to content

feat(xai): 为xAI渠道添加/v1/responses支持 - #2897

Merged
Calcium-Ion merged 6 commits into
QuantumNous:mainfrom
funkpopo:main
Feb 11, 2026
Merged

feat(xai): 为xAI渠道添加/v1/responses支持#2897
Calcium-Ion merged 6 commits into
QuantumNous:mainfrom
funkpopo:main

Conversation

@funkpopo

@funkpopo funkpopo commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

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

    • Expanded Xai channel support with additional endpoint types.
    • Refreshed available Grok models and added new image/video variants (e.g., grok-4-1-fast variants, grok-3-mini, grok-2-vision-1212, grok-imagine-*).
  • Bug Fixes / Behavior

    • Improved response and streaming handling for Xai responses.
    • Default upstream model is used when none is specified.
    • Removed the previous "medium" model suffix option.

@coderabbitai

coderabbitai Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds 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

Cohort / File(s) Summary
Endpoint Type Configuration
common/endpoint_type.go
Add ChannelTypeXai case to return OpenAI and OpenAIResponse endpoint types so xAI can route responses-mode traffic.
xAI Channel Adaptor
relay/channel/xai/adaptor.go
Removed "-medium" reasoning-suffix trimming (keeps "-high"/"-low"), default request.Model to info.UpstreamModelName in ConvertOpenAIResponsesRequest, and route RelayModeResponses to OaiResponsesHandler or OaiResponsesStreamHandler in DoResponse.
xAI Model List
relay/channel/xai/constants.go
Replaced legacy grok model entries with a refreshed, expanded set of grok variants (language, search, high/low, image/video models).
Stream Response Handler
relay/channel/xai/text.go
Replaced direct json.Unmarshal usage with common.UnmarshalJsonStr for streaming JSON parsing in xAI stream handler.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #1569: Adds responses-mode support and integrates ConvertOpenAIResponsesRequest with OaiResponsesHandler/OaiResponsesStreamHandler.
  • PR #1205: Adjusts RelayModeResponses handling and routing for channel adaptors (responses preview URL / flow changes).
  • PR #2889: Integrates Responses-specific request/response routing and handler selection similar to this change.

Suggested reviewers

  • seefs001
  • creamlike1024

"I'm a rabbit in the code-lush glade,
New grok models in my hopping parade.
Responses routed, old suffixes undone,
Streams parsed neat with a helper run.
I nibble bugs and celebrate the sun! 🐇✨"

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main objective: adding support for the /v1/responses endpoint to the xAI channel, which aligns with the primary changes across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 3 to 18
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",
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 include grok-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; only grok-imagine-image is 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.

Calcium-Ion
Calcium-Ion previously approved these changes Feb 8, 2026
@seefs001

Copy link
Copy Markdown
Collaborator

@funkpopo 为啥要移除思考预算后缀和 -search 的处理嘞

@funkpopo

funkpopo commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

@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 掉移除后缀处理的代码。

非常感谢您的提醒,我会立即更改,并在未来提交时更注意项目的向下兼容性。

@Calcium-Ion
Calcium-Ion merged commit 75e533e into QuantumNous:main Feb 11, 2026
1 check passed
hardingCheng pushed a commit to hardingCheng/new-api that referenced this pull request Feb 14, 2026
* 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
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
* feat(xai): 为xAI渠道添加/v1/responses支持

* Add video generation model to constants

* fix: 修正先前更改中对于grok-3-mini的思考预算和"-search"设计
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.

3 participants