Skip to main content

async_openai/types/videos/
video.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5use crate::types::videos::ImageInput;
6use crate::types::InputSource;
7
8#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
9pub enum VideoSize {
10    #[default]
11    #[serde(rename = "720x1280")]
12    S720x1280,
13    #[serde(rename = "1280x720")]
14    S1280x720,
15    #[serde(rename = "1024x1792")]
16    S1024x1792,
17    #[serde(rename = "1792x1024")]
18    S1792x1024,
19}
20
21#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
22pub enum VideoSeconds {
23    #[default]
24    #[serde(rename = "4")]
25    Four,
26    #[serde(rename = "8")]
27    Eight,
28    #[serde(rename = "12")]
29    Twelve,
30    #[serde(rename = "16")]
31    Sixteen,
32    #[serde(rename = "20")]
33    Twenty,
34    #[serde(untagged)]
35    Other(String),
36}
37
38/// Reference to a completed video by its ID.
39#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
40pub struct VideoReferenceInputParam {
41    /// The identifier of the completed video.
42    pub id: String,
43}
44
45/// Image reference parameter for video generation.
46#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
47pub struct ImageRefParam {
48    /// A fully qualified URL or base64-encoded data URL.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub image_url: Option<String>,
51    /// A file ID.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub file_id: Option<String>,
54}
55
56// CreateVideoJsonBody in the spec
57#[derive(Clone, Default, Debug, Builder, PartialEq)]
58#[builder(name = "CreateVideoRequestArgs")]
59#[builder(pattern = "mutable")]
60#[builder(setter(into, strip_option), default)]
61#[builder(derive(Debug))]
62#[builder(build_fn(error = "OpenAIError"))]
63pub struct CreateVideoRequest {
64    /// The video generation model to use (allowed values: sora-2, sora-2-pro). Defaults to `sora-2`.
65    pub model: String,
66
67    /// Text prompt that describes the video to generate.
68    pub prompt: String,
69    /// Output resolution formatted as width x height (allowed values: 720x1280, 1280x720, 1024x1792,
70    /// 1792x1024). Defaults to 720x1280.
71    pub size: Option<VideoSize>,
72    /// Clip duration in seconds (allowed values: 4, 8, 12). Defaults to 4 seconds.
73    pub seconds: Option<VideoSeconds>,
74    /// Optional image reference that guides generation.
75    pub input_reference: Option<ImageInput>,
76    /// Character IDs to include in the generation.
77    pub character_ids: Option<Vec<String>>,
78}
79
80/// Parameters for creating a video character.
81#[derive(Clone, Default, Debug, Builder, PartialEq)]
82#[builder(name = "CreateVideoCharacterRequestArgs")]
83#[builder(pattern = "mutable")]
84#[builder(setter(into, strip_option), default)]
85#[builder(derive(Debug))]
86#[builder(build_fn(error = "OpenAIError"))]
87pub struct CreateVideoCharacterRequest {
88    /// Video file used to create a character.
89    pub video: InputSource,
90    /// Display name for this API character.
91    pub name: String,
92}
93
94/// Parameters for editing an existing generated video.
95#[derive(Clone, Default, Debug, Builder, PartialEq)]
96#[builder(name = "CreateVideoEditRequestArgs")]
97#[builder(pattern = "mutable")]
98#[builder(setter(into, strip_option), default)]
99#[builder(derive(Debug))]
100#[builder(build_fn(error = "OpenAIError"))]
101pub struct CreateVideoEditRequest {
102    /// Reference to the completed video to edit (video ID or uploaded file).
103    pub video: VideoEditInput,
104    /// Text prompt that describes how to edit the source video.
105    pub prompt: String,
106}
107
108/// Input for video edit - either a reference to an existing video or a file upload.
109#[derive(Clone, Debug, PartialEq)]
110pub enum VideoEditInput {
111    /// A reference to a completed video by its ID.
112    Reference(VideoReferenceInputParam),
113    /// A video input source.
114    Input(InputSource),
115}
116
117impl Default for VideoEditInput {
118    fn default() -> Self {
119        Self::Reference(VideoReferenceInputParam::default())
120    }
121}
122
123/// Parameters for extending a completed video.
124#[derive(Clone, Default, Debug, Builder, PartialEq)]
125#[builder(name = "CreateVideoExtendRequestArgs")]
126#[builder(pattern = "mutable")]
127#[builder(setter(into, strip_option), default)]
128#[builder(derive(Debug))]
129#[builder(build_fn(error = "OpenAIError"))]
130pub struct CreateVideoExtendRequest {
131    /// Reference to the completed video to extend (video ID or uploaded file).
132    pub video: VideoEditInput,
133    /// Updated text prompt that directs the extension generation.
134    pub prompt: String,
135    /// Length of the newly generated extension segment in seconds (allowed values: 4, 8, 12, 16, 20).
136    pub seconds: Option<VideoSeconds>,
137}
138
139#[derive(Clone, Default, Debug, Builder, PartialEq, Serialize)]
140#[builder(name = "RemixVideoRequestArgs")]
141#[builder(pattern = "mutable")]
142#[builder(setter(into, strip_option), default)]
143#[builder(derive(Debug))]
144#[builder(build_fn(error = "OpenAIError"))]
145pub struct RemixVideoRequest {
146    pub prompt: String,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct VideoResourceError {
151    pub code: String,
152    pub message: String,
153}
154
155/// Structured information describing a generated video job.
156#[derive(Debug, Clone, Serialize, Deserialize)]
157pub struct VideoResource {
158    /// Unix timestamp (seconds) for when the job completed, if finished.
159    pub completed_at: Option<u64>,
160
161    /// Unix timestamp (seconds) for when the job was created.
162    pub created_at: u64,
163
164    /// Error payload that explains why generation failed, if applicable.
165    pub error: Option<VideoResourceError>,
166
167    /// Unix timestamp (seconds) for when the downloadable assets expire, if set.
168    pub expires_at: Option<u64>,
169
170    /// Unique identifier for the video job.
171    pub id: String,
172
173    /// The video generation model that produced the job.
174    pub model: String,
175
176    /// The object type, which is always video.
177    pub object: String,
178
179    /// Approximate completion percentage for the generation task.
180    pub progress: u8,
181
182    /// Identifier of the source video if this video is a remix.
183    pub remixed_from_video_id: Option<String>,
184
185    /// Duration of the generated clip in seconds. For extensions, this is the stitched total duration.
186    pub seconds: VideoSeconds,
187
188    /// The resolution of the generated video.
189    pub size: VideoSize,
190
191    /// Current lifecycle status of the video job.
192    pub status: VideoStatus,
193}
194
195/// Character resource returned by character creation and retrieval.
196#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct VideoCharacterResource {
198    /// Identifier for the character.
199    pub id: Option<String>,
200    /// Display name for the character.
201    pub name: Option<String>,
202    /// Unix timestamp (in seconds) when the character was created.
203    pub created_at: u64,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
207#[serde(rename_all = "snake_case")]
208pub enum VideoStatus {
209    Queued,
210    InProgress,
211    Completed,
212    Failed,
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize)]
216pub struct DeletedVideoResource {
217    pub id: String,
218    pub object: String,
219    pub deleted: bool,
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize)]
223pub struct VideoListResource {
224    pub data: Vec<VideoResource>,
225    pub object: String,
226    pub first_id: Option<String>,
227    pub last_id: Option<String>,
228    pub has_more: bool,
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize, Default)]
232#[serde(rename_all = "lowercase")]
233pub enum VideoVariant {
234    #[default]
235    Video,
236    Thumbnail,
237    Spritesheet,
238}