feat(videos): add support for video_url extraction and validation in handlers

- Updated `openai_videos_handlers` to extract and set `video_url` from payloads when available.
- Enhanced unit tests to validate correct `video_url` extraction and inclusion in responses.
This commit is contained in:
Luis Pater
2026-06-16 21:06:27 +08:00
parent f63cf9820a
commit 2884a67ed0
2 changed files with 6 additions and 0 deletions
@@ -559,6 +559,9 @@ func buildVideosRetrieveAPIResponseFromXAI(videoID string, payload []byte, fallb
} else if duration := gjson.GetBytes(payload, "video.duration"); duration.Exists() {
out, _ = sjson.SetBytes(out, "seconds", duration.String())
}
if videoURL := strings.TrimSpace(gjson.GetBytes(payload, "video.url").String()); videoURL != "" {
out, _ = sjson.SetBytes(out, "video_url", videoURL)
}
out = setOpenAIVideoErrorFromXAI(out, payload)
return out, nil
}
@@ -317,6 +317,9 @@ func TestBuildVideosRetrieveAPIResponseFromXAI(t *testing.T) {
if got := gjson.GetBytes(out, "seconds").String(); got != "4" {
t.Fatalf("seconds = %q, want 4", got)
}
if got := gjson.GetBytes(out, "video_url").String(); got != "https://vidgen.x.ai/xai-vidgen-bucket/xai-video-08609066-e7e9-43ba-bd8d-bd29cb6221d9.mp4" {
t.Fatalf("video_url = %q", got)
}
if gjson.GetBytes(out, "video").Exists() {
t.Fatalf("video field must not be exposed in OpenAI retrieve response: %s", string(out))
}