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;
6
7#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
8pub enum VideoSize {
9    #[default]
10    #[serde(rename = "720x1280")]
11    S720x1280,
12    #[serde(rename = "1280x720")]
13    S1280x720,
14    #[serde(rename = "1024x1792")]
15    S1024x1792,
16    #[serde(rename = "1792x1024")]
17    S1792x1024,
18}
19
20#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
21pub enum VideoSeconds {
22    #[default]
23    #[serde(rename = "4")]
24    Four,
25    #[serde(rename = "8")]
26    Eight,
27    #[serde(rename = "12")]
28    Twelve,
29}
30
31// CreateVideoBody in the spec
32#[derive(Clone, Default, Debug, Builder, PartialEq)]
33#[builder(name = "CreateVideoRequestArgs")]
34#[builder(pattern = "mutable")]
35#[builder(setter(into, strip_option), default)]
36#[builder(derive(Debug))]
37#[builder(build_fn(error = "OpenAIError"))]
38pub struct CreateVideoRequest {
39    /// The video generation model to use (allowed values: sora-2, sora-2-pro). Defaults to `sora-2`.
40    pub model: String,
41
42    /// Text prompt that describes the video to generate.
43    pub prompt: String,
44    /// Output resolution formatted as width x height (allowed values: 720x1280, 1280x720, 1024x1792,
45    /// 1792x1024). Defaults to 720x1280.
46    pub size: Option<VideoSize>,
47    /// Clip duration in seconds (allowed values: 4, 8, 12). Defaults to 4 seconds.
48    pub seconds: Option<VideoSeconds>,
49    /// Optional image reference that guides generation.
50    pub input_reference: Option<ImageInput>,
51    /// Character IDs to include in the generation.
52    pub character_ids: Option<Vec<String>>,
53}
54
55#[derive(Clone, Default, Debug, Builder, PartialEq, Serialize)]
56#[builder(name = "RemixVideoRequestArgs")]
57#[builder(pattern = "mutable")]
58#[builder(setter(into, strip_option), default)]
59#[builder(derive(Debug))]
60#[builder(build_fn(error = "OpenAIError"))]
61pub struct RemixVideoRequest {
62    pub prompt: String,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct VideoResourceError {
67    pub code: String,
68    pub message: String,
69}
70
71/// Structured information describing a generated video job.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct VideoResource {
74    /// Unix timestamp (seconds) for when the job completed, if finished.
75    pub completed_at: Option<u64>,
76
77    /// Unix timestamp (seconds) for when the job was created.
78    pub created_at: u64,
79
80    /// Error payload that explains why generation failed, if applicable.
81    pub error: Option<VideoResourceError>,
82
83    /// Unix timestamp (seconds) for when the downloadable assets expire, if set.
84    pub expires_at: Option<u64>,
85
86    /// Unique identifier for the video job.
87    pub id: String,
88
89    /// The video generation model that produced the job.
90    pub model: String,
91
92    /// The object type, which is always video.
93    pub object: String,
94
95    /// Approximate completion percentage for the generation task.
96    pub progress: u8,
97
98    /// Identifier of the source video if this video is a remix.
99    pub remixed_from_video_id: Option<String>,
100
101    /// Duration of the generated clip in seconds.
102    pub seconds: VideoSeconds,
103
104    /// The resolution of the generated video.
105    pub size: VideoSize,
106
107    /// Current lifecycle status of the video job.
108    pub status: VideoStatus,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(rename_all = "snake_case")]
113pub enum VideoStatus {
114    Queued,
115    InProgress,
116    Completed,
117    Failed,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct DeletedVideoResource {
122    pub id: String,
123    pub object: String,
124    pub deleted: bool,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct VideoListResource {
129    pub data: Vec<VideoResource>,
130    pub object: String,
131    pub first_id: Option<String>,
132    pub last_id: Option<String>,
133    pub has_more: bool,
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize, Default)]
137#[serde(rename_all = "lowercase")]
138pub enum VideoVariant {
139    #[default]
140    Video,
141    Thumbnail,
142    Spritesheet,
143}