portkey_sdk/model/images.rs
1use serde::{Deserialize, Serialize};
2
3/// Image quality options for DALL-E 3
4#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
5#[serde(rename_all = "lowercase")]
6pub enum ImageQuality {
7 /// Standard quality
8 #[default]
9 Standard,
10
11 /// High definition quality with finer details
12 Hd,
13}
14
15/// Image response format
16#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
17#[serde(rename_all = "snake_case")]
18pub enum ImageResponseFormat {
19 /// URL to the generated image (valid for 60 minutes)
20 #[default]
21 Url,
22
23 /// Base64-encoded JSON of the image
24 B64Json,
25}
26
27/// Image size options
28#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
29pub enum ImageSize {
30 /// 256x256 pixels (DALL-E 2 only)
31 #[serde(rename = "256x256")]
32 Size256x256,
33
34 /// 512x512 pixels (DALL-E 2 only)
35 #[serde(rename = "512x512")]
36 Size512x512,
37
38 /// 1024x1024 pixels (DALL-E 2 and 3)
39 #[serde(rename = "1024x1024")]
40 #[default]
41 Size1024x1024,
42
43 /// 1792x1024 pixels (DALL-E 3 only)
44 #[serde(rename = "1792x1024")]
45 Size1792x1024,
46
47 /// 1024x1792 pixels (DALL-E 3 only)
48 #[serde(rename = "1024x1792")]
49 Size1024x1792,
50}
51
52/// Image style for DALL-E 3
53#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
54#[serde(rename_all = "lowercase")]
55pub enum ImageStyle {
56 /// Hyper-real and dramatic images
57 #[default]
58 Vivid,
59
60 /// More natural, less hyper-real images
61 Natural,
62}
63
64/// Request to generate an image.
65///
66/// # Example
67///
68/// ```rust
69/// use portkey_sdk::model::{CreateImageRequest, ImageSize, ImageQuality, ImageStyle};
70///
71/// let request = CreateImageRequest {
72/// prompt: "A cute baby sea otter".to_string(),
73/// model: Some("dall-e-3".to_string()),
74/// n: Some(1),
75/// quality: Some(ImageQuality::Hd),
76/// response_format: None,
77/// size: Some(ImageSize::Size1024x1024),
78/// style: Some(ImageStyle::Vivid),
79/// user: None,
80/// };
81/// ```
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct CreateImageRequest {
84 /// A text description of the desired image(s).
85 ///
86 /// Maximum length is 1000 characters for DALL-E 2 and 4000 characters for DALL-E 3.
87 pub prompt: String,
88
89 /// The model to use for image generation (default: dall-e-2)
90 #[serde(skip_serializing_if = "Option::is_none")]
91 pub model: Option<String>,
92
93 /// Number of images to generate (1-10).
94 ///
95 /// For DALL-E 3, only n=1 is supported.
96 #[serde(skip_serializing_if = "Option::is_none")]
97 pub n: Option<i32>,
98
99 /// Image quality (DALL-E 3 only).
100 ///
101 /// `hd` creates images with finer details and greater consistency.
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub quality: Option<ImageQuality>,
104
105 /// Format for the generated images.
106 ///
107 /// URLs are only valid for 60 minutes after generation.
108 #[serde(skip_serializing_if = "Option::is_none")]
109 pub response_format: Option<ImageResponseFormat>,
110
111 /// Size of the generated images.
112 ///
113 /// For DALL-E 2: 256x256, 512x512, or 1024x1024.
114 /// For DALL-E 3: 1024x1024, 1792x1024, or 1024x1792.
115 #[serde(skip_serializing_if = "Option::is_none")]
116 pub size: Option<ImageSize>,
117
118 /// Style of the generated images (DALL-E 3 only).
119 ///
120 /// `vivid` generates hyper-real and dramatic images.
121 /// `natural` generates more natural, less hyper-real images.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub style: Option<ImageStyle>,
124
125 /// A unique identifier representing your end-user
126 #[serde(skip_serializing_if = "Option::is_none")]
127 pub user: Option<String>,
128}
129
130/// A single generated image.
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct Image {
133 /// Base64-encoded JSON of the image (if response_format is b64_json)
134 #[serde(skip_serializing_if = "Option::is_none")]
135 pub b64_json: Option<String>,
136
137 /// URL of the generated image (if response_format is url)
138 #[serde(skip_serializing_if = "Option::is_none")]
139 pub url: Option<String>,
140
141 /// The revised prompt that was used to generate the image
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub revised_prompt: Option<String>,
144}
145
146/// Response from image generation.
147///
148/// # Example
149///
150/// ```rust
151/// use portkey_sdk::model::{ImagesResponse, Image};
152///
153/// let response = ImagesResponse {
154/// created: 1677652288,
155/// data: vec![
156/// Image {
157/// url: Some("https://...".to_string()),
158/// b64_json: None,
159/// revised_prompt: Some("A cute baby sea otter swimming".to_string()),
160/// }
161/// ],
162/// };
163/// ```
164#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct ImagesResponse {
166 /// Unix timestamp of when the images were created
167 pub created: i64,
168
169 /// Array of generated images
170 pub data: Vec<Image>,
171}
172
173/// Request for editing an image with a prompt.
174///
175/// # Example
176///
177/// ```
178/// use portkey_sdk::model::{CreateImageEditRequest, ImageSize, ImageResponseFormat};
179///
180/// let request = CreateImageEditRequest {
181/// prompt: "A cute baby sea otter wearing a beret".to_string(),
182/// model: Some("dall-e-2".to_string()),
183/// n: Some(1),
184/// size: Some(ImageSize::Size1024x1024),
185/// response_format: Some(ImageResponseFormat::Url),
186/// user: None,
187/// };
188/// ```
189#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct CreateImageEditRequest {
191 /// A text description of the desired image(s).
192 ///
193 /// Maximum length is 1000 characters.
194 pub prompt: String,
195
196 /// The model to use for image generation.
197 ///
198 /// Only `dall-e-2` is supported for edits.
199 #[serde(skip_serializing_if = "Option::is_none")]
200 pub model: Option<String>,
201
202 /// Number of images to generate (1-10).
203 #[serde(skip_serializing_if = "Option::is_none")]
204 pub n: Option<i32>,
205
206 /// Size of the generated images.
207 ///
208 /// Must be one of `256x256`, `512x512`, or `1024x1024`.
209 #[serde(skip_serializing_if = "Option::is_none")]
210 pub size: Option<ImageSize>,
211
212 /// Format for the generated images.
213 #[serde(skip_serializing_if = "Option::is_none")]
214 pub response_format: Option<ImageResponseFormat>,
215
216 /// A unique identifier representing your end-user
217 #[serde(skip_serializing_if = "Option::is_none")]
218 pub user: Option<String>,
219}
220
221/// Request for creating a variation of an image.
222///
223/// # Example
224///
225/// ```
226/// use portkey_sdk::model::{CreateImageVariationRequest, ImageSize, ImageResponseFormat};
227///
228/// let request = CreateImageVariationRequest {
229/// model: Some("dall-e-2".to_string()),
230/// n: Some(2),
231/// size: Some(ImageSize::Size1024x1024),
232/// response_format: Some(ImageResponseFormat::Url),
233/// user: None,
234/// };
235/// ```
236#[derive(Debug, Clone, Default, Serialize, Deserialize)]
237pub struct CreateImageVariationRequest {
238 /// The model to use for image generation.
239 ///
240 /// Only `dall-e-2` is supported for variations.
241 #[serde(skip_serializing_if = "Option::is_none")]
242 pub model: Option<String>,
243
244 /// Number of images to generate (1-10).
245 #[serde(skip_serializing_if = "Option::is_none")]
246 pub n: Option<i32>,
247
248 /// Size of the generated images.
249 ///
250 /// Must be one of `256x256`, `512x512`, or `1024x1024`.
251 #[serde(skip_serializing_if = "Option::is_none")]
252 pub size: Option<ImageSize>,
253
254 /// Format for the generated images.
255 #[serde(skip_serializing_if = "Option::is_none")]
256 pub response_format: Option<ImageResponseFormat>,
257
258 /// A unique identifier representing your end-user
259 #[serde(skip_serializing_if = "Option::is_none")]
260 pub user: Option<String>,
261}