-
-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathadmin_api_keys.rs
More file actions
60 lines (53 loc) · 1.95 KB
/
admin_api_keys.rs
File metadata and controls
60 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use serde::Serialize;
use crate::{
config::Config,
error::OpenAIError,
types::admin::api_keys::{
AdminApiKey, AdminApiKeyDeleteResponse, ApiKeyList, CreateAdminApiKeyRequest,
},
Client,
};
/// Admin API keys enable Organization Owners to programmatically manage various aspects of their
/// organization, including users, projects, and API keys. These keys provide administrative capabilities,
/// allowing you to automate organization management tasks.
pub struct AdminAPIKeys<'c, C: Config> {
client: &'c Client<C>,
}
impl<'c, C: Config> AdminAPIKeys<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self { client }
}
/// List all organization and project API keys.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn list<Q>(&self, query: &Q) -> Result<ApiKeyList, OpenAIError>
where
Q: Serialize + ?Sized,
{
self.client
.get_with_query("/organization/admin_api_keys", &query)
.await
}
/// Create an organization admin API key.
pub async fn create(
&self,
request: CreateAdminApiKeyRequest,
) -> Result<AdminApiKey, OpenAIError> {
self.client
.post("/organization/admin_api_keys", request)
.await
}
/// Retrieve a single organization API key.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, key_id: &str) -> Result<AdminApiKey, OpenAIError> {
self.client
.get(format!("/organization/admin_api_keys/{key_id}").as_str())
.await
}
/// Delete an organization admin API key.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, key_id: &str) -> Result<AdminApiKeyDeleteResponse, OpenAIError> {
self.client
.delete(format!("/organization/admin_api_keys/{key_id}").as_str())
.await
}
}