Skip to main content

langfuse_client_base/apis/
feedback_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 [`feedback_submit`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum FeedbackSubmitError {
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    Status409(),
26    UnknownValue(serde_json::Value),
27}
28
29/// 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.
30#[bon::builder]
31pub async fn feedback_submit(
32    configuration: &configuration::Configuration,
33    submit_feedback_request: models::SubmitFeedbackRequest,
34) -> Result<models::SubmitFeedbackResponse, Error<FeedbackSubmitError>> {
35    // add a prefix to parameters to efficiently prevent name collisions
36    let p_body_submit_feedback_request = submit_feedback_request;
37
38    let uri_str = format!("{}/api/public/feedback", configuration.base_path);
39    let mut req_builder = configuration
40        .client
41        .request(reqwest::Method::POST, &uri_str);
42
43    if let Some(ref user_agent) = configuration.user_agent {
44        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
45    }
46    if let Some(ref auth_conf) = configuration.basic_auth {
47        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
48    };
49    req_builder = req_builder.json(&p_body_submit_feedback_request);
50
51    let req = req_builder.build()?;
52    let resp = configuration.client.execute(req).await?;
53
54    let status = resp.status();
55    let content_type = resp
56        .headers()
57        .get("content-type")
58        .and_then(|v| v.to_str().ok())
59        .unwrap_or("application/octet-stream");
60    let content_type = super::ContentType::from(content_type);
61
62    if !status.is_client_error() && !status.is_server_error() {
63        let content = resp.text().await?;
64        match content_type {
65            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SubmitFeedbackResponse`"))),
67            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::SubmitFeedbackResponse`")))),
68        }
69    } else {
70        let content = resp.text().await?;
71        let entity: Option<FeedbackSubmitError> = serde_json::from_str(&content).ok();
72        Err(Error::ResponseError(ResponseContent {
73            status,
74            content,
75            entity,
76        }))
77    }
78}