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
13pub 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 pub fn users(&self, project_id: &str) -> ProjectUsers<'_, C> {
30 ProjectUsers::new(self.client, project_id)
31 }
32
33 pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<'_, C> {
35 ProjectServiceAccounts::new(self.client, project_id)
36 }
37
38 pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<'_, C> {
40 ProjectAPIKeys::new(self.client, project_id)
41 }
42
43 pub fn rate_limits(&self, project_id: &str) -> ProjectRateLimits<'_, C> {
45 ProjectRateLimits::new(self.client, project_id)
46 }
47
48 pub fn certificates(&self, project_id: &str) -> ProjectCertificates<'_, C> {
50 ProjectCertificates::new(self.client, project_id)
51 }
52
53 pub fn groups(&self, project_id: &str) -> ProjectGroups<'_, C> {
55 ProjectGroups::new(self.client, project_id)
56 }
57
58 pub fn roles(&self, project_id: &str) -> ProjectRoles<'_, C> {
60 ProjectRoles::new(self.client, project_id)
61 }
62
63 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 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 pub fn data_retention(&self, project_id: &str) -> ProjectDataRetentions<'_, C> {
75 ProjectDataRetentions::new(self.client, project_id)
76 }
77
78 pub fn spend_alerts(&self, project_id: &str) -> ProjectSpendAlerts<'_, C> {
80 ProjectSpendAlerts::new(self.client, project_id)
81 }
82
83 pub fn spend_limit(&self, project_id: &str) -> ProjectSpendLimit<'_, C> {
85 ProjectSpendLimit::new(self.client, project_id)
86 }
87
88 pub fn hosted_tool_permissions(&self, project_id: &str) -> ProjectHostedToolPermission<'_, C> {
90 ProjectHostedToolPermission::new(self.client, project_id)
91 }
92
93 pub fn model_permissions(&self, project_id: &str) -> ProjectModelPermission<'_, C> {
95 ProjectModelPermission::new(self.client, project_id)
96 }
97
98 #[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 #[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 #[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 #[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 #[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}