/*
* server
*
* ## 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`
*
* The version of the OpenAPI document:
*
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`evaluators_create`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsCreateError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status412(models::PublicApiError),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`evaluators_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsDeleteError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`evaluators_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsGetError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`evaluators_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsListError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`evaluators_list_versions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsListVersionsError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`evaluators_update`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EvaluatorsUpdateError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
Status409(models::PublicApiError),
Status412(models::PublicApiError),
Status429(models::PublicApiError),
Status500(models::PublicApiError),
UnknownValue(serde_json::Value),
}
/// Create an evaluator in the authenticated project. An evaluator defines **how** Langfuse should score data. LLM-as-a-judge evaluators define a prompt, expected structured output, and optional model configuration. Code evaluators define source code and a runtime language. This always creates a new evaluator with version `1`. Names are not identifiers and do not need to be unique.
#[bon::builder]
pub async fn evaluators_create(
configuration: &configuration::Configuration,
create_evaluator_request: models::CreateEvaluatorRequest,
) -> Result<models::Evaluator, Error<EvaluatorsCreateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_evaluator_request = create_evaluator_request;
let uri_str = format!("{}/api/public/v2/evaluators", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_body_create_evaluator_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Evaluator`"))),
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::Evaluator`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Delete an evaluator and all of its stored versions. Associated evaluation-rule assignments are also removed. Scores already produced by the evaluator are preserved.
#[bon::builder]
pub async fn evaluators_delete(
configuration: &configuration::Configuration,
evaluator_id: &str,
) -> Result<models::DeletedEvaluator, Error<EvaluatorsDeleteError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_evaluator_id = evaluator_id;
let uri_str = format!(
"{}/api/public/v2/evaluators/{evaluatorId}",
configuration.base_path,
evaluatorId = crate::apis::urlencode(p_path_evaluator_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeletedEvaluator`"))),
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::DeletedEvaluator`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsDeleteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Get one evaluator by its stable identifier. The response includes the evaluator's latest definition and version metadata flattened into the evaluator object, plus associated evaluation rules. Use the version-history endpoint when older definitions are needed.
#[bon::builder]
pub async fn evaluators_get(
configuration: &configuration::Configuration,
evaluator_id: &str,
) -> Result<models::Evaluator, Error<EvaluatorsGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_evaluator_id = evaluator_id;
let uri_str = format!(
"{}/api/public/v2/evaluators/{evaluatorId}",
configuration.base_path,
evaluatorId = crate::apis::urlencode(p_path_evaluator_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Evaluator`"))),
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::Evaluator`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// List evaluators in newest-first creation order. Every evaluator includes its latest definition and version metadata flattened into the evaluator object, plus associated evaluation rules. Treat the cursor as opaque and return it unchanged.
#[bon::builder]
pub async fn evaluators_list(
configuration: &configuration::Configuration,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::EvaluatorsPage, Error<EvaluatorsListError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!("{}/api/public/v2/evaluators", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluatorsPage`"))),
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::EvaluatorsPage`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// List an evaluator's version history in newest-first order. This endpoint is intended for history and audit use cases. Ordinary clients can use the flattened `version` and definition fields on the evaluator response.
#[bon::builder]
pub async fn evaluators_list_versions(
configuration: &configuration::Configuration,
evaluator_id: &str,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::EvaluatorVersionsPage, Error<EvaluatorsListVersionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_evaluator_id = evaluator_id;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!(
"{}/api/public/v2/evaluators/{evaluatorId}/versions",
configuration.base_path,
evaluatorId = crate::apis::urlencode(p_path_evaluator_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EvaluatorVersionsPage`"))),
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::EvaluatorVersionsPage`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsListVersionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Update an evaluator by its stable identifier. Provide only the top-level fields to change. Metadata-only changes do not create a version. Evaluator type cannot change. Definition fields are flattened into the request. To replace a definition, include `type` and every definition field for that type. Definition fields are replaced as a complete unit rather than merged. For LLM-as-a-judge evaluators, omitting or setting `modelConfig` to `null` selects the project's default evaluation model. Replacing a definition automatically returns an evaluator paused by an invalid or missing model configuration to `active`, while preserving its id and evaluation-rule assignments. Pauses caused by provider authentication, billing, connectivity, account state, or an unknown legacy reason remain paused until the explicit reactivation check succeeds.
#[bon::builder]
pub async fn evaluators_update(
configuration: &configuration::Configuration,
evaluator_id: &str,
update_evaluator_request: models::UpdateEvaluatorRequest,
) -> Result<models::Evaluator, Error<EvaluatorsUpdateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_evaluator_id = evaluator_id;
let p_body_update_evaluator_request = update_evaluator_request;
let uri_str = format!(
"{}/api/public/v2/evaluators/{evaluatorId}",
configuration.base_path,
evaluatorId = crate::apis::urlencode(p_path_evaluator_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_body_update_evaluator_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Evaluator`"))),
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::Evaluator`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EvaluatorsUpdateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}