#![allow(deprecated)]
/*
* 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 serde::{de::Error as _, Deserialize, Serialize};
use timvw_rust_runtime;
/// struct for typed errors of method [`prompts_create`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PromptsCreateError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`prompts_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PromptsDeleteError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`prompts_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PromptsGetError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`prompts_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PromptsListError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// Create a new version for the prompt with the given `name`
#[bon::builder]
pub async fn prompts_create(
configuration: &configuration::Configuration,
create_prompt_request: &models::CreatePromptRequest,
options: Option<&timvw_rust_runtime::RequestOptions>,
) -> Result<models::Prompt, Error<PromptsCreateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_prompt_request = create_prompt_request;
let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
let mut req_builder = configuration
.client
.request(timvw_rust_runtime::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder =
req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(
&auth_conf.0,
auth_conf
.1
.as_ref()
.map(timvw_rust_runtime::ExposeSecret::expose_secret),
);
};
req_builder = req_builder.json(p_body_create_prompt_request);
// last, so its headers replace the generated ones
if let Some(options) = options {
req_builder = req_builder.options(options);
}
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 => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Prompt`")))),
}
} else {
let headers = resp.headers().clone();
let content = resp.text().await?;
let entity: Option<PromptsCreateError> = match status.as_u16() {
400 => serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::Status400),
401 => serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::Status401),
403 => serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::Status403),
404 => serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::Status404),
405 => serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::Status405),
_ => None,
}
.or_else(|| {
serde_json::from_str(&content)
.ok()
.map(PromptsCreateError::UnknownValue)
});
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
headers,
})))
}
}
/// Delete prompt versions. If neither version nor label is specified, all versions of the prompt are deleted.
#[bon::builder]
pub async fn prompts_delete(
configuration: &configuration::Configuration,
prompt_name: &str,
label: Option<&str>,
version: Option<i64>,
options: Option<&timvw_rust_runtime::RequestOptions>,
) -> Result<(), Error<PromptsDeleteError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_prompt_name = prompt_name;
let p_query_label = label;
let p_query_version = version;
let uri_str = format!(
"{}/api/public/v2/prompts/{promptName}",
configuration.base_path,
promptName = crate::apis::urlencode(p_path_prompt_name)
);
let mut req_builder = configuration
.client
.request(timvw_rust_runtime::Method::DELETE, &uri_str);
if let Some(ref param_value) = p_query_label {
req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_version {
req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder =
req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(
&auth_conf.0,
auth_conf
.1
.as_ref()
.map(timvw_rust_runtime::ExposeSecret::expose_secret),
);
};
// last, so its headers replace the generated ones
if let Some(options) = options {
req_builder = req_builder.options(options);
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let headers = resp.headers().clone();
let content = resp.text().await?;
let entity: Option<PromptsDeleteError> = match status.as_u16() {
400 => serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::Status400),
401 => serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::Status401),
403 => serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::Status403),
404 => serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::Status404),
405 => serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::Status405),
_ => None,
}
.or_else(|| {
serde_json::from_str(&content)
.ok()
.map(PromptsDeleteError::UnknownValue)
});
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
headers,
})))
}
}
/// Get a prompt
#[bon::builder]
pub async fn prompts_get(
configuration: &configuration::Configuration,
prompt_name: &str,
version: Option<i64>,
label: Option<&str>,
resolve: Option<bool>,
options: Option<&timvw_rust_runtime::RequestOptions>,
) -> Result<models::Prompt, Error<PromptsGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_prompt_name = prompt_name;
let p_query_version = version;
let p_query_label = label;
let p_query_resolve = resolve;
let uri_str = format!(
"{}/api/public/v2/prompts/{promptName}",
configuration.base_path,
promptName = crate::apis::urlencode(p_path_prompt_name)
);
let mut req_builder = configuration
.client
.request(timvw_rust_runtime::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_version {
req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_label {
req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_resolve {
req_builder = req_builder.query(&[("resolve", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder =
req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(
&auth_conf.0,
auth_conf
.1
.as_ref()
.map(timvw_rust_runtime::ExposeSecret::expose_secret),
);
};
// last, so its headers replace the generated ones
if let Some(options) = options {
req_builder = req_builder.options(options);
}
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 => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Prompt`")))),
}
} else {
let headers = resp.headers().clone();
let content = resp.text().await?;
let entity: Option<PromptsGetError> = match status.as_u16() {
400 => serde_json::from_str(&content)
.ok()
.map(PromptsGetError::Status400),
401 => serde_json::from_str(&content)
.ok()
.map(PromptsGetError::Status401),
403 => serde_json::from_str(&content)
.ok()
.map(PromptsGetError::Status403),
404 => serde_json::from_str(&content)
.ok()
.map(PromptsGetError::Status404),
405 => serde_json::from_str(&content)
.ok()
.map(PromptsGetError::Status405),
_ => None,
}
.or_else(|| {
serde_json::from_str(&content)
.ok()
.map(PromptsGetError::UnknownValue)
});
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
headers,
})))
}
}
/// Get a list of prompt names with versions and labels
#[bon::builder]
pub async fn prompts_list(
configuration: &configuration::Configuration,
name: Option<&str>,
label: Option<&str>,
tag: Option<&str>,
page: Option<i64>,
limit: Option<i64>,
from_updated_at: Option<chrono::DateTime<chrono::FixedOffset>>,
to_updated_at: Option<chrono::DateTime<chrono::FixedOffset>>,
filter: Option<&str>,
options: Option<&timvw_rust_runtime::RequestOptions>,
) -> Result<models::PromptMetaListResponse, Error<PromptsListError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_name = name;
let p_query_label = label;
let p_query_tag = tag;
let p_query_page = page;
let p_query_limit = limit;
let p_query_from_updated_at = from_updated_at;
let p_query_to_updated_at = to_updated_at;
let p_query_filter = filter;
let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
let mut req_builder = configuration
.client
.request(timvw_rust_runtime::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_name {
req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_label {
req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_tag {
req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
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_from_updated_at {
req_builder = req_builder.query(&[("fromUpdatedAt", ¶m_value.to_rfc3339())]);
}
if let Some(ref param_value) = p_query_to_updated_at {
req_builder = req_builder.query(&[("toUpdatedAt", ¶m_value.to_rfc3339())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder =
req_builder.header(timvw_rust_runtime::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(
&auth_conf.0,
auth_conf
.1
.as_ref()
.map(timvw_rust_runtime::ExposeSecret::expose_secret),
);
};
// last, so its headers replace the generated ones
if let Some(options) = options {
req_builder = req_builder.options(options);
}
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 => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PromptMetaListResponse`"))),
ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PromptMetaListResponse`")))),
}
} else {
let headers = resp.headers().clone();
let content = resp.text().await?;
let entity: Option<PromptsListError> = match status.as_u16() {
400 => serde_json::from_str(&content)
.ok()
.map(PromptsListError::Status400),
401 => serde_json::from_str(&content)
.ok()
.map(PromptsListError::Status401),
403 => serde_json::from_str(&content)
.ok()
.map(PromptsListError::Status403),
404 => serde_json::from_str(&content)
.ok()
.map(PromptsListError::Status404),
405 => serde_json::from_str(&content)
.ok()
.map(PromptsListError::Status405),
_ => None,
}
.or_else(|| {
serde_json::from_str(&content)
.ok()
.map(PromptsListError::UnknownValue)
});
Err(Error::ResponseError(Box::new(ResponseContent {
status,
content,
entity,
headers,
})))
}
}