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