Skip to main content

langfuse_client_base/models/
observation_v2.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
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/// 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.
15#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
16pub struct ObservationV2 {
17    /// The unique identifier of the observation
18    #[serde(rename = "id")]
19    pub id: String,
20    /// The trace ID associated with the observation
21    #[serde(
22        rename = "traceId",
23        default,
24        with = "::serde_with::rust::double_option",
25        skip_serializing_if = "Option::is_none"
26    )]
27    pub trace_id: Option<Option<String>>,
28    /// The start time of the observation
29    #[serde(rename = "startTime")]
30    pub start_time: chrono::DateTime<chrono::FixedOffset>,
31    /// The end time of the observation
32    #[serde(
33        rename = "endTime",
34        default,
35        with = "::serde_with::rust::double_option",
36        skip_serializing_if = "Option::is_none"
37    )]
38    pub end_time: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
39    /// The project ID this observation belongs to
40    #[serde(rename = "projectId")]
41    pub project_id: String,
42    /// The parent observation ID
43    #[serde(
44        rename = "parentObservationId",
45        default,
46        with = "::serde_with::rust::double_option",
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub parent_observation_id: Option<Option<String>>,
50    /// The type of the observation (e.g. GENERATION, SPAN, EVENT)
51    #[serde(rename = "type")]
52    pub r#type: String,
53    /// The name of the observation
54    #[serde(
55        rename = "name",
56        default,
57        with = "::serde_with::rust::double_option",
58        skip_serializing_if = "Option::is_none"
59    )]
60    pub name: Option<Option<String>>,
61    #[serde(rename = "level", skip_serializing_if = "Option::is_none")]
62    pub level: Option<models::ObservationLevel>,
63    /// The status message of the observation
64    #[serde(
65        rename = "statusMessage",
66        default,
67        with = "::serde_with::rust::double_option",
68        skip_serializing_if = "Option::is_none"
69    )]
70    pub status_message: Option<Option<String>>,
71    /// The version of the observation
72    #[serde(
73        rename = "version",
74        default,
75        with = "::serde_with::rust::double_option",
76        skip_serializing_if = "Option::is_none"
77    )]
78    pub version: Option<Option<String>>,
79    /// The environment from which this observation originated
80    #[serde(
81        rename = "environment",
82        default,
83        with = "::serde_with::rust::double_option",
84        skip_serializing_if = "Option::is_none"
85    )]
86    pub environment: Option<Option<String>>,
87    /// Whether the observation is bookmarked
88    #[serde(
89        rename = "bookmarked",
90        default,
91        with = "::serde_with::rust::double_option",
92        skip_serializing_if = "Option::is_none"
93    )]
94    pub bookmarked: Option<Option<bool>>,
95    /// Whether the observation is public
96    #[serde(
97        rename = "public",
98        default,
99        with = "::serde_with::rust::double_option",
100        skip_serializing_if = "Option::is_none"
101    )]
102    pub public: Option<Option<bool>>,
103    /// The user ID associated with the observation
104    #[serde(
105        rename = "userId",
106        default,
107        with = "::serde_with::rust::double_option",
108        skip_serializing_if = "Option::is_none"
109    )]
110    pub user_id: Option<Option<String>>,
111    /// The session ID associated with the observation
112    #[serde(
113        rename = "sessionId",
114        default,
115        with = "::serde_with::rust::double_option",
116        skip_serializing_if = "Option::is_none"
117    )]
118    pub session_id: Option<Option<String>>,
119    /// The completion start time of the observation
120    #[serde(
121        rename = "completionStartTime",
122        default,
123        with = "::serde_with::rust::double_option",
124        skip_serializing_if = "Option::is_none"
125    )]
126    pub completion_start_time: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
127    /// The creation timestamp of the observation
128    #[serde(
129        rename = "createdAt",
130        default,
131        with = "::serde_with::rust::double_option",
132        skip_serializing_if = "Option::is_none"
133    )]
134    pub created_at: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
135    /// The last update timestamp of the observation
136    #[serde(
137        rename = "updatedAt",
138        default,
139        with = "::serde_with::rust::double_option",
140        skip_serializing_if = "Option::is_none"
141    )]
142    pub updated_at: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
143    /// The input data of the observation
144    #[serde(
145        rename = "input",
146        default,
147        with = "::serde_with::rust::double_option",
148        skip_serializing_if = "Option::is_none"
149    )]
150    pub input: Option<Option<serde_json::Value>>,
151    /// The output data of the observation
152    #[serde(
153        rename = "output",
154        default,
155        with = "::serde_with::rust::double_option",
156        skip_serializing_if = "Option::is_none"
157    )]
158    pub output: Option<Option<serde_json::Value>>,
159    /// Additional metadata of the observation
160    #[serde(
161        rename = "metadata",
162        default,
163        with = "::serde_with::rust::double_option",
164        skip_serializing_if = "Option::is_none"
165    )]
166    pub metadata: Option<Option<serde_json::Value>>,
167    /// The model name as provided by the user
168    #[serde(
169        rename = "providedModelName",
170        default,
171        with = "::serde_with::rust::double_option",
172        skip_serializing_if = "Option::is_none"
173    )]
174    pub provided_model_name: Option<Option<String>>,
175    /// The internal model ID matched by Langfuse
176    #[serde(
177        rename = "internalModelId",
178        default,
179        with = "::serde_with::rust::double_option",
180        skip_serializing_if = "Option::is_none"
181    )]
182    pub internal_model_id: Option<Option<String>>,
183    /// The parameters of the model used for the observation
184    #[serde(
185        rename = "modelParameters",
186        default,
187        with = "::serde_with::rust::double_option",
188        skip_serializing_if = "Option::is_none"
189    )]
190    pub model_parameters: Option<Option<serde_json::Value>>,
191    /// The usage details of the observation. Key is the usage metric name, value is the number of units consumed.
192    #[serde(
193        rename = "usageDetails",
194        default,
195        with = "::serde_with::rust::double_option",
196        skip_serializing_if = "Option::is_none"
197    )]
198    pub usage_details: Option<Option<std::collections::HashMap<String, i32>>>,
199    /// The cost details of the observation. Key is the cost metric name, value is the cost in USD.
200    #[serde(
201        rename = "costDetails",
202        default,
203        with = "::serde_with::rust::double_option",
204        skip_serializing_if = "Option::is_none"
205    )]
206    pub cost_details: Option<Option<std::collections::HashMap<String, f64>>>,
207    /// The total cost of the observation in USD
208    #[serde(
209        rename = "totalCost",
210        default,
211        with = "::serde_with::rust::double_option",
212        skip_serializing_if = "Option::is_none"
213    )]
214    pub total_cost: Option<Option<f64>>,
215    /// The name of the pricing tier applied to this observation's usage costs
216    #[serde(
217        rename = "usagePricingTierName",
218        default,
219        with = "::serde_with::rust::double_option",
220        skip_serializing_if = "Option::is_none"
221    )]
222    pub usage_pricing_tier_name: Option<Option<String>>,
223    /// The prompt ID associated with the observation
224    #[serde(
225        rename = "promptId",
226        default,
227        with = "::serde_with::rust::double_option",
228        skip_serializing_if = "Option::is_none"
229    )]
230    pub prompt_id: Option<Option<String>>,
231    /// The prompt name associated with the observation
232    #[serde(
233        rename = "promptName",
234        default,
235        with = "::serde_with::rust::double_option",
236        skip_serializing_if = "Option::is_none"
237    )]
238    pub prompt_name: Option<Option<String>>,
239    /// The prompt version associated with the observation
240    #[serde(
241        rename = "promptVersion",
242        default,
243        with = "::serde_with::rust::double_option",
244        skip_serializing_if = "Option::is_none"
245    )]
246    pub prompt_version: Option<Option<i32>>,
247    /// The latency in seconds
248    #[serde(
249        rename = "latency",
250        default,
251        with = "::serde_with::rust::double_option",
252        skip_serializing_if = "Option::is_none"
253    )]
254    pub latency: Option<Option<f64>>,
255    /// The time to first token in seconds
256    #[serde(
257        rename = "timeToFirstToken",
258        default,
259        with = "::serde_with::rust::double_option",
260        skip_serializing_if = "Option::is_none"
261    )]
262    pub time_to_first_token: Option<Option<f64>>,
263    /// The matched model ID
264    #[serde(
265        rename = "modelId",
266        default,
267        with = "::serde_with::rust::double_option",
268        skip_serializing_if = "Option::is_none"
269    )]
270    pub model_id: Option<Option<String>>,
271    /// The name of the parent trace
272    #[serde(
273        rename = "traceName",
274        default,
275        with = "::serde_with::rust::double_option",
276        skip_serializing_if = "Option::is_none"
277    )]
278    pub trace_name: Option<Option<String>>,
279    /// Tags from the parent trace (denormalized onto the observation)
280    #[serde(
281        rename = "tags",
282        default,
283        with = "::serde_with::rust::double_option",
284        skip_serializing_if = "Option::is_none"
285    )]
286    pub tags: Option<Option<Vec<String>>>,
287    /// The release version of the parent trace
288    #[serde(
289        rename = "release",
290        default,
291        with = "::serde_with::rust::double_option",
292        skip_serializing_if = "Option::is_none"
293    )]
294    pub release: Option<Option<String>>,
295}
296
297impl ObservationV2 {
298    /// 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.
299    pub fn new(
300        id: String,
301        start_time: chrono::DateTime<chrono::FixedOffset>,
302        project_id: String,
303        r#type: String,
304    ) -> ObservationV2 {
305        ObservationV2 {
306            id,
307            trace_id: None,
308            start_time,
309            end_time: None,
310            project_id,
311            parent_observation_id: None,
312            r#type,
313            name: None,
314            level: None,
315            status_message: None,
316            version: None,
317            environment: None,
318            bookmarked: None,
319            public: None,
320            user_id: None,
321            session_id: None,
322            completion_start_time: None,
323            created_at: None,
324            updated_at: None,
325            input: None,
326            output: None,
327            metadata: None,
328            provided_model_name: None,
329            internal_model_id: None,
330            model_parameters: None,
331            usage_details: None,
332            cost_details: None,
333            total_cost: None,
334            usage_pricing_tier_name: None,
335            prompt_id: None,
336            prompt_name: None,
337            prompt_version: None,
338            latency: None,
339            time_to_first_token: None,
340            model_id: None,
341            trace_name: None,
342            tags: None,
343            release: None,
344        }
345    }
346}