xai_openapi/
images.rs

1//! Image generation API types for `/v1/images/generations` and `/v1/images/edits` endpoints.
2
3use serde::{Deserialize, Serialize};
4
5use crate::prelude::*;
6
7use crate::common::ImageUrl;
8
9/// Quality level for image generation.
10#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
11#[serde(rename_all = "lowercase")]
12pub enum ImageQuality {
13    /// Low quality.
14    Low,
15    /// Medium quality.
16    #[default]
17    Medium,
18    /// High quality.
19    High,
20}
21
22/// Request to generate image for `/v1/images/generations` endpoint.
23#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
24pub struct GenerateImageRequest {
25    /// Prompt for image generation.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub prompt: Option<String>,
28
29    /// Model to be used.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub model: Option<String>,
32
33    /// Number of images to be generated.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub n: Option<i32>,
36
37    /// Quality of the output image.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub quality: Option<ImageQuality>,
40
41    /// Response format to return the image in. Can be `url` or `b64_json`.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub response_format: Option<String>,
44
45    /// (Not supported) Size of the image.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub size: Option<String>,
48
49    /// (Not supported) Style of the image.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub style: Option<String>,
52
53    /// A unique identifier representing your end-user.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub user: Option<String>,
56}
57
58/// Request for editing image.
59#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
60pub struct EditImageRequest {
61    /// Prompt for image editing.
62    pub prompt: String,
63
64    /// Input image to perform edit on.
65    pub image: ImageUrl,
66
67    /// Mask image.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub mask: Option<ImageUrl>,
70
71    /// Model to be used.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub model: Option<String>,
74
75    /// Number of image edits to be generated.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub n: Option<i32>,
78
79    /// Quality of the output image.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub quality: Option<ImageQuality>,
82
83    /// Response format to return the image in.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub response_format: Option<String>,
86
87    /// (Not supported) Size of the image.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub size: Option<String>,
90
91    /// (Not supported) Style of the image.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub style: Option<String>,
94
95    /// A unique identifier representing your end-user.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub user: Option<String>,
98}
99
100/// Image generation response for `/v1/images/generations` endpoint.
101#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
102pub struct GeneratedImageResponse {
103    /// A list of generated image objects.
104    pub data: Vec<GeneratedImage>,
105}
106
107/// Generated image.
108#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
109pub struct GeneratedImage {
110    /// The revised prompt generated by a chat model from the original prompt.
111    pub revised_prompt: String,
112
113    /// A url to the generated image.
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub url: Option<String>,
116
117    /// A base64-encoded string representation of the generated image.
118    #[serde(skip_serializing_if = "Option::is_none")]
119    pub b64_json: Option<String>,
120}