Skip to main content

langfuse_client_base/apis/
sessions_api.rs

1/*
2 * server
3 *
4 * ## 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`
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`sessions_get`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum SessionsGetError {
20    Status400(serde_json::Value),
21    Status401(serde_json::Value),
22    Status403(serde_json::Value),
23    Status404(serde_json::Value),
24    Status405(serde_json::Value),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`sessions_list`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum SessionsListError {
32    Status400(serde_json::Value),
33    Status401(serde_json::Value),
34    Status403(serde_json::Value),
35    Status404(serde_json::Value),
36    Status405(serde_json::Value),
37    UnknownValue(serde_json::Value),
38}
39
40/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. In Langfuse v4, read session data via `GET /api/public/v2/observations?filter=<urlencoded sessionId filter>&fromStartTime=<from>&toStartTime=<to>`. 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 session.  Please note that `traces` on this endpoint are not paginated. For large sessions or new data extraction workflows, use the v2 observations endpoint with a URL-encoded `sessionId` filter and a bounded time range: `GET /api/public/v2/observations?filter=<sessionId filter>&fromStartTime=<from>&toStartTime=<to>`.
41#[deprecated]
42#[bon::builder]
43pub async fn sessions_get(
44    configuration: &configuration::Configuration,
45    session_id: &str,
46) -> Result<models::SessionWithTraces, Error<SessionsGetError>> {
47    // add a prefix to parameters to efficiently prevent name collisions
48    let p_path_session_id = session_id;
49
50    let uri_str = format!(
51        "{}/api/public/sessions/{sessionId}",
52        configuration.base_path,
53        sessionId = crate::apis::urlencode(p_path_session_id)
54    );
55    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
56
57    if let Some(ref user_agent) = configuration.user_agent {
58        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
59    }
60    if let Some(ref auth_conf) = configuration.basic_auth {
61        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
62    };
63
64    let req = req_builder.build()?;
65    let resp = configuration.client.execute(req).await?;
66
67    let status = resp.status();
68    let content_type = resp
69        .headers()
70        .get("content-type")
71        .and_then(|v| v.to_str().ok())
72        .unwrap_or("application/octet-stream");
73    let content_type = super::ContentType::from(content_type);
74
75    if !status.is_client_error() && !status.is_server_error() {
76        let content = resp.text().await?;
77        match content_type {
78            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SessionWithTraces`"))),
80            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SessionWithTraces`")))),
81        }
82    } else {
83        let content = resp.text().await?;
84        let entity: Option<SessionsGetError> = serde_json::from_str(&content).ok();
85        Err(Error::ResponseError(ResponseContent {
86            status,
87            content,
88            entity,
89        }))
90    }
91}
92
93/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. In Langfuse v4, read session data via `GET /api/public/v2/observations?filter=<urlencoded sessionId filter>&fromStartTime=<from>&toStartTime=<to>`. 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 sessions.  This legacy endpoint is not recommended for new data extraction workflows. Use the v2 observations endpoint with a bounded time range and group rows by `sessionId` instead: `GET /api/public/v2/observations?fromStartTime=<from>&toStartTime=<to>`.
94#[deprecated]
95#[bon::builder]
96pub async fn sessions_list(
97    configuration: &configuration::Configuration,
98    page: Option<i32>,
99    limit: Option<i32>,
100    from_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
101    to_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
102    environment: Option<Vec<String>>,
103) -> Result<models::PaginatedSessions, Error<SessionsListError>> {
104    // add a prefix to parameters to efficiently prevent name collisions
105    let p_query_page = page;
106    let p_query_limit = limit;
107    let p_query_from_timestamp = from_timestamp;
108    let p_query_to_timestamp = to_timestamp;
109    let p_query_environment = environment;
110
111    let uri_str = format!("{}/api/public/sessions", configuration.base_path);
112    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
113
114    if let Some(ref param_value) = p_query_page {
115        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
116    }
117    if let Some(ref param_value) = p_query_limit {
118        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
119    }
120    if let Some(ref param_value) = p_query_from_timestamp {
121        req_builder = req_builder.query(&[("fromTimestamp", &param_value.to_string())]);
122    }
123    if let Some(ref param_value) = p_query_to_timestamp {
124        req_builder = req_builder.query(&[("toTimestamp", &param_value.to_string())]);
125    }
126    if let Some(ref param_value) = p_query_environment {
127        req_builder = match "multi" {
128            "multi" => req_builder.query(
129                &param_value
130                    .into_iter()
131                    .map(|p| ("environment".to_owned(), p.to_string()))
132                    .collect::<Vec<(std::string::String, std::string::String)>>(),
133            ),
134            _ => req_builder.query(&[(
135                "environment",
136                &param_value
137                    .into_iter()
138                    .map(|p| p.to_string())
139                    .collect::<Vec<String>>()
140                    .join(",")
141                    .to_string(),
142            )]),
143        };
144    }
145    if let Some(ref user_agent) = configuration.user_agent {
146        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147    }
148    if let Some(ref auth_conf) = configuration.basic_auth {
149        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150    };
151
152    let req = req_builder.build()?;
153    let resp = configuration.client.execute(req).await?;
154
155    let status = resp.status();
156    let content_type = resp
157        .headers()
158        .get("content-type")
159        .and_then(|v| v.to_str().ok())
160        .unwrap_or("application/octet-stream");
161    let content_type = super::ContentType::from(content_type);
162
163    if !status.is_client_error() && !status.is_server_error() {
164        let content = resp.text().await?;
165        match content_type {
166            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedSessions`"))),
168            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PaginatedSessions`")))),
169        }
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<SessionsListError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent {
174            status,
175            content,
176            entity,
177        }))
178    }
179}