async_openai/
invites.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::invites::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest},
5    Client, RequestOptions,
6};
7
8/// Invite and manage invitations for an organization. Invited users are automatically added to the Default project.
9pub struct Invites<'c, C: Config> {
10    client: &'c Client<C>,
11    pub(crate) request_options: RequestOptions,
12}
13
14impl<'c, C: Config> Invites<'c, C> {
15    pub fn new(client: &'c Client<C>) -> Self {
16        Self {
17            client,
18            request_options: RequestOptions::new(),
19        }
20    }
21
22    /// Returns a list of invites in the organization.
23    #[crate::byot(R = serde::de::DeserializeOwned)]
24    pub async fn list(&self) -> Result<InviteListResponse, OpenAIError> {
25        self.client
26            .get("/organization/invites", &self.request_options)
27            .await
28    }
29
30    /// Retrieves an invite.
31    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
32    pub async fn retrieve(&self, invite_id: &str) -> Result<Invite, OpenAIError> {
33        self.client
34            .get(
35                format!("/organization/invites/{invite_id}").as_str(),
36                &self.request_options,
37            )
38            .await
39    }
40
41    /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
42    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
43    pub async fn create(&self, request: InviteRequest) -> Result<Invite, OpenAIError> {
44        self.client
45            .post("/organization/invites", request, &self.request_options)
46            .await
47    }
48
49    /// Delete an invite. If the invite has already been accepted, it cannot be deleted.
50    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
51    pub async fn delete(&self, invite_id: &str) -> Result<InviteDeleteResponse, OpenAIError> {
52        self.client
53            .delete(
54                format!("/organization/invites/{invite_id}").as_str(),
55                &self.request_options,
56            )
57            .await
58    }
59}