async_openai/
projects.rs

1use serde::Serialize;
2
3use crate::{
4    config::Config,
5    error::OpenAIError,
6    project_api_keys::ProjectAPIKeys,
7    project_certificates::ProjectCertificates,
8    project_rate_limits::ProjectRateLimits,
9    types::admin::projects::{
10        Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest,
11    },
12    Client, ProjectServiceAccounts, ProjectUsers,
13};
14
15/// Manage the projects within an organization includes creation, updating, and archiving or projects.
16/// The Default project cannot be modified or archived.
17pub struct Projects<'c, C: Config> {
18    client: &'c Client<C>,
19}
20
21impl<'c, C: Config> Projects<'c, C> {
22    pub fn new(client: &'c Client<C>) -> Self {
23        Self { client }
24    }
25
26    // call [ProjectUsers] group APIs
27    pub fn users(&self, project_id: &str) -> ProjectUsers<'_, C> {
28        ProjectUsers::new(self.client, project_id)
29    }
30
31    // call [ProjectServiceAccounts] group APIs
32    pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<'_, C> {
33        ProjectServiceAccounts::new(self.client, project_id)
34    }
35
36    // call [ProjectAPIKeys] group APIs
37    pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<'_, C> {
38        ProjectAPIKeys::new(self.client, project_id)
39    }
40
41    // call [ProjectRateLimits] group APIs
42    pub fn rate_limits(&self, project_id: &str) -> ProjectRateLimits<'_, C> {
43        ProjectRateLimits::new(self.client, project_id)
44    }
45
46    // call [ProjectCertificates] group APIs
47    pub fn certificates(&self, project_id: &str) -> ProjectCertificates<'_, C> {
48        ProjectCertificates::new(self.client, project_id)
49    }
50
51    /// Returns a list of projects.
52    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
53    pub async fn list<Q>(&self, query: &Q) -> Result<ProjectListResponse, OpenAIError>
54    where
55        Q: Serialize + ?Sized,
56    {
57        self.client
58            .get_with_query("/organization/projects", &query)
59            .await
60    }
61
62    /// Create a new project in the organization. Projects can be created and archived, but cannot be deleted.
63    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
64    pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
65        self.client.post("/organization/projects", request).await
66    }
67
68    /// Retrieves a project.
69    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
70    pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
71        self.client
72            .get(format!("/organization/projects/{project_id}").as_str())
73            .await
74    }
75
76    /// Modifies a project in the organization.
77    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
78    pub async fn modify(
79        &self,
80        project_id: String,
81        request: ProjectUpdateRequest,
82    ) -> Result<Project, OpenAIError> {
83        self.client
84            .post(
85                format!("/organization/projects/{project_id}").as_str(),
86                request,
87            )
88            .await
89    }
90
91    /// Archives a project in the organization. Archived projects cannot be used or updated.
92    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
93    pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
94        self.client
95            .post(
96                format!("/organization/projects/{project_id}/archive").as_str(),
97                (),
98            )
99            .await
100    }
101}