Skip to main content

async_openai/admin/
project_spend_alerts.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::projects::{
5        CreateSpendAlertBody, ProjectSpendAlert, ProjectSpendAlertDeletedResource,
6        ProjectSpendAlertListResource,
7    },
8    Client, RequestOptions,
9};
10
11pub struct ProjectSpendAlerts<'c, C: Config> {
12    client: &'c Client<C>,
13    pub(crate) request_options: RequestOptions,
14    pub project_id: String,
15}
16
17impl<'c, C: Config> ProjectSpendAlerts<'c, C> {
18    pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
19        Self {
20            client,
21            request_options: RequestOptions::new(),
22            project_id: project_id.into(),
23        }
24    }
25
26    /// Lists project spend alerts.
27    #[crate::byot(R = serde::de::DeserializeOwned)]
28    pub async fn list(&self) -> Result<ProjectSpendAlertListResource, OpenAIError> {
29        self.client
30            .get(
31                &format!(
32                    "/organization/projects/{project_id}/spend_alerts",
33                    project_id = self.project_id
34                ),
35                &self.request_options,
36            )
37            .await
38    }
39
40    /// Creates a project spend alert.
41    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
42    pub async fn create(
43        &self,
44        request: CreateSpendAlertBody,
45    ) -> Result<ProjectSpendAlert, OpenAIError> {
46        self.client
47            .post(
48                &format!(
49                    "/organization/projects/{project_id}/spend_alerts",
50                    project_id = self.project_id
51                ),
52                request,
53                &self.request_options,
54            )
55            .await
56    }
57
58    /// Retrieves a project spend alert.
59    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
60    pub async fn retrieve(&self, alert_id: &str) -> Result<ProjectSpendAlert, OpenAIError> {
61        self.client
62            .get(
63                &format!(
64                    "/organization/projects/{project_id}/spend_alerts/{alert_id}",
65                    project_id = self.project_id
66                ),
67                &self.request_options,
68            )
69            .await
70    }
71
72    /// Updates a project spend alert.
73    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
74    pub async fn update(
75        &self,
76        alert_id: &str,
77        request: CreateSpendAlertBody,
78    ) -> Result<ProjectSpendAlert, OpenAIError> {
79        self.client
80            .post(
81                &format!(
82                    "/organization/projects/{project_id}/spend_alerts/{alert_id}",
83                    project_id = self.project_id
84                ),
85                request,
86                &self.request_options,
87            )
88            .await
89    }
90
91    /// Deletes a project spend alert.
92    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
93    pub async fn delete(
94        &self,
95        alert_id: &str,
96    ) -> Result<ProjectSpendAlertDeletedResource, OpenAIError> {
97        self.client
98            .delete(
99                &format!(
100                    "/organization/projects/{project_id}/spend_alerts/{alert_id}",
101                    project_id = self.project_id
102                ),
103                &self.request_options,
104            )
105            .await
106    }
107}