Implementation:Openai Openai node Videos Resource
| Knowledge Sources | |
|---|---|
| Domains | SDK, Video Generation |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The Videos class provides API resource methods for creating, retrieving, listing, deleting, downloading, and remixing AI-generated videos using models like Sora.
Description
The Videos class extends APIResource and exposes six methods covering the full video generation lifecycle. The create method initiates a video generation job with a text prompt, optional input reference image, model selection (defaulting to sora-2), clip duration (4, 8, or 12 seconds), and output resolution. The retrieve method fetches a video job's current status and metadata. The list method returns cursor-paginated video jobs with optional sort ordering.
The delete method removes a video and returns a VideoDeleteResponse confirmation. The downloadContent method retrieves the actual video binary content, with a variant parameter to select between the video MP4, thumbnail, or spritesheet. The remix method creates a new video based on an existing one with an updated prompt.
The Video interface describes the video job object with fields for status tracking (status: queued/in_progress/completed/failed, progress: 0-100), metadata (model, prompt, seconds, size), timestamps (created_at, completed_at, expires_at), error information, and remix provenance (remixed_from_video_id). Supported models include sora-2 and sora-2-pro variants.
Usage
Use this resource to generate videos from text prompts, monitor generation progress, download completed videos, or create remixed variations of existing videos. It is the primary interface for interacting with OpenAI's video generation capabilities.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/videos.ts
Signature
export class Videos extends APIResource {
create(body: VideoCreateParams, options?: RequestOptions): APIPromise<Video>;
retrieve(videoID: string, options?: RequestOptions): APIPromise<Video>;
list(query?: VideoListParams | null, options?: RequestOptions): PagePromise<VideosPage, Video>;
delete(videoID: string, options?: RequestOptions): APIPromise<VideoDeleteResponse>;
downloadContent(videoID: string, query?: VideoDownloadContentParams | null, options?: RequestOptions): APIPromise<Response>;
remix(videoID: string, body: VideoRemixParams, options?: RequestOptions): APIPromise<Video>;
}
export interface Video {
id: string;
completed_at: number | null;
created_at: number;
error: VideoCreateError | null;
expires_at: number | null;
model: VideoModel;
object: 'video';
progress: number;
prompt: string | null;
remixed_from_video_id: string | null;
seconds: VideoSeconds;
size: VideoSize;
status: 'queued' | 'in_progress' | 'completed' | 'failed';
}
export type VideoModel = string | 'sora-2' | 'sora-2-pro' | ...;
export type VideoSeconds = '4' | '8' | '12';
export type VideoSize = '720x1280' | '1280x720' | '1024x1792' | '1792x1024';
Import
import OpenAI from 'openai';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| body.prompt | string |
Yes (create/remix) | Text prompt describing the video to generate. |
| body.model | VideoModel |
No (create) | Video generation model; defaults to sora-2.
|
| body.seconds | '8' | '12' | No (create) | Clip duration in seconds; defaults to 4. |
| body.size | VideoSize |
No (create) | Output resolution (e.g., '1280x720'); defaults to '720x1280'.
|
| body.input_reference | Uploadable |
No (create) | Optional image reference to guide generation. |
| videoID | string |
Yes (retrieve/delete/download/remix) | The video job identifier. |
| query.variant | 'thumbnail' | 'spritesheet' | No (downloadContent) | Which downloadable asset to return; defaults to video MP4. |
| query.order | 'desc' | No (list) | Sort order by timestamp. |
| options | RequestOptions |
No | Additional request configuration. |
Outputs
| Name | Type | Description |
|---|---|---|
| id | string |
Unique video job identifier. |
| status | 'in_progress' | 'completed' | 'failed' | Current lifecycle status. |
| progress | number |
Approximate completion percentage (0-100). |
| model | VideoModel |
The model used for generation. |
| prompt | null | The text prompt used. |
| seconds | VideoSeconds |
Clip duration. |
| size | VideoSize |
Output resolution. |
| created_at | number |
Unix timestamp when the job was created. |
| completed_at | null | Unix timestamp when the job finished. |
| expires_at | null | Unix timestamp when downloadable assets expire. |
| error | null | Error details if generation failed. |
| remixed_from_video_id | null | Source video ID if this is a remix. |
Usage Examples
import OpenAI from 'openai';
const client = new OpenAI();
// Create a video
const video = await client.videos.create({
prompt: 'A serene mountain lake at sunrise with mist rising from the water',
model: 'sora-2',
seconds: '8',
size: '1280x720',
});
console.log(video.id, video.status);
// Poll for completion
let result = await client.videos.retrieve(video.id);
while (result.status !== 'completed' && result.status !== 'failed') {
await new Promise((r) => setTimeout(r, 5000));
result = await client.videos.retrieve(video.id);
console.log(`Progress: ${result.progress}%`);
}
// Download the completed video
const response = await client.videos.downloadContent(video.id, { variant: 'video' });
// List all videos
for await (const v of client.videos.list({ order: 'desc' })) {
console.log(v.id, v.status);
}
// Create a remix
const remix = await client.videos.remix(video.id, {
prompt: 'Same scene but during a thunderstorm with dramatic lighting',
});
// Delete a video
const deleted = await client.videos.delete(video.id);
console.log(deleted.deleted); // true