langfuse_client_base/apis/
projects_api.rs

1/*
2 * langfuse
3 *
4 * ## 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 - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
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 [`projects_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ProjectsCreateError {
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 [`projects_create_api_key`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ProjectsCreateApiKeyError {
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/// struct for typed errors of method [`projects_delete`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ProjectsDeleteError {
44    Status400(serde_json::Value),
45    Status401(serde_json::Value),
46    Status403(serde_json::Value),
47    Status404(serde_json::Value),
48    Status405(serde_json::Value),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`projects_delete_api_key`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ProjectsDeleteApiKeyError {
56    Status400(serde_json::Value),
57    Status401(serde_json::Value),
58    Status403(serde_json::Value),
59    Status404(serde_json::Value),
60    Status405(serde_json::Value),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`projects_get`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum ProjectsGetError {
68    Status400(serde_json::Value),
69    Status401(serde_json::Value),
70    Status403(serde_json::Value),
71    Status404(serde_json::Value),
72    Status405(serde_json::Value),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`projects_get_api_keys`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ProjectsGetApiKeysError {
80    Status400(serde_json::Value),
81    Status401(serde_json::Value),
82    Status403(serde_json::Value),
83    Status404(serde_json::Value),
84    Status405(serde_json::Value),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`projects_update`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum ProjectsUpdateError {
92    Status400(serde_json::Value),
93    Status401(serde_json::Value),
94    Status403(serde_json::Value),
95    Status404(serde_json::Value),
96    Status405(serde_json::Value),
97    UnknownValue(serde_json::Value),
98}
99
100/// Create a new project (requires organization-scoped API key)
101pub async fn projects_create(
102    configuration: &configuration::Configuration,
103    projects_create_request: models::ProjectsCreateRequest,
104) -> Result<models::Project, Error<ProjectsCreateError>> {
105    // add a prefix to parameters to efficiently prevent name collisions
106    let p_body_projects_create_request = projects_create_request;
107
108    let uri_str = format!("{}/api/public/projects", configuration.base_path);
109    let mut req_builder = configuration
110        .client
111        .request(reqwest::Method::POST, &uri_str);
112
113    if let Some(ref user_agent) = configuration.user_agent {
114        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115    }
116    if let Some(ref auth_conf) = configuration.basic_auth {
117        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
118    };
119    req_builder = req_builder.json(&p_body_projects_create_request);
120
121    let req = req_builder.build()?;
122    let resp = configuration.client.execute(req).await?;
123
124    let status = resp.status();
125    let content_type = resp
126        .headers()
127        .get("content-type")
128        .and_then(|v| v.to_str().ok())
129        .unwrap_or("application/octet-stream");
130    let content_type = super::ContentType::from(content_type);
131
132    if !status.is_client_error() && !status.is_server_error() {
133        let content = resp.text().await?;
134        match content_type {
135            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Project`"))),
137            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::Project`")))),
138        }
139    } else {
140        let content = resp.text().await?;
141        let entity: Option<ProjectsCreateError> = serde_json::from_str(&content).ok();
142        Err(Error::ResponseError(ResponseContent {
143            status,
144            content,
145            entity,
146        }))
147    }
148}
149
150/// Create a new API key for a project (requires organization-scoped API key)
151pub async fn projects_create_api_key(
152    configuration: &configuration::Configuration,
153    project_id: &str,
154    projects_create_api_key_request: models::ProjectsCreateApiKeyRequest,
155) -> Result<models::ApiKeyResponse, Error<ProjectsCreateApiKeyError>> {
156    // add a prefix to parameters to efficiently prevent name collisions
157    let p_path_project_id = project_id;
158    let p_body_projects_create_api_key_request = projects_create_api_key_request;
159
160    let uri_str = format!(
161        "{}/api/public/projects/{projectId}/apiKeys",
162        configuration.base_path,
163        projectId = crate::apis::urlencode(p_path_project_id)
164    );
165    let mut req_builder = configuration
166        .client
167        .request(reqwest::Method::POST, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref auth_conf) = configuration.basic_auth {
173        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
174    };
175    req_builder = req_builder.json(&p_body_projects_create_api_key_request);
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiKeyResponse`"))),
193            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::ApiKeyResponse`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<ProjectsCreateApiKeyError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent {
199            status,
200            content,
201            entity,
202        }))
203    }
204}
205
206/// Delete a project by ID (requires organization-scoped API key). Project deletion is processed asynchronously.
207pub async fn projects_delete(
208    configuration: &configuration::Configuration,
209    project_id: &str,
210) -> Result<models::ProjectDeletionResponse, Error<ProjectsDeleteError>> {
211    // add a prefix to parameters to efficiently prevent name collisions
212    let p_path_project_id = project_id;
213
214    let uri_str = format!(
215        "{}/api/public/projects/{projectId}",
216        configuration.base_path,
217        projectId = crate::apis::urlencode(p_path_project_id)
218    );
219    let mut req_builder = configuration
220        .client
221        .request(reqwest::Method::DELETE, &uri_str);
222
223    if let Some(ref user_agent) = configuration.user_agent {
224        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225    }
226    if let Some(ref auth_conf) = configuration.basic_auth {
227        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
228    };
229
230    let req = req_builder.build()?;
231    let resp = configuration.client.execute(req).await?;
232
233    let status = resp.status();
234    let content_type = resp
235        .headers()
236        .get("content-type")
237        .and_then(|v| v.to_str().ok())
238        .unwrap_or("application/octet-stream");
239    let content_type = super::ContentType::from(content_type);
240
241    if !status.is_client_error() && !status.is_server_error() {
242        let content = resp.text().await?;
243        match content_type {
244            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectDeletionResponse`"))),
246            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::ProjectDeletionResponse`")))),
247        }
248    } else {
249        let content = resp.text().await?;
250        let entity: Option<ProjectsDeleteError> = serde_json::from_str(&content).ok();
251        Err(Error::ResponseError(ResponseContent {
252            status,
253            content,
254            entity,
255        }))
256    }
257}
258
259/// Delete an API key for a project (requires organization-scoped API key)
260pub async fn projects_delete_api_key(
261    configuration: &configuration::Configuration,
262    project_id: &str,
263    api_key_id: &str,
264) -> Result<models::ApiKeyDeletionResponse, Error<ProjectsDeleteApiKeyError>> {
265    // add a prefix to parameters to efficiently prevent name collisions
266    let p_path_project_id = project_id;
267    let p_path_api_key_id = api_key_id;
268
269    let uri_str = format!(
270        "{}/api/public/projects/{projectId}/apiKeys/{apiKeyId}",
271        configuration.base_path,
272        projectId = crate::apis::urlencode(p_path_project_id),
273        apiKeyId = crate::apis::urlencode(p_path_api_key_id)
274    );
275    let mut req_builder = configuration
276        .client
277        .request(reqwest::Method::DELETE, &uri_str);
278
279    if let Some(ref user_agent) = configuration.user_agent {
280        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
281    }
282    if let Some(ref auth_conf) = configuration.basic_auth {
283        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
284    };
285
286    let req = req_builder.build()?;
287    let resp = configuration.client.execute(req).await?;
288
289    let status = resp.status();
290    let content_type = resp
291        .headers()
292        .get("content-type")
293        .and_then(|v| v.to_str().ok())
294        .unwrap_or("application/octet-stream");
295    let content_type = super::ContentType::from(content_type);
296
297    if !status.is_client_error() && !status.is_server_error() {
298        let content = resp.text().await?;
299        match content_type {
300            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
301            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiKeyDeletionResponse`"))),
302            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::ApiKeyDeletionResponse`")))),
303        }
304    } else {
305        let content = resp.text().await?;
306        let entity: Option<ProjectsDeleteApiKeyError> = serde_json::from_str(&content).ok();
307        Err(Error::ResponseError(ResponseContent {
308            status,
309            content,
310            entity,
311        }))
312    }
313}
314
315/// Get Project associated with API key
316pub async fn projects_get(
317    configuration: &configuration::Configuration,
318) -> Result<models::Projects, Error<ProjectsGetError>> {
319    let uri_str = format!("{}/api/public/projects", configuration.base_path);
320    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
321
322    if let Some(ref user_agent) = configuration.user_agent {
323        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
324    }
325    if let Some(ref auth_conf) = configuration.basic_auth {
326        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
327    };
328
329    let req = req_builder.build()?;
330    let resp = configuration.client.execute(req).await?;
331
332    let status = resp.status();
333    let content_type = resp
334        .headers()
335        .get("content-type")
336        .and_then(|v| v.to_str().ok())
337        .unwrap_or("application/octet-stream");
338    let content_type = super::ContentType::from(content_type);
339
340    if !status.is_client_error() && !status.is_server_error() {
341        let content = resp.text().await?;
342        match content_type {
343            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
344            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Projects`"))),
345            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::Projects`")))),
346        }
347    } else {
348        let content = resp.text().await?;
349        let entity: Option<ProjectsGetError> = serde_json::from_str(&content).ok();
350        Err(Error::ResponseError(ResponseContent {
351            status,
352            content,
353            entity,
354        }))
355    }
356}
357
358/// Get all API keys for a project (requires organization-scoped API key)
359pub async fn projects_get_api_keys(
360    configuration: &configuration::Configuration,
361    project_id: &str,
362) -> Result<models::ApiKeyList, Error<ProjectsGetApiKeysError>> {
363    // add a prefix to parameters to efficiently prevent name collisions
364    let p_path_project_id = project_id;
365
366    let uri_str = format!(
367        "{}/api/public/projects/{projectId}/apiKeys",
368        configuration.base_path,
369        projectId = crate::apis::urlencode(p_path_project_id)
370    );
371    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
372
373    if let Some(ref user_agent) = configuration.user_agent {
374        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
375    }
376    if let Some(ref auth_conf) = configuration.basic_auth {
377        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
378    };
379
380    let req = req_builder.build()?;
381    let resp = configuration.client.execute(req).await?;
382
383    let status = resp.status();
384    let content_type = resp
385        .headers()
386        .get("content-type")
387        .and_then(|v| v.to_str().ok())
388        .unwrap_or("application/octet-stream");
389    let content_type = super::ContentType::from(content_type);
390
391    if !status.is_client_error() && !status.is_server_error() {
392        let content = resp.text().await?;
393        match content_type {
394            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
395            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiKeyList`"))),
396            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::ApiKeyList`")))),
397        }
398    } else {
399        let content = resp.text().await?;
400        let entity: Option<ProjectsGetApiKeysError> = serde_json::from_str(&content).ok();
401        Err(Error::ResponseError(ResponseContent {
402            status,
403            content,
404            entity,
405        }))
406    }
407}
408
409/// Update a project by ID (requires organization-scoped API key).
410pub async fn projects_update(
411    configuration: &configuration::Configuration,
412    project_id: &str,
413    projects_create_request: models::ProjectsCreateRequest,
414) -> Result<models::Project, Error<ProjectsUpdateError>> {
415    // add a prefix to parameters to efficiently prevent name collisions
416    let p_path_project_id = project_id;
417    let p_body_projects_create_request = projects_create_request;
418
419    let uri_str = format!(
420        "{}/api/public/projects/{projectId}",
421        configuration.base_path,
422        projectId = crate::apis::urlencode(p_path_project_id)
423    );
424    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
425
426    if let Some(ref user_agent) = configuration.user_agent {
427        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
428    }
429    if let Some(ref auth_conf) = configuration.basic_auth {
430        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
431    };
432    req_builder = req_builder.json(&p_body_projects_create_request);
433
434    let req = req_builder.build()?;
435    let resp = configuration.client.execute(req).await?;
436
437    let status = resp.status();
438    let content_type = resp
439        .headers()
440        .get("content-type")
441        .and_then(|v| v.to_str().ok())
442        .unwrap_or("application/octet-stream");
443    let content_type = super::ContentType::from(content_type);
444
445    if !status.is_client_error() && !status.is_server_error() {
446        let content = resp.text().await?;
447        match content_type {
448            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
449            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Project`"))),
450            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::Project`")))),
451        }
452    } else {
453        let content = resp.text().await?;
454        let entity: Option<ProjectsUpdateError> = serde_json::from_str(&content).ok();
455        Err(Error::ResponseError(ResponseContent {
456            status,
457            content,
458            entity,
459        }))
460    }
461}