Skip to content

fix(video): 参考图张数与时长在入队前校验,不再产出必然失败的任务 - #931

Open
741075810 wants to merge 1 commit into
chenyme:mainfrom
741075810:pr/video-admission-limits
Open

fix(video): 参考图张数与时长在入队前校验,不再产出必然失败的任务#931
741075810 wants to merge 1 commit into
chenyme:mainfrom
741075810:pr/video-admission-limits

Conversation

@741075810

Copy link
Copy Markdown
Contributor

背景

POST /v1/videos/generations 是异步接口:create 入队即返回 request_id,参数问题只在轮询 GET /v1/videos/{id}status:failed 里体现。Console 视频的两条限制目前只在 console.Adapter.GenerateVideo(provider 层)拦截,于是客户端会先拿到一个 request_id,再从轮询里读到一个必然失败的任务。

生产环境实测(同一台部署,v3.1.2 + 当前 main):

POST /v1/videos/generations
{"model":"grok-imagine-video","duration":15,"resolution":"720p",
 "reference_images":[{"file_id":"..."},{"file_id":"..."}]}
-> 200 {"request_id":"video_09odbhi6ppYgRZ31FG2jJijW"}

GET /v1/videos/video_09odbhi6ppYgRZ31FG2jJijW
-> {"status":"failed","error":{"code":"internal_error",
     "message":"grok-imagine-video 的参考图生视频最长 10 秒,当前为 15 秒"}}

另外张数上限在入站层用的是与 provider 不一致的值,报错数字也因此是错的:

POST /v1/videos/generations  reference_images × 9
-> 400 {"code":"invalid_request","message":"reference_images 不能超过 8 张"}

mediadomain.MaxInputImages 是跨 provider 的粗粒度上界(Grok Build 的 buildVideoMaxImages 也用它,DB 的 input_image_count CHECK 同样以它为上界),而 Console 的 reference_images 上游实测上限是 7。所以传 8 张能过入站校验,随后在 provider 层被拒——又是一个失败任务。

改动

把这两条已经在 provider 层执行的规则,提到 validateVideoRouteParameters(也就是 1080p 校验所在的位置)在入队前执行,仅对 Console 视频上游模型生效:

  • reference_images 超过 7 张直接返回错误,并在文案里给出真实上限与当前张数
  • grok-imagine-video 且带 reference_imagesduration > 10 直接返回错误

image(image-to-video)、纯文本生视频、以及 grok-imagine-video-1.5 的多参考图 15s 都不受影响。非 Console 视频模型完全不进这段逻辑。入站层的 MaxInputImages 保持不变,继续作为跨 provider 的外层上界。

依据

两条限制都来自对 Console POST /v1/videos/generations 的黑盒实测,上游报错原文如下。

参考图张数上限,两个视频模型分别验证:

400 {"code":"invalid-argument","error":"Too many reference images: 8. Maximum allowed is 7."}

基础模型的 reference-to-video 时长上限,只传 1 张参考图时同样被拒,所以该上限与张数无关:

400 {"code":"invalid-argument","error":"Duration 15s exceeds the maximum allowed for reference-to-video, which is 10s."}

作为对照,grok-imagine-video-1.5 的多参考图 15s 与走 image 字段的 image-to-video 15s 都能正常出片,因此守卫按「模型 + 是否有 reference_images」分档,而不是只看 duration。

复测时要注意:Console 的限频是 team + model 级而不是账号级,实测 Requests per Second 2/2Requests per Minute 60,换账号并不能规避 429;而且 429 的优先级高于参数校验,连发用例很容易把配额错误误读成接口契约。

测试

新增 TestVideoRouteParametersRejectConsoleReferenceLimits,覆盖 8 张被拒 / 7 张放行、基础模型带参考图 15s 被拒 / 10s 放行、基础模型纯文本或首帧 15s 放行、1.5 多参考图 15s 放行、以及非 Console 模型不受影响。既有的 TestVideo1080pValidationUsesResolvedUpstreamModel 同步补上新参数,断言不变。

本地:go build ./...go vet ./...go test ./... 全部通过。

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.

1 participant