async_openai/admin/
project_api_keys.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::admin::project_api_keys::{
5 ProjectApiKey, ProjectApiKeyDeleteResponse, ProjectApiKeyListResponse,
6 },
7 Client, RequestOptions,
8};
9
10pub struct ProjectAPIKeys<'c, C: Config> {
13 client: &'c Client<C>,
14 pub project_id: String,
15 pub(crate) request_options: RequestOptions,
16}
17
18impl<'c, C: Config> ProjectAPIKeys<'c, C> {
19 pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
20 Self {
21 client,
22 project_id: project_id.into(),
23 request_options: RequestOptions::new(),
24 }
25 }
26
27 #[crate::byot(R = serde::de::DeserializeOwned)]
29 pub async fn list(&self) -> Result<ProjectApiKeyListResponse, OpenAIError> {
30 self.client
31 .get(
32 format!("/organization/projects/{}/api_keys", self.project_id).as_str(),
33 &self.request_options,
34 )
35 .await
36 }
37
38 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
40 pub async fn retrieve(&self, api_key: &str) -> Result<ProjectApiKey, OpenAIError> {
41 self.client
42 .get(
43 format!(
44 "/organization/projects/{}/api_keys/{api_key}",
45 self.project_id
46 )
47 .as_str(),
48 &self.request_options,
49 )
50 .await
51 }
52
53 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
55 pub async fn delete(&self, api_key: &str) -> Result<ProjectApiKeyDeleteResponse, OpenAIError> {
56 self.client
57 .delete(
58 format!(
59 "/organization/projects/{}/api_keys/{api_key}",
60 self.project_id
61 )
62 .as_str(),
63 &self.request_options,
64 )
65 .await
66 }
67}