dynamo_async_openai/
invites.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use serde::Serialize;
12
13use crate::{
14    Client,
15    config::Config,
16    error::OpenAIError,
17    types::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest},
18};
19
20/// Invite and manage invitations for an organization. Invited users are automatically added to the Default project.
21pub struct Invites<'c, C: Config> {
22    client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Invites<'c, C> {
26    pub fn new(client: &'c Client<C>) -> Self {
27        Self { client }
28    }
29
30    /// Returns a list of invites in the organization.
31    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
32    pub async fn list<Q>(&self, query: &Q) -> Result<InviteListResponse, OpenAIError>
33    where
34        Q: Serialize + ?Sized,
35    {
36        self.client
37            .get_with_query("/organization/invites", &query)
38            .await
39    }
40
41    /// Retrieves an invite.
42    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
43    pub async fn retrieve(&self, invite_id: &str) -> Result<Invite, OpenAIError> {
44        self.client
45            .get(format!("/organization/invites/{invite_id}").as_str())
46            .await
47    }
48
49    /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
50    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
51    pub async fn create(&self, request: InviteRequest) -> Result<Invite, OpenAIError> {
52        self.client.post("/organization/invites", request).await
53    }
54
55    /// Delete an invite. If the invite has already been accepted, it cannot be deleted.
56    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
57    pub async fn delete(&self, invite_id: &str) -> Result<InviteDeleteResponse, OpenAIError> {
58        self.client
59            .delete(format!("/organization/invites/{invite_id}").as_str())
60            .await
61    }
62}