Skip to main content

langfuse_client_base/apis/
feedback_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 [`feedback_submit`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum FeedbackSubmitError {
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    Status409(),
27    UnknownValue(serde_json::Value),
28}
29
30/// Submit explicit user-approved feedback about Langfuse skills, MCP tools, CLI, docs, or public API. Do not include secrets, credentials, customer data, trace payloads, or unrelated use-case details.  Not available in the HIPAA cloud region.
31#[bon::builder]
32pub async fn feedback_submit(
33    configuration: &configuration::Configuration,
34    submit_feedback_request: &models::SubmitFeedbackRequest,
35    options: Option<&timvw_rust_runtime::RequestOptions>,
36) -> Result<models::SubmitFeedbackResponse, Error<FeedbackSubmitError>> {
37    // add a prefix to parameters to efficiently prevent name collisions
38    let p_body_submit_feedback_request = submit_feedback_request;
39
40    let uri_str = format!("{}/api/public/feedback", configuration.base_path);
41    let mut req_builder = configuration
42        .client
43        .request(timvw_rust_runtime::Method::POST, &uri_str);
44
45    if let Some(ref user_agent) = configuration.user_agent {
46        req_builder =
47            req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
48    }
49    if let Some(ref auth_conf) = configuration.basic_auth {
50        req_builder = req_builder.basic_auth(
51            &auth_conf.0,
52            auth_conf
53                .1
54                .as_ref()
55                .map(timvw_rust_runtime::ExposeSecret::expose_secret),
56        );
57    };
58    req_builder = req_builder.json(p_body_submit_feedback_request);
59
60    // last, so its headers replace the generated ones; its base URL replaces configuration.base_path
61    if let Some(options) = options {
62        req_builder = req_builder.base(&configuration.base_path).options(options);
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 => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SubmitFeedbackResponse`"))),
80            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SubmitFeedbackResponse`")))),
81        }
82    } else {
83        let headers = resp.headers().clone();
84        let content = resp.text().await?;
85        let entity: Option<FeedbackSubmitError> = match status.as_u16() {
86            400 => serde_json::from_str(&content)
87                .ok()
88                .map(FeedbackSubmitError::Status400),
89            401 => serde_json::from_str(&content)
90                .ok()
91                .map(FeedbackSubmitError::Status401),
92            403 => serde_json::from_str(&content)
93                .ok()
94                .map(FeedbackSubmitError::Status403),
95            404 => serde_json::from_str(&content)
96                .ok()
97                .map(FeedbackSubmitError::Status404),
98            405 => serde_json::from_str(&content)
99                .ok()
100                .map(FeedbackSubmitError::Status405),
101            409 => Some(FeedbackSubmitError::Status409()),
102            _ => None,
103        }
104        .or_else(|| {
105            serde_json::from_str(&content)
106                .ok()
107                .map(FeedbackSubmitError::UnknownValue)
108        });
109        Err(Error::ResponseError(Box::new(ResponseContent {
110            status,
111            content,
112            entity,
113            headers,
114        })))
115    }
116}