async_openai/
admin_api_keys.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 types::admin::api_keys::{
7 AdminApiKey, AdminApiKeyDeleteResponse, ApiKeyList, CreateAdminApiKeyRequest,
8 },
9 Client,
10};
11
12pub struct AdminAPIKeys<'c, C: Config> {
16 client: &'c Client<C>,
17}
18
19impl<'c, C: Config> AdminAPIKeys<'c, C> {
20 pub fn new(client: &'c Client<C>) -> Self {
21 Self { client }
22 }
23
24 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
26 pub async fn list<Q>(&self, query: &Q) -> Result<ApiKeyList, OpenAIError>
27 where
28 Q: Serialize + ?Sized,
29 {
30 self.client
31 .get_with_query("/organization/admin_api_keys", &query)
32 .await
33 }
34
35 pub async fn create(
37 &self,
38 request: CreateAdminApiKeyRequest,
39 ) -> Result<AdminApiKey, OpenAIError> {
40 self.client
41 .post("/organization/admin_api_keys", request)
42 .await
43 }
44
45 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
47 pub async fn retrieve(&self, key_id: &str) -> Result<AdminApiKey, OpenAIError> {
48 self.client
49 .get(format!("/organization/admin_api_keys/{key_id}").as_str())
50 .await
51 }
52
53 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
55 pub async fn delete(&self, key_id: &str) -> Result<AdminApiKeyDeleteResponse, OpenAIError> {
56 self.client
57 .delete(format!("/organization/admin_api_keys/{key_id}").as_str())
58 .await
59 }
60}