langfuse_client_base/models/
model.rs

1/*
2 * langfuse
3 *
4 * ## 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 - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14/// Model : Model definition used for transforming usage into USD cost and/or tokenization.  Models can have either simple flat pricing or tiered pricing: - Flat pricing: Single price per usage type (legacy, but still supported) - Tiered pricing: Multiple pricing tiers with conditional matching based on usage patterns  The pricing tiers approach is recommended for models with usage-based pricing variations. When using tiered pricing, the flat price fields (inputPrice, outputPrice, prices) are populated from the default tier for backward compatibility.
15#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
16pub struct Model {
17    #[serde(rename = "id")]
18    pub id: String,
19    /// Name of the model definition. If multiple with the same name exist, they are applied in the following order: (1) custom over built-in, (2) newest according to startTime where model.startTime<observation.startTime
20    #[serde(rename = "modelName")]
21    pub model_name: String,
22    /// Regex pattern which matches this model definition to generation.model. Useful in case of fine-tuned models. If you want to exact match, use `(?i)^modelname$`
23    #[serde(rename = "matchPattern")]
24    pub match_pattern: String,
25    /// Apply only to generations which are newer than this ISO date.
26    #[serde(
27        rename = "startDate",
28        default,
29        with = "::serde_with::rust::double_option",
30        skip_serializing_if = "Option::is_none"
31    )]
32    pub start_date: Option<Option<String>>,
33    #[serde(rename = "unit", skip_serializing_if = "Option::is_none")]
34    pub unit: Option<models::ModelUsageUnit>,
35    /// Deprecated. See 'prices' instead. Price (USD) per input unit
36    #[serde(
37        rename = "inputPrice",
38        default,
39        with = "::serde_with::rust::double_option",
40        skip_serializing_if = "Option::is_none"
41    )]
42    pub input_price: Option<Option<f64>>,
43    /// Deprecated. See 'prices' instead. Price (USD) per output unit
44    #[serde(
45        rename = "outputPrice",
46        default,
47        with = "::serde_with::rust::double_option",
48        skip_serializing_if = "Option::is_none"
49    )]
50    pub output_price: Option<Option<f64>>,
51    /// Deprecated. See 'prices' instead. Price (USD) per total unit. Cannot be set if input or output price is set.
52    #[serde(
53        rename = "totalPrice",
54        default,
55        with = "::serde_with::rust::double_option",
56        skip_serializing_if = "Option::is_none"
57    )]
58    pub total_price: Option<Option<f64>>,
59    /// Optional. Tokenizer to be applied to observations which match to this model. See docs for more details.
60    #[serde(
61        rename = "tokenizerId",
62        default,
63        with = "::serde_with::rust::double_option",
64        skip_serializing_if = "Option::is_none"
65    )]
66    pub tokenizer_id: Option<Option<String>>,
67    /// Optional. Configuration for the selected tokenizer. Needs to be JSON. See docs for more details.
68    #[serde(
69        rename = "tokenizerConfig",
70        default,
71        with = "::serde_with::rust::double_option",
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub tokenizer_config: Option<Option<serde_json::Value>>,
75    #[serde(rename = "isLangfuseManaged")]
76    pub is_langfuse_managed: bool,
77    /// Timestamp when the model was created
78    #[serde(rename = "createdAt")]
79    pub created_at: String,
80    /// Deprecated. Use 'pricingTiers' instead for models with usage-based pricing variations.  This field shows prices by usage type from the default pricing tier. Maintained for backward compatibility. If the model uses tiered pricing, this field will be populated from the default tier's prices.
81    #[serde(rename = "prices")]
82    pub prices: std::collections::HashMap<String, models::ModelPrice>,
83    /// Array of pricing tiers with conditional pricing based on usage thresholds.  Pricing tiers enable accurate cost tracking for models that charge different rates based on usage patterns (e.g., different rates for high-volume usage, large context windows, or cached tokens).  Each model must have exactly one default tier (isDefault=true, priority=0) that serves as a fallback. Additional conditional tiers can be defined with specific matching criteria.  If this array is empty, the model uses legacy flat pricing from the inputPrice/outputPrice/totalPrice fields.
84    #[serde(rename = "pricingTiers")]
85    pub pricing_tiers: Vec<models::PricingTier>,
86}
87
88impl Model {
89    /// Model definition used for transforming usage into USD cost and/or tokenization.  Models can have either simple flat pricing or tiered pricing: - Flat pricing: Single price per usage type (legacy, but still supported) - Tiered pricing: Multiple pricing tiers with conditional matching based on usage patterns  The pricing tiers approach is recommended for models with usage-based pricing variations. When using tiered pricing, the flat price fields (inputPrice, outputPrice, prices) are populated from the default tier for backward compatibility.
90    pub fn new(
91        id: String,
92        model_name: String,
93        match_pattern: String,
94        is_langfuse_managed: bool,
95        created_at: String,
96        prices: std::collections::HashMap<String, models::ModelPrice>,
97        pricing_tiers: Vec<models::PricingTier>,
98    ) -> Model {
99        Model {
100            id,
101            model_name,
102            match_pattern,
103            start_date: None,
104            unit: None,
105            input_price: None,
106            output_price: None,
107            total_price: None,
108            tokenizer_id: None,
109            tokenizer_config: None,
110            is_langfuse_managed,
111            created_at,
112            prices,
113            pricing_tiers,
114        }
115    }
116}