openai-client-base 0.12.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// UsageCompletionsResult : The aggregated completions usage details of the specific time bucket.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct UsageCompletionsResult {
    #[serde(rename = "object")]
    pub object: Object,
    /// The aggregated number of text input tokens used, including cached tokens. For customers subscribe to scale tier, this includes scale tier tokens.
    #[serde(rename = "input_tokens")]
    pub input_tokens: i32,
    /// The aggregated number of text input tokens that has been cached from previous requests. For customers subscribe to scale tier, this includes scale tier tokens.
    #[serde(
        rename = "input_cached_tokens",
        skip_serializing_if = "Option::is_none"
    )]
    pub input_cached_tokens: Option<i32>,
    /// The aggregated number of text output tokens used. For customers subscribe to scale tier, this includes scale tier tokens.
    #[serde(rename = "output_tokens")]
    pub output_tokens: i32,
    /// The aggregated number of audio input tokens used, including cached tokens.
    #[serde(rename = "input_audio_tokens", skip_serializing_if = "Option::is_none")]
    pub input_audio_tokens: Option<i32>,
    /// The aggregated number of audio output tokens used.
    #[serde(
        rename = "output_audio_tokens",
        skip_serializing_if = "Option::is_none"
    )]
    pub output_audio_tokens: Option<i32>,
    /// The count of requests made to the model.
    #[serde(rename = "num_model_requests")]
    pub num_model_requests: i32,
    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
    #[serde(
        rename = "project_id",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub project_id: Option<Option<String>>,
    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
    #[serde(
        rename = "user_id",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub user_id: Option<Option<String>>,
    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
    #[serde(
        rename = "api_key_id",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub api_key_id: Option<Option<String>>,
    /// ID of the model to use
    #[serde(rename = "model", skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    /// When `group_by=batch`, this field tells whether the grouped usage result is batch or not.
    #[serde(
        rename = "batch",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub batch: Option<Option<bool>>,
    /// When `group_by=service_tier`, this field provides the service tier of the grouped usage result.
    #[serde(
        rename = "service_tier",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub service_tier: Option<Option<String>>,
}

impl UsageCompletionsResult {
    /// The aggregated completions usage details of the specific time bucket.
    pub fn new(
        object: Object,
        input_tokens: i32,
        output_tokens: i32,
        num_model_requests: i32,
    ) -> UsageCompletionsResult {
        UsageCompletionsResult {
            object,
            input_tokens,
            input_cached_tokens: None,
            output_tokens,
            input_audio_tokens: None,
            output_audio_tokens: None,
            num_model_requests,
            project_id: None,
            user_id: None,
            api_key_id: None,
            model: None,
            batch: None,
            service_tier: None,
        }
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Object {
    #[serde(rename = "organization.usage.completions.result")]
    OrganizationUsageCompletionsResult,
}

impl Default for Object {
    fn default() -> Object {
        Self::OrganizationUsageCompletionsResult
    }
}

impl std::fmt::Display for UsageCompletionsResult {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}