Repository navigation
feat(xai): add grok-imagine-video task plugin - #1
Conversation
xAI channel type 48 advertised grok-imagine-video but had no video task adaptor, so POST /v1/videos failed with invalid_api_platform: 48. Add a built-in plugin that maps OpenAI video requests onto the xAI / grok2api generations API, including grok-imagine-video-1.5.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32173938e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| version: "1.0.0", | ||
| author: { name: "datehoer" }, | ||
| channelTypes: [48], | ||
| models: ["grok-imagine-video", "grok-imagine-video-1.5"], |
There was a problem hiding this comment.
Add default billing expressions for the video models
On a fresh installation without an administrator pricing override, both newly routable models fail before reaching xAI: neither model has a built-in billing expression or legacy ratio, so ModelPriceHelperPerCall returns model_price_error when AcceptUnsetRatioModel is false. Add self-contained expressions for both video models while preserving explicit administrator overrides.
AGENTS.md reference: AGENTS.md:L110-L110
Useful? React with 👍 / 👎.
| if IsVideoGenerationModel(modelName) { | ||
| endpointTypes = append([]constant.EndpointType{constant.EndpointTypeOpenAIVideo}, endpointTypes...) |
There was a problem hiding this comment.
Restrict video endpoint advertising to XAI channels
When an administrator configures a non-XAI channel with a model name containing grok-imagine-video, this unconditional model-name check advertises openai-video for that ability. Requests cannot use that advertised endpoint because the only matching plugin declares channelTypes: [48], and channel selection rejects every other type through the task-plugin identity filter. Gate this endpoint addition on an XAI-compatible channel type.
Useful? React with 👍 / 👎.
| let aspect = trimmed(req.aspect_ratio || metadata.aspect_ratio).toLowerCase(); | ||
| let resolution = trimmed(req.resolution || metadata.resolution).toLowerCase(); |
There was a problem hiding this comment.
Preserve native fields on the legacy video route
For requests sent through the supported legacy POST /v1/video/generations route, these top-level native fields never reach the plugin: that route is intentionally not claimed by openai_video and its generic validation unmarshals into relay/common.TaskSubmitReq, which has neither aspect_ratio nor resolution. Consequently, a request such as grok-imagine-video-1.5 with resolution: "1080p" silently becomes the 720p default here. Preserve the native fields in the legacy request DTO or normalize them before invoking the plugin.
Useful? React with 👍 / 👎.
| @@ -0,0 +1,195 @@ | |||
| package plugins_test | |||
There was a problem hiding this comment.
Consolidate the XAI regression tests
This focused feature creates three separate test files—common/endpoint_type_xai_video_test.go, this file, and relay/xai_task_plugin_test.go—in addition to extending an existing plugin test. Consolidate the regression cases into at most one new suitable test file as required by the backend test convention.
AGENTS.md reference: AGENTS.md:L126-L126
Useful? React with 👍 / 👎.
Agent
Links
datehoer/new-api 已关闭 Issues,无法在本仓库新建 Issue。上游已有同类 bug:xAI 渠道列出
grok-imagine-video,但 type 48 没有视频任务插件。User request
用户说:「New API的话,它不支持这个视频模型吗?那它应该怎么做?」随后确认:「可以,你先改吧,而且我们也fork过这个项目,可以用我们fork的来修改然后build镜像。」改完后又说:「创建一个pr吧」。
Out of scope — refuse
这不是新建逆向渠道,也不是第三方封装。xAI 渠道(type 48)本来就在 New API 里,模型列表已经包含
grok-imagine-video。本 PR 只补这个渠道缺失的视频任务插件,把 OpenAI Video 协议转成上游/v1/videos/generations。Kind
广告出来的模型走不通,属于 bug;同时补上
grok-imagine-video-1.5和 OpenAI Video 端点声明。Issue facts
取自上游 QuantumNous#6358,并与本次本地实测一致。
POST /v1/videos和POST /v1/video/generations返回invalid_api_platform: 48,请求没有出网关。POST /v1/videos/generations返回 200 并生成 mp4;同一 key 走 New API 在进入上游前就被拒。POST /v1/videos、POST /v1/video/generations,channel type 48,modelgrok-imagine-videoplugins/tasks/xai/plugin.jsChange
内置任务插件
plugins/tasks/xai/plugin.js,channelTypes: [48],把客户端 OpenAI Video 请求翻译成 xAI/grok2api 的 generations API。relay/relay_adaptor.go把 platform"48"映射到插件 keyxai,RelayTask不再因为没有 adaptor 直接 400。POST /v1/videos/generations,轮询GET /v1/videos/{id},把上游pending/done/failed映射成任务状态;done与上游 fix(task): support xAI grok-imagine-video task polling QuantumNous/new-api#5927 描述一致。seconds/size转成duration/aspect_ratio/resolution;也接受 grok 原生字段。common/endpoint_type.go给grok-imagine-video*声明openai-video端点。grok-imagine-video-1.5。聊天、图片仍走原有 xAI adaptor,不改通道类型。
Research
Duplicate / prior art
xai grok-imagine-video、invalid_api_platform 48、grok imagine videoDocs and code
channelTypes绑定,GetTaskAdaptor通过taskPluginKeys解析;48 原先不在表里。plugins/tasks/*和relay/relay_adaptor.go。constant.ChannelTypeXai = 48relay/channel/xai/constants.go已列出grok-imagine-videorelay/relay_adaptor.go的taskPluginKeys原先没有 48,导致invalid_api_platform: 48plugins/embed.go会自动注册plugins/tasks/*/plugin.jsAlternatives considered
done)和字段(duration/resolution)与 Sora 不同,需要独立映射。Gemini 也是对话 adaptor + 视频插件共存。Files
plugins/tasks/xai/plugin.jsrelay/relay_adaptor.go"48"→xairelay/channel/xai/constants.gogrok-imagine-video-1.5common/model.goIsVideoGenerationModelcommon/endpoint_type.goopenai-videoplugins/builtin_plugins_test.goplugins/xai_responses_test.gorelay/xai_task_plugin_test.gocommon/endpoint_type_xai_video_test.goBehavior
POST /v1/videos返回invalid_api_platform: 48。GET /v1/videos/{id}/content下载 mp4。grok-chat-fast对话不受影响。Verification
Only what was actually run.
go test ./plugins ./relay ./common ./relay/channel/xai→ passdocker compose build new-api→new-api:datehoer构建成功GET https://api.hotday.uk/v1/models含grok-imagine-video、grok-imagine-video-1.5,supported endpoint 含openai-videoPOST /v1/videosmodel=grok-imagine-videoseconds=6 size=1280x720→ 200status=queued,随后completedGET /v1/videos/{id}/content→video/mp4,约 8.1MBPOST /v1/chat/completionsmodel=grok-chat-fast→ 仍返回ponggrok-imagine-video-1.5会进入 xAI 通道;若上游 Console 视频额度为 0,会返回上游限额/饱和,而不再是 platform 48grok-imagine-video720p 文生视频。Risks
Scope check