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}
52
53#[derive(Clone, Default, Debug, Builder, PartialEq, Serialize)]
54#[builder(name = "RemixVideoRequestArgs")]
55#[builder(pattern = "mutable")]
56#[builder(setter(into, strip_option), default)]
57#[builder(derive(Debug))]
58#[builder(build_fn(error = "OpenAIError"))]
59pub struct RemixVideoRequest {
60    pub prompt: String,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct VideoResourceError {
65    pub code: String,
66    pub message: String,
67}
68
69/// Structured information describing a generated video job.
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct VideoResource {
72    /// Unix timestamp (seconds) for when the job completed, if finished.
73    pub completed_at: Option<u64>,
74
75    /// Unix timestamp (seconds) for when the job was created.
76    pub created_at: u64,
77
78    /// Error payload that explains why generation failed, if applicable.
79    pub error: Option<VideoResourceError>,
80
81    /// Unix timestamp (seconds) for when the downloadable assets expire, if set.
82    pub expires_at: Option<u64>,
83
84    /// Unique identifier for the video job.
85    pub id: String,
86
87    /// The video generation model that produced the job.
88    pub model: String,
89
90    /// The object type, which is always video.
91    pub object: String,
92
93    /// Approximate completion percentage for the generation task.
94    pub progress: u8,
95
96    /// Identifier of the source video if this video is a remix.
97    pub remixed_from_video_id: Option<String>,
98
99    /// Duration of the generated clip in seconds.
100    pub seconds: VideoSeconds,
101
102    /// The resolution of the generated video.
103    pub size: VideoSize,
104
105    /// Current lifecycle status of the video job.
106    pub status: VideoStatus,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(rename_all = "snake_case")]
111pub enum VideoStatus {
112    Queued,
113    InProgress,
114    Completed,
115    Failed,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct DeletedVideoResource {
120    pub id: String,
121    pub object: String,
122    pub deleted: bool,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct VideoListResource {
127    pub data: Vec<VideoResource>,
128    pub object: String,
129    pub first_id: Option<String>,
130    pub last_id: Option<String>,
131    pub has_more: bool,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize, Default)]
135#[serde(rename_all = "lowercase")]
136pub enum VideoVariant {
137    #[default]
138    Video,
139    Thumbnail,
140    Spritesheet,
141}