langfuse-client-base 0.12.0

Auto-generated Langfuse API client from OpenAPI specification
Documentation
/*
 * langfuse
 *
 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml
 *
 * The version of the OpenAPI document:
 *
 * Generated by: https://openapi-generator.tech
 */

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

/// ObservationV2 : An observation from the v2 API with field-group-based selection. Core fields are always present. Other fields are included only when their field group is requested.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ObservationV2 {
    /// The unique identifier of the observation
    #[serde(rename = "id")]
    pub id: String,
    /// The trace ID associated with the observation
    #[serde(
        rename = "traceId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub trace_id: Option<Option<String>>,
    /// The start time of the observation
    #[serde(rename = "startTime")]
    pub start_time: String,
    /// The end time of the observation
    #[serde(
        rename = "endTime",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub end_time: Option<Option<String>>,
    /// The project ID this observation belongs to
    #[serde(rename = "projectId")]
    pub project_id: String,
    /// The parent observation ID
    #[serde(
        rename = "parentObservationId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub parent_observation_id: Option<Option<String>>,
    /// The type of the observation (e.g. GENERATION, SPAN, EVENT)
    #[serde(rename = "type")]
    pub r#type: String,
    /// The name of the observation
    #[serde(
        rename = "name",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub name: Option<Option<String>>,
    #[serde(rename = "level", skip_serializing_if = "Option::is_none")]
    pub level: Option<models::ObservationLevel>,
    /// The status message of the observation
    #[serde(
        rename = "statusMessage",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub status_message: Option<Option<String>>,
    /// The version of the observation
    #[serde(
        rename = "version",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub version: Option<Option<String>>,
    /// The environment from which this observation originated
    #[serde(
        rename = "environment",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub environment: Option<Option<String>>,
    /// Whether the observation is bookmarked
    #[serde(
        rename = "bookmarked",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub bookmarked: Option<Option<bool>>,
    /// Whether the observation is public
    #[serde(
        rename = "public",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub public: Option<Option<bool>>,
    /// The user ID associated with the observation
    #[serde(
        rename = "userId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub user_id: Option<Option<String>>,
    /// The session ID associated with the observation
    #[serde(
        rename = "sessionId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub session_id: Option<Option<String>>,
    /// The completion start time of the observation
    #[serde(
        rename = "completionStartTime",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub completion_start_time: Option<Option<String>>,
    /// The creation timestamp of the observation
    #[serde(
        rename = "createdAt",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub created_at: Option<Option<String>>,
    /// The last update timestamp of the observation
    #[serde(
        rename = "updatedAt",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub updated_at: Option<Option<String>>,
    /// The input data of the observation
    #[serde(
        rename = "input",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub input: Option<Option<serde_json::Value>>,
    /// The output data of the observation
    #[serde(
        rename = "output",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub output: Option<Option<serde_json::Value>>,
    /// Additional metadata of the observation
    #[serde(
        rename = "metadata",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub metadata: Option<Option<serde_json::Value>>,
    /// The model name as provided by the user
    #[serde(
        rename = "providedModelName",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub provided_model_name: Option<Option<String>>,
    /// The internal model ID matched by Langfuse
    #[serde(
        rename = "internalModelId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub internal_model_id: Option<Option<String>>,
    /// The parameters of the model used for the observation
    #[serde(
        rename = "modelParameters",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub model_parameters: Option<Option<serde_json::Value>>,
    /// The usage details of the observation. Key is the usage metric name, value is the number of units consumed.
    #[serde(
        rename = "usageDetails",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub usage_details: Option<Option<std::collections::HashMap<String, i32>>>,
    /// The cost details of the observation. Key is the cost metric name, value is the cost in USD.
    #[serde(
        rename = "costDetails",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub cost_details: Option<Option<std::collections::HashMap<String, f64>>>,
    /// The total cost of the observation in USD
    #[serde(
        rename = "totalCost",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub total_cost: Option<Option<f64>>,
    /// The prompt ID associated with the observation
    #[serde(
        rename = "promptId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub prompt_id: Option<Option<String>>,
    /// The prompt name associated with the observation
    #[serde(
        rename = "promptName",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub prompt_name: Option<Option<String>>,
    /// The prompt version associated with the observation
    #[serde(
        rename = "promptVersion",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub prompt_version: Option<Option<i32>>,
    /// The latency in seconds
    #[serde(
        rename = "latency",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub latency: Option<Option<f64>>,
    /// The time to first token in seconds
    #[serde(
        rename = "timeToFirstToken",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub time_to_first_token: Option<Option<f64>>,
    /// The matched model ID
    #[serde(
        rename = "modelId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub model_id: Option<Option<String>>,
}

impl ObservationV2 {
    /// An observation from the v2 API with field-group-based selection. Core fields are always present. Other fields are included only when their field group is requested.
    pub fn new(
        id: String,
        start_time: String,
        project_id: String,
        r#type: String,
    ) -> ObservationV2 {
        ObservationV2 {
            id,
            trace_id: None,
            start_time,
            end_time: None,
            project_id,
            parent_observation_id: None,
            r#type,
            name: None,
            level: None,
            status_message: None,
            version: None,
            environment: None,
            bookmarked: None,
            public: None,
            user_id: None,
            session_id: None,
            completion_start_time: None,
            created_at: None,
            updated_at: None,
            input: None,
            output: None,
            metadata: None,
            provided_model_name: None,
            internal_model_id: None,
            model_parameters: None,
            usage_details: None,
            cost_details: None,
            total_cost: None,
            prompt_id: None,
            prompt_name: None,
            prompt_version: None,
            latency: None,
            time_to_first_token: None,
            model_id: None,
        }
    }
}