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