Skip to main content

async_openai/admin/
projects.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::projects::{
5        Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest,
6    },
7    Client, ProjectAPIKeys, ProjectCertificates, ProjectDataRetentions, ProjectGroupRoles,
8    ProjectGroups, ProjectHostedToolPermission, ProjectModelPermission, ProjectRateLimits,
9    ProjectRoles, ProjectServiceAccounts, ProjectSpendAlerts, ProjectSpendLimit, ProjectUserRoles,
10    ProjectUsers, RequestOptions,
11};
12
13/// Manage the projects within an organization includes creation, updating, and archiving or projects.
14/// The Default project cannot be modified or archived.
15pub struct Projects<'c, C: Config> {
16    client: &'c Client<C>,
17    pub(crate) request_options: RequestOptions,
18}
19
20impl<'c, C: Config> Projects<'c, C> {
21    pub fn new(client: &'c Client<C>) -> Self {
22        Self {
23            client,
24            request_options: RequestOptions::new(),
25        }
26    }
27
28    // call [ProjectUsers] group APIs
29    pub fn users(&self, project_id: &str) -> ProjectUsers<'_, C> {
30        ProjectUsers::new(self.client, project_id)
31    }
32
33    // call [ProjectServiceAccounts] group APIs
34    pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<'_, C> {
35        ProjectServiceAccounts::new(self.client, project_id)
36    }
37
38    // call [ProjectAPIKeys] group APIs
39    pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<'_, C> {
40        ProjectAPIKeys::new(self.client, project_id)
41    }
42
43    // call [ProjectRateLimits] group APIs
44    pub fn rate_limits(&self, project_id: &str) -> ProjectRateLimits<'_, C> {
45        ProjectRateLimits::new(self.client, project_id)
46    }
47
48    // call [ProjectCertificates] group APIs
49    pub fn certificates(&self, project_id: &str) -> ProjectCertificates<'_, C> {
50        ProjectCertificates::new(self.client, project_id)
51    }
52
53    // call [ProjectGroups] group APIs
54    pub fn groups(&self, project_id: &str) -> ProjectGroups<'_, C> {
55        ProjectGroups::new(self.client, project_id)
56    }
57
58    // call [ProjectRoles] group APIs
59    pub fn roles(&self, project_id: &str) -> ProjectRoles<'_, C> {
60        ProjectRoles::new(self.client, project_id)
61    }
62
63    // call [ProjectUserRoles] group APIs
64    pub fn user_roles(&self, project_id: &str, user_id: &str) -> ProjectUserRoles<'_, C> {
65        ProjectUserRoles::new(self.client, project_id, user_id)
66    }
67
68    // call [ProjectGroupRoles] group APIs
69    pub fn group_roles(&self, project_id: &str, group_id: &str) -> ProjectGroupRoles<'_, C> {
70        ProjectGroupRoles::new(self.client, project_id, group_id)
71    }
72
73    /// call [ProjectDataRetentions] group APIs
74    pub fn data_retention(&self, project_id: &str) -> ProjectDataRetentions<'_, C> {
75        ProjectDataRetentions::new(self.client, project_id)
76    }
77
78    /// call [ProjectSpendAlerts] group APIs
79    pub fn spend_alerts(&self, project_id: &str) -> ProjectSpendAlerts<'_, C> {
80        ProjectSpendAlerts::new(self.client, project_id)
81    }
82
83    /// call [ProjectSpendLimit] group APIs
84    pub fn spend_limit(&self, project_id: &str) -> ProjectSpendLimit<'_, C> {
85        ProjectSpendLimit::new(self.client, project_id)
86    }
87
88    /// call [ProjectHostedToolPermission] group APIs
89    pub fn hosted_tool_permissions(&self, project_id: &str) -> ProjectHostedToolPermission<'_, C> {
90        ProjectHostedToolPermission::new(self.client, project_id)
91    }
92
93    /// call [ProjectModelPermission] group APIs
94    pub fn model_permissions(&self, project_id: &str) -> ProjectModelPermission<'_, C> {
95        ProjectModelPermission::new(self.client, project_id)
96    }
97
98    /// Returns a list of projects.
99    #[crate::byot(R = serde::de::DeserializeOwned)]
100    pub async fn list(&self) -> Result<ProjectListResponse, OpenAIError> {
101        self.client
102            .get("/organization/projects", &self.request_options)
103            .await
104    }
105
106    /// Create a new project in the organization. Projects can be created and archived, but cannot be deleted.
107    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
108    pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
109        self.client
110            .post("/organization/projects", request, &self.request_options)
111            .await
112    }
113
114    /// Retrieves a project.
115    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
116    pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
117        self.client
118            .get(
119                format!("/organization/projects/{project_id}").as_str(),
120                &self.request_options,
121            )
122            .await
123    }
124
125    /// Modifies a project in the organization.
126    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
127    pub async fn modify(
128        &self,
129        project_id: String,
130        request: ProjectUpdateRequest,
131    ) -> Result<Project, OpenAIError> {
132        self.client
133            .post(
134                format!("/organization/projects/{project_id}").as_str(),
135                request,
136                &self.request_options,
137            )
138            .await
139    }
140
141    /// Archives a project in the organization. Archived projects cannot be used or updated.
142    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
143    pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
144        self.client
145            .post(
146                format!("/organization/projects/{project_id}/archive").as_str(),
147                (),
148                &self.request_options,
149            )
150            .await
151    }
152}