async_openai/admin/
admin_api_keys.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::admin::api_keys::{
5 AdminApiKey, AdminApiKeyDeleteResponse, ApiKeyList, CreateAdminApiKeyRequest,
6 },
7 Client, RequestOptions,
8};
9
10pub struct AdminAPIKeys<'c, C: Config> {
14 client: &'c Client<C>,
15 pub(crate) request_options: RequestOptions,
16}
17
18impl<'c, C: Config> AdminAPIKeys<'c, C> {
19 pub fn new(client: &'c Client<C>) -> Self {
20 Self {
21 client,
22 request_options: RequestOptions::new(),
23 }
24 }
25
26 #[crate::byot(R = serde::de::DeserializeOwned)]
28 pub async fn list(&self) -> Result<ApiKeyList, OpenAIError> {
29 self.client
30 .get("/organization/admin_api_keys", &self.request_options)
31 .await
32 }
33
34 pub async fn create(
36 &self,
37 request: CreateAdminApiKeyRequest,
38 ) -> Result<AdminApiKey, OpenAIError> {
39 self.client
40 .post(
41 "/organization/admin_api_keys",
42 request,
43 &self.request_options,
44 )
45 .await
46 }
47
48 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
50 pub async fn retrieve(&self, key_id: &str) -> Result<AdminApiKey, OpenAIError> {
51 self.client
52 .get(
53 format!("/organization/admin_api_keys/{key_id}").as_str(),
54 &self.request_options,
55 )
56 .await
57 }
58
59 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
61 pub async fn delete(&self, key_id: &str) -> Result<AdminApiKeyDeleteResponse, OpenAIError> {
62 self.client
63 .delete(
64 format!("/organization/admin_api_keys/{key_id}").as_str(),
65 &self.request_options,
66 )
67 .await
68 }
69}