Skip to content

feat: support openAI sdk retrieve videos#2000

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/sora-retrieve-video-sdk
Oct 10, 2025
Merged

feat: support openAI sdk retrieve videos#2000
seefs001 merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/sora-retrieve-video-sdk

Conversation

@feitianbubu
Copy link
Copy Markdown
Contributor

@feitianbubu feitianbubu commented Oct 10, 2025

支持openai sdk获取Sora视频
参考: https://platform.openai.com/docs/api-reference/videos/retrieve

import OpenAI from 'openai';
const client = new OpenAI();
const video = await client.videos.retrieve('video_123');
console.log(video.id);
    const video = await client.videos.retrieve(config.get('taskId'));

    console.log('✅ 视频查询成功!');
    console.log('📋 视频任务详情:', video);
    console.log(`   ID: ${video.id}`);
    console.log(`   状态: ${video.status}`);
    console.log(`   创建时间: ${new Date(video.created_at * 1000).toLocaleString()}`);

    if (video.completed_at) {
      console.log(`   完成时间: ${new Date(video.completed_at * 1000).toLocaleString()}`);
    }
image

Summary by CodeRabbit

  • New Features
    • Video task responses now include the task’s data payload, providing richer information for clients.
    • Video detail endpoints return the original task data directly, improving fidelity and alignment with upstream responses.
    • Response behavior remains consistent for status, progress, and reasons while delivering more complete data.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 10, 2025

Walkthrough

Propagates video task response data into local task objects and adjusts relay response construction. For /v1/videos/ URIs, the relay now returns originTask.Data directly; otherwise it marshals a success DTO. Adds t.Data assignment during task update. No exported APIs changed.

Changes

Cohort / File(s) Summary of Changes
Video task data propagation and relay response path
controller/task_video.go, relay/relay_task.go
controller: In updateVideoSingleTask (new API parsing), assign t.Data to task.Data alongside TaskID/Status/Url/Progress/Reason. relay: Reworked videoFetchByIDRespBodyBuilder to early-return when respBody exists; for URIs starting with /v1/videos/ return originTask.Data directly, else marshal TaskModel2Dto(originTask); updated error path label on marshal failure.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Relay as Relay (relay_task.go)
  participant Controller as Controller (task_video.go)
  participant Origin as Origin Service

  Client->>Relay: GET /v1/videos/{id}
  Relay->>Origin: Fetch task by ID
  Origin-->>Relay: originTask (includes Data)
  alt URI starts with /v1/videos/
    Relay-->>Client: originTask.Data (JSON)
  else Other URIs
    Relay->>Relay: Marshal TaskModel2Dto(originTask)
    Relay-->>Client: Success response (DTO)
  end

  note over Controller,Origin: During updates (new API), Controller assigns t.Data -> task.Data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • veo #1792 — Similar edits to propagate task.Data and to return originTask.Data for /v1/videos/ in the relay.
  • feat: vertex veo (#1450) #1659 — Related handling for video task Data, including propagation and specialized relay response logic.

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

I nudge the frames with twitchy care,
Pack Data snug in tasks we share—
The relay hops a shorter lane,
For /videos/ it sends plain grain.
Two files touched, a tidy feat—
Thump-thump! My review is swift and sweet. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the new feature of supporting video retrieval via the OpenAI SDK, which matches the core change introduced in the code and documented in the PR objectives. It is specific, concise, and free of extraneous or vague language.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@seefs001 seefs001 merged commit 721357b into QuantumNous:main Oct 10, 2025
1 check was pending
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b551d9 and ff9f9fb.

📒 Files selected for processing (2)
  • controller/task_video.go (1 hunks)
  • relay/relay_task.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-26T09:59:00.337Z
Learnt from: Sh1n3zZ
PR: QuantumNous/new-api#1659
File: relay/relay_task.go:285-305
Timestamp: 2025-08-26T09:59:00.337Z
Learning: In controller/task_video.go, the redactVideoResponseBody function sanitizes video task responses by removing bytesBase64Encoded fields and truncating base64 strings to 256 characters to prevent large binary data from being stored in task.Data.

Applied to files:

  • relay/relay_task.go
  • controller/task_video.go
🧬 Code graph analysis (1)
relay/relay_task.go (1)
service/error.go (1)
  • TaskErrorWrapper (139-155)
🔇 Additional comments (2)
relay/relay_task.go (2)

365-367: LGTM: Early return pattern improves code clarity.

The early return when respBody is already populated simplifies control flow and avoids unnecessary processing.


373-379: LGTM: Proper error handling for marshaling failures.

The fallback logic correctly marshals a TaskResponse and handles JSON marshaling errors appropriately.

Comment thread controller/task_video.go
taskResult.Url = t.FailReason
taskResult.Progress = t.Progress
taskResult.Reason = t.FailReason
task.Data = t.Data
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 | 🔴 Critical

🧩 Analysis chain

Verify data sanitization for New API response format.

The Data field is now propagated from the New API response, but unlike the alternative parsing path (line 104) which applies redactVideoResponseBody to sanitize large binary data, this path stores t.Data directly without sanitization. This inconsistency could lead to large base64-encoded video data being stored in the database when processing New API format responses.

Verify whether the New API response format already sanitizes the Data field or if sanitization should be applied here as well:

Based on learnings.


🏁 Script executed:

#!/bin/bash
# Description: Check if there are any other locations where New API response data is sanitized
# or if the New API format is expected to return pre-sanitized data

# Search for sanitization patterns in New API response handling
rg -n "dto\.TaskResponse\[model\.Task\]" -A 10 -B 5

# Check if there's documentation or comments about New API data format
rg -n "New API.*Data" -C 3

Length of output: 1122


🏁 Script executed:

#!/bin/bash
# Locate the sanitization function
rg -n "func redactVideoResponseBody" -C3

# Inspect the legacy parsing path to see if it applies sanitization
rg -n "func ParseTaskResult" -C10

Length of output: 354


🏁 Script executed:

#!/bin/bash
# Show imports in controller/task_video.go to locate adaptor package path
sed -n '1,50p' controller/task_video.go

# Search for all definitions and references of ParseTaskResult
rg -n "ParseTaskResult\(" -C3

Length of output: 6385


Sanitize video Data for New API response
The New API path at controller/task_video.go:100 assigns t.Data directly, bypassing redactVideoResponseBody. This can store unbounded base64-encoded video data in the database. Apply redactVideoResponseBody (or equivalent truncation) here as well.

🤖 Prompt for AI Agents
In controller/task_video.go around line 100, the New API path assigns task.Data
= t.Data directly, which bypasses redactVideoResponseBody and can store
unbounded base64 video blobs; replace that direct assignment by passing t.Data
through redactVideoResponseBody (or an equivalent truncation/sanitization
function) and assign the sanitized result to task.Data so only a
truncated/redacted payload is stored.

Comment thread relay/relay_task.go
Comment on lines +369 to +372
if strings.HasPrefix(c.Request.RequestURI, "/v1/videos/") {
respBody = originTask.Data
return
}
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

Validate originTask.Data before returning.

Directly returning originTask.Data for /v1/videos/ URIs assumes the data is valid, non-nil JSON. However, if originTask.Data is nil, empty, or contains invalid JSON (due to database corruption, incomplete task updates, or sanitization issues), the response will fail with cryptic errors since the Content-Type is set to "application/json" in line 207.

Apply this diff to add validation:

 if strings.HasPrefix(c.Request.RequestURI, "/v1/videos/") {
+  if len(originTask.Data) == 0 {
+    taskResp = service.TaskErrorWrapperLocal(errors.New("task data is empty"), "task_data_empty", http.StatusInternalServerError)
+    return
+  }
+  // Validate it's valid JSON
+  if !json.Valid(originTask.Data) {
+    taskResp = service.TaskErrorWrapperLocal(errors.New("task data is not valid JSON"), "invalid_task_data", http.StatusInternalServerError)
+    return
+  }
   respBody = originTask.Data
   return
 }
🤖 Prompt for AI Agents
In relay/relay_task.go around lines 369 to 372, the code returns originTask.Data
directly for requests under /v1/videos/ without checking it; validate
originTask.Data before returning: if originTask.Data is nil or empty, set
respBody to a safe JSON payload (e.g., []byte("null")) or return a proper JSON
error response; otherwise use json.Valid(originTask.Data) to ensure it is valid
JSON and if not valid, log a warning and again set respBody to a safe JSON
payload or return a 5xx JSON error; ensure you do not change the existing
Content-Type and avoid panic by never returning raw nil/invalid bytes.

ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…-video-sdk

feat: support openAI sdk retrieve videos
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.

2 participants