xai-openapi 0.1.1

Rust types for the xAI API (Grok models)
Documentation
//! Image generation API types for `/v1/images/generations` and `/v1/images/edits` endpoints.

use serde::{Deserialize, Serialize};

use crate::prelude::*;

use crate::common::ImageUrl;

/// Quality level for image generation.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ImageQuality {
    /// Low quality.
    Low,
    /// Medium quality.
    #[default]
    Medium,
    /// High quality.
    High,
}

/// Request to generate image for `/v1/images/generations` endpoint.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct GenerateImageRequest {
    /// Prompt for image generation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prompt: Option<String>,

    /// Model to be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,

    /// Number of images to be generated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub n: Option<i32>,

    /// Quality of the output image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quality: Option<ImageQuality>,

    /// Response format to return the image in. Can be `url` or `b64_json`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub response_format: Option<String>,

    /// (Not supported) Size of the image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<String>,

    /// (Not supported) Style of the image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<String>,

    /// A unique identifier representing your end-user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<String>,
}

/// Request for editing image.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct EditImageRequest {
    /// Prompt for image editing.
    pub prompt: String,

    /// Input image to perform edit on.
    pub image: ImageUrl,

    /// Mask image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mask: Option<ImageUrl>,

    /// Model to be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,

    /// Number of image edits to be generated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub n: Option<i32>,

    /// Quality of the output image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quality: Option<ImageQuality>,

    /// Response format to return the image in.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub response_format: Option<String>,

    /// (Not supported) Size of the image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<String>,

    /// (Not supported) Style of the image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style: Option<String>,

    /// A unique identifier representing your end-user.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<String>,
}

/// Image generation response for `/v1/images/generations` endpoint.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct GeneratedImageResponse {
    /// A list of generated image objects.
    pub data: Vec<GeneratedImage>,
}

/// Generated image.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct GeneratedImage {
    /// The revised prompt generated by a chat model from the original prompt.
    pub revised_prompt: String,

    /// A url to the generated image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,

    /// A base64-encoded string representation of the generated image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub b64_json: Option<String>,
}