api_openai/components/
images.rs

1//! Structures related to image generation and manipulation responses.
2
3/// Define a private namespace for all its items.
4mod private
5{
6  // Serde imports
7  use serde::{ Serialize, Deserialize }; // Added Serialize
8
9  /// Represents the url or the content of an image generated by the `OpenAI` API.
10  ///
11  /// # Used By
12  /// - `ImagesResponse`
13  #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
14  pub struct Image
15  {
16    /// The base64-encoded JSON of the generated image, if `response_format` is `b64_json`.
17    #[ serde( skip_serializing_if = "Option::is_none" ) ]
18    pub b64_json : Option< String >,
19    /// The URL of the generated image, if `response_format` is `url` (default). URLs are only valid for 60 minutes.
20    #[ serde( skip_serializing_if = "Option::is_none" ) ]
21    pub url : Option< String >,
22    /// The prompt that was used to generate the image, if there was any revision to the prompt.
23    #[ serde( skip_serializing_if = "Option::is_none" ) ]
24    pub revised_prompt : Option< String >,
25  }
26
27  /// Represents the response object for image generation, edit, and variation endpoints.
28  ///
29  /// # Used By
30  /// - `/images/generations` (POST)
31  /// - `/images/edits` (POST)
32  /// - `/images/variations` (POST)
33  #[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ] // Added Serialize
34  pub struct ImagesResponse
35  {
36    /// The Unix timestamp (in seconds) when the response was created.
37    pub created : i64,
38    /// A list of generated image objects.
39    pub data : Vec< Image >,
40  }
41
42  /// Request parameters for editing an image.
43  ///
44  /// # Used By
45  /// - `/images/edits` (POST request)
46  #[ derive( Debug, Clone ) ]
47  pub struct CreateImageEditRequest
48  {
49    /// The image to edit. Must be a valid PNG file, less than 4MB, and square.
50    pub image : Vec< u8 >,
51    /// The filename for the image file.
52    pub image_filename : String,
53    /// An additional image whose fully transparent areas indicate where image should be edited.
54    /// Must be a PNG file, less than 4MB, and have the same dimensions as image.
55    pub mask : Option< Vec< u8 > >,
56    /// The filename for the mask file (if mask is provided).
57    pub mask_filename : Option< String >,
58    /// A text description of the desired image(s). The maximum length is 1000 characters.
59    pub prompt : String,
60    /// The model to use for image generation.
61    pub model : Option< String >,
62    /// The number of images to generate. Must be between 1 and 10.
63    pub n : Option< i32 >,
64    /// The size of the generated images.
65    pub size : Option< String >,
66    /// The format in which the generated images are returned.
67    pub response_format : Option< String >,
68    /// A unique identifier representing your end-user.
69    pub user : Option< String >,
70  }
71
72  /// Request parameters for creating a variation of an image.
73  ///
74  /// # Used By
75  /// - `/images/variations` (POST request)
76  #[ derive( Debug, Clone ) ]
77  pub struct CreateImageVariationRequest
78  {
79    /// The image to create a variation of. Must be a valid PNG file, less than 4MB, and square.
80    pub image : Vec< u8 >,
81    /// The filename for the image file.
82    pub image_filename : String,
83    /// The model to use for image generation.
84    pub model : Option< String >,
85    /// The number of images to generate. Must be between 1 and 10.
86    pub n : Option< i32 >,
87    /// The format in which the generated images are returned.
88    pub response_format : Option< String >,
89    /// The size of the generated images.
90    pub size : Option< String >,
91    /// A unique identifier representing your end-user.
92    pub user : Option< String >,
93  }
94} // end mod private
95
96crate ::mod_interface!
97{
98  exposed use
99  {
100    Image,
101    ImagesResponse,
102    CreateImageEditRequest,
103    CreateImageVariationRequest,
104  };
105}