Skip to main content

langfuse_client_base/apis/
scores_api.rs

1#![allow(deprecated)]
2/*
3 * server
4 *
5 * ## Real-time data  The only real-time path to get tracing data is to ingest via OpenTelemetry (`POST /api/public/otel/v1/traces`) and retrieve via Observations API v2 (`GET /api/public/v2/observations`) and Metrics API v2 (`GET /api/public/v2/metrics`). Other public API write and read endpoints can delay data by about 10 minutes. Direct OpenTelemetry exporters must send the `x-langfuse-ingestion-version: 4` header; current Python and JS SDKs already do. See the [Public API docs](https://langfuse.com/docs/api-and-data-platform/features/public-api) and [real-time ingestion](https://langfuse.com/integrations/native/opentelemetry.md#real-time-ingestion).  ## 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 - Self-hosted deployments: interactive API reference at `/api/docs` and OpenAPI spec at `/api/openapi.yaml`
6 *
7 * The version of the OpenAPI document:
8 *
9 * Generated by: https://openapi-generator.tech
10 */
11
12use super::{configuration, ContentType, Error};
13use crate::{apis::ResponseContent, models};
14use serde::{de::Error as _, Deserialize, Serialize};
15use timvw_rust_runtime;
16
17/// struct for typed errors of method [`scores_create`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum ScoresCreateError {
21    Status400(serde_json::Value),
22    Status401(serde_json::Value),
23    Status403(serde_json::Value),
24    Status404(serde_json::Value),
25    Status405(serde_json::Value),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`scores_get_by_id`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum ScoresGetByIdError {
33    Status400(serde_json::Value),
34    Status401(serde_json::Value),
35    Status403(serde_json::Value),
36    Status404(serde_json::Value),
37    Status405(serde_json::Value),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`scores_get_many`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum ScoresGetManyError {
45    Status400(serde_json::Value),
46    Status401(serde_json::Value),
47    Status403(serde_json::Value),
48    Status404(serde_json::Value),
49    Status405(serde_json::Value),
50    UnknownValue(serde_json::Value),
51}
52
53/// Create scores asynchronously from a list of scores. Returns 202 if all scores are accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; the endpoint returns 202 or 207.
54#[bon::builder]
55pub async fn scores_create(
56    configuration: &configuration::Configuration,
57    create_scores_request: &models::CreateScoresRequest,
58    options: Option<&timvw_rust_runtime::RequestOptions>,
59) -> Result<models::CreateScoresResponse, Error<ScoresCreateError>> {
60    // add a prefix to parameters to efficiently prevent name collisions
61    let p_body_create_scores_request = create_scores_request;
62
63    let uri_str = format!("{}/api/public/scores", configuration.base_path);
64    let mut req_builder = configuration
65        .client
66        .request(timvw_rust_runtime::Method::POST, &uri_str);
67
68    if let Some(ref user_agent) = configuration.user_agent {
69        req_builder =
70            req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref auth_conf) = configuration.basic_auth {
73        req_builder = req_builder.basic_auth(
74            &auth_conf.0,
75            auth_conf
76                .1
77                .as_ref()
78                .map(timvw_rust_runtime::ExposeSecret::expose_secret),
79        );
80    };
81    req_builder = req_builder.json(p_body_create_scores_request);
82
83    // last, so its headers replace the generated ones; its base URL replaces configuration.base_path
84    if let Some(options) = options {
85        req_builder = req_builder.base(&configuration.base_path).options(options);
86    }
87    let req = req_builder.build()?;
88    let resp = configuration.client.execute(req).await?;
89
90    let status = resp.status();
91    let content_type = resp
92        .headers()
93        .get("content-type")
94        .and_then(|v| v.to_str().ok())
95        .unwrap_or("application/octet-stream");
96    let content_type = super::ContentType::from(content_type);
97
98    if !status.is_client_error() && !status.is_server_error() {
99        let content = resp.text().await?;
100        match content_type {
101            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateScoresResponse`"))),
103            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateScoresResponse`")))),
104        }
105    } else {
106        let headers = resp.headers().clone();
107        let content = resp.text().await?;
108        let entity: Option<ScoresCreateError> = match status.as_u16() {
109            400 => serde_json::from_str(&content)
110                .ok()
111                .map(ScoresCreateError::Status400),
112            401 => serde_json::from_str(&content)
113                .ok()
114                .map(ScoresCreateError::Status401),
115            403 => serde_json::from_str(&content)
116                .ok()
117                .map(ScoresCreateError::Status403),
118            404 => serde_json::from_str(&content)
119                .ok()
120                .map(ScoresCreateError::Status404),
121            405 => serde_json::from_str(&content)
122                .ok()
123                .map(ScoresCreateError::Status405),
124            _ => None,
125        }
126        .or_else(|| {
127            serde_json::from_str(&content)
128                .ok()
129                .map(ScoresCreateError::UnknownValue)
130        });
131        Err(Error::ResponseError(Box::new(ResponseContent {
132            status,
133            content,
134            entity,
135            headers,
136        })))
137    }
138}
139
140/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. Use `GET /api/public/v3/scores` with the `id` filter instead. Self-hosted deployments are unaffected by this date; the endpoint becomes unavailable when they upgrade to Langfuse v4. See the [Langfuse v3 to v4 upgrade guide](https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v3-to-v4).  Get a score (supports both trace and session scores)
141#[deprecated]
142#[bon::builder]
143pub async fn scores_get_by_id(
144    configuration: &configuration::Configuration,
145    score_id: &str,
146    options: Option<&timvw_rust_runtime::RequestOptions>,
147) -> Result<models::Score, Error<ScoresGetByIdError>> {
148    // add a prefix to parameters to efficiently prevent name collisions
149    let p_path_score_id = score_id;
150
151    let uri_str = format!(
152        "{}/api/public/v2/scores/{scoreId}",
153        configuration.base_path,
154        scoreId = crate::apis::urlencode(p_path_score_id)
155    );
156    let mut req_builder = configuration
157        .client
158        .request(timvw_rust_runtime::Method::GET, &uri_str);
159
160    if let Some(ref user_agent) = configuration.user_agent {
161        req_builder =
162            req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
163    }
164    if let Some(ref auth_conf) = configuration.basic_auth {
165        req_builder = req_builder.basic_auth(
166            &auth_conf.0,
167            auth_conf
168                .1
169                .as_ref()
170                .map(timvw_rust_runtime::ExposeSecret::expose_secret),
171        );
172    };
173
174    // last, so its headers replace the generated ones; its base URL replaces configuration.base_path
175    if let Some(options) = options {
176        req_builder = req_builder.base(&configuration.base_path).options(options);
177    }
178    let req = req_builder.build()?;
179    let resp = configuration.client.execute(req).await?;
180
181    let status = resp.status();
182    let content_type = resp
183        .headers()
184        .get("content-type")
185        .and_then(|v| v.to_str().ok())
186        .unwrap_or("application/octet-stream");
187    let content_type = super::ContentType::from(content_type);
188
189    if !status.is_client_error() && !status.is_server_error() {
190        let content = resp.text().await?;
191        match content_type {
192            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
193            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Score`"))),
194            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Score`")))),
195        }
196    } else {
197        let headers = resp.headers().clone();
198        let content = resp.text().await?;
199        let entity: Option<ScoresGetByIdError> = match status.as_u16() {
200            400 => serde_json::from_str(&content)
201                .ok()
202                .map(ScoresGetByIdError::Status400),
203            401 => serde_json::from_str(&content)
204                .ok()
205                .map(ScoresGetByIdError::Status401),
206            403 => serde_json::from_str(&content)
207                .ok()
208                .map(ScoresGetByIdError::Status403),
209            404 => serde_json::from_str(&content)
210                .ok()
211                .map(ScoresGetByIdError::Status404),
212            405 => serde_json::from_str(&content)
213                .ok()
214                .map(ScoresGetByIdError::Status405),
215            _ => None,
216        }
217        .or_else(|| {
218            serde_json::from_str(&content)
219                .ok()
220                .map(ScoresGetByIdError::UnknownValue)
221        });
222        Err(Error::ResponseError(Box::new(ResponseContent {
223            status,
224            content,
225            entity,
226            headers,
227        })))
228    }
229}
230
231/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. Use `GET /api/public/v3/scores` instead. Self-hosted deployments are unaffected by this date; the endpoint becomes unavailable when they upgrade to Langfuse v4. See the [Langfuse v3 to v4 upgrade guide](https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v3-to-v4).  Get a list of scores (supports both trace and session scores)
232#[deprecated]
233#[bon::builder]
234pub async fn scores_get_many(
235    configuration: &configuration::Configuration,
236    page: Option<i64>,
237    limit: Option<i64>,
238    user_id: Option<&str>,
239    name: Option<&str>,
240    from_timestamp: Option<jiff::Timestamp>,
241    to_timestamp: Option<jiff::Timestamp>,
242    environment: Option<Vec<String>>,
243    source: Option<models::ScoreSource>,
244    operator: Option<&str>,
245    value: Option<f64>,
246    score_ids: Option<&str>,
247    config_id: Option<&str>,
248    session_id: Option<&str>,
249    dataset_run_id: Option<&str>,
250    trace_id: Option<&str>,
251    observation_id: Option<&str>,
252    queue_id: Option<&str>,
253    data_type: Option<models::ScoreDataType>,
254    trace_tags: Option<Vec<String>>,
255    fields: Option<&str>,
256    filter: Option<&str>,
257    options: Option<&timvw_rust_runtime::RequestOptions>,
258) -> Result<models::GetScoresResponse, Error<ScoresGetManyError>> {
259    // add a prefix to parameters to efficiently prevent name collisions
260    let p_query_page = page;
261    let p_query_limit = limit;
262    let p_query_user_id = user_id;
263    let p_query_name = name;
264    let p_query_from_timestamp = from_timestamp;
265    let p_query_to_timestamp = to_timestamp;
266    let p_query_environment = environment;
267    let p_query_source = source;
268    let p_query_operator = operator;
269    let p_query_value = value;
270    let p_query_score_ids = score_ids;
271    let p_query_config_id = config_id;
272    let p_query_session_id = session_id;
273    let p_query_dataset_run_id = dataset_run_id;
274    let p_query_trace_id = trace_id;
275    let p_query_observation_id = observation_id;
276    let p_query_queue_id = queue_id;
277    let p_query_data_type = data_type;
278    let p_query_trace_tags = trace_tags;
279    let p_query_fields = fields;
280    let p_query_filter = filter;
281
282    let uri_str = format!("{}/api/public/v2/scores", configuration.base_path);
283    let mut req_builder = configuration
284        .client
285        .request(timvw_rust_runtime::Method::GET, &uri_str);
286
287    if let Some(ref param_value) = p_query_page {
288        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
289    }
290    if let Some(ref param_value) = p_query_limit {
291        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
292    }
293    if let Some(ref param_value) = p_query_user_id {
294        req_builder = req_builder.query(&[("userId", &param_value.to_string())]);
295    }
296    if let Some(ref param_value) = p_query_name {
297        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
298    }
299    if let Some(ref param_value) = p_query_from_timestamp {
300        req_builder = req_builder.query(&[("fromTimestamp", &param_value.to_string())]);
301    }
302    if let Some(ref param_value) = p_query_to_timestamp {
303        req_builder = req_builder.query(&[("toTimestamp", &param_value.to_string())]);
304    }
305    if let Some(ref param_value) = p_query_environment {
306        let items: Vec<String> = param_value.iter().map(|p| p.to_string()).collect();
307        for item in items {
308            req_builder = req_builder.query(&[("environment", item)]);
309        }
310    }
311    if let Some(ref param_value) = p_query_source {
312        req_builder = req_builder.query(&[("source", &param_value.to_string())]);
313    }
314    if let Some(ref param_value) = p_query_operator {
315        req_builder = req_builder.query(&[("operator", &param_value.to_string())]);
316    }
317    if let Some(ref param_value) = p_query_value {
318        req_builder = req_builder.query(&[("value", &param_value.to_string())]);
319    }
320    if let Some(ref param_value) = p_query_score_ids {
321        req_builder = req_builder.query(&[("scoreIds", &param_value.to_string())]);
322    }
323    if let Some(ref param_value) = p_query_config_id {
324        req_builder = req_builder.query(&[("configId", &param_value.to_string())]);
325    }
326    if let Some(ref param_value) = p_query_session_id {
327        req_builder = req_builder.query(&[("sessionId", &param_value.to_string())]);
328    }
329    if let Some(ref param_value) = p_query_dataset_run_id {
330        req_builder = req_builder.query(&[("datasetRunId", &param_value.to_string())]);
331    }
332    if let Some(ref param_value) = p_query_trace_id {
333        req_builder = req_builder.query(&[("traceId", &param_value.to_string())]);
334    }
335    if let Some(ref param_value) = p_query_observation_id {
336        req_builder = req_builder.query(&[("observationId", &param_value.to_string())]);
337    }
338    if let Some(ref param_value) = p_query_queue_id {
339        req_builder = req_builder.query(&[("queueId", &param_value.to_string())]);
340    }
341    if let Some(ref param_value) = p_query_data_type {
342        req_builder = req_builder.query(&[("dataType", &param_value.to_string())]);
343    }
344    if let Some(ref param_value) = p_query_trace_tags {
345        let items: Vec<String> = param_value.iter().map(|p| p.to_string()).collect();
346        for item in items {
347            req_builder = req_builder.query(&[("traceTags", item)]);
348        }
349    }
350    if let Some(ref param_value) = p_query_fields {
351        req_builder = req_builder.query(&[("fields", &param_value.to_string())]);
352    }
353    if let Some(ref param_value) = p_query_filter {
354        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
355    }
356    if let Some(ref user_agent) = configuration.user_agent {
357        req_builder =
358            req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
359    }
360    if let Some(ref auth_conf) = configuration.basic_auth {
361        req_builder = req_builder.basic_auth(
362            &auth_conf.0,
363            auth_conf
364                .1
365                .as_ref()
366                .map(timvw_rust_runtime::ExposeSecret::expose_secret),
367        );
368    };
369
370    // last, so its headers replace the generated ones; its base URL replaces configuration.base_path
371    if let Some(options) = options {
372        req_builder = req_builder.base(&configuration.base_path).options(options);
373    }
374    let req = req_builder.build()?;
375    let resp = configuration.client.execute(req).await?;
376
377    let status = resp.status();
378    let content_type = resp
379        .headers()
380        .get("content-type")
381        .and_then(|v| v.to_str().ok())
382        .unwrap_or("application/octet-stream");
383    let content_type = super::ContentType::from(content_type);
384
385    if !status.is_client_error() && !status.is_server_error() {
386        let content = resp.text().await?;
387        match content_type {
388            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
389            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetScoresResponse`"))),
390            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetScoresResponse`")))),
391        }
392    } else {
393        let headers = resp.headers().clone();
394        let content = resp.text().await?;
395        let entity: Option<ScoresGetManyError> = match status.as_u16() {
396            400 => serde_json::from_str(&content)
397                .ok()
398                .map(ScoresGetManyError::Status400),
399            401 => serde_json::from_str(&content)
400                .ok()
401                .map(ScoresGetManyError::Status401),
402            403 => serde_json::from_str(&content)
403                .ok()
404                .map(ScoresGetManyError::Status403),
405            404 => serde_json::from_str(&content)
406                .ok()
407                .map(ScoresGetManyError::Status404),
408            405 => serde_json::from_str(&content)
409                .ok()
410                .map(ScoresGetManyError::Status405),
411            _ => None,
412        }
413        .or_else(|| {
414            serde_json::from_str(&content)
415                .ok()
416                .map(ScoresGetManyError::UnknownValue)
417        });
418        Err(Error::ResponseError(Box::new(ResponseContent {
419            status,
420            content,
421            entity,
422            headers,
423        })))
424    }
425}