async_openai/admin/
usage.rs

1use crate::{
2    config::Config, error::OpenAIError, types::admin::usage::UsageResponse, Client, RequestOptions,
3};
4
5/// Manage organization usage data. Get usage details for various API endpoints including
6/// completions, embeddings, images, audio, moderations, vector stores, and code interpreter sessions.
7pub struct Usage<'c, C: Config> {
8    client: &'c Client<C>,
9    pub(crate) request_options: RequestOptions,
10}
11
12impl<'c, C: Config> Usage<'c, C> {
13    pub fn new(client: &'c Client<C>) -> Self {
14        Self {
15            client,
16            request_options: RequestOptions::new(),
17        }
18    }
19
20    /// Get audio speeches usage details for the organization.
21    #[crate::byot(R = serde::de::DeserializeOwned)]
22    pub async fn audio_speeches(&self) -> Result<UsageResponse, OpenAIError> {
23        self.client
24            .get("/organization/usage/audio_speeches", &self.request_options)
25            .await
26    }
27
28    /// Get audio transcriptions usage details for the organization.
29    #[crate::byot(R = serde::de::DeserializeOwned)]
30    pub async fn audio_transcriptions(&self) -> Result<UsageResponse, OpenAIError> {
31        self.client
32            .get(
33                "/organization/usage/audio_transcriptions",
34                &self.request_options,
35            )
36            .await
37    }
38
39    /// Get code interpreter sessions usage details for the organization.
40    #[crate::byot(R = serde::de::DeserializeOwned)]
41    pub async fn code_interpreter_sessions(&self) -> Result<UsageResponse, OpenAIError> {
42        self.client
43            .get(
44                "/organization/usage/code_interpreter_sessions",
45                &self.request_options,
46            )
47            .await
48    }
49
50    /// Get completions usage details for the organization.
51    #[crate::byot(R = serde::de::DeserializeOwned)]
52    pub async fn completions(&self) -> Result<UsageResponse, OpenAIError> {
53        self.client
54            .get("/organization/usage/completions", &self.request_options)
55            .await
56    }
57
58    /// Get embeddings usage details for the organization.
59    #[crate::byot(R = serde::de::DeserializeOwned)]
60    pub async fn embeddings(&self) -> Result<UsageResponse, OpenAIError> {
61        self.client
62            .get("/organization/usage/embeddings", &self.request_options)
63            .await
64    }
65
66    /// Get images usage details for the organization.
67    #[crate::byot(R = serde::de::DeserializeOwned)]
68    pub async fn images(&self) -> Result<UsageResponse, OpenAIError> {
69        self.client
70            .get("/organization/usage/images", &self.request_options)
71            .await
72    }
73
74    /// Get moderations usage details for the organization.
75    #[crate::byot(R = serde::de::DeserializeOwned)]
76    pub async fn moderations(&self) -> Result<UsageResponse, OpenAIError> {
77        self.client
78            .get("/organization/usage/moderations", &self.request_options)
79            .await
80    }
81
82    /// Get vector stores usage details for the organization.
83    #[crate::byot(R = serde::de::DeserializeOwned)]
84    pub async fn vector_stores(&self) -> Result<UsageResponse, OpenAIError> {
85        self.client
86            .get("/organization/usage/vector_stores", &self.request_options)
87            .await
88    }
89
90    /// Get costs details for the organization.
91    #[crate::byot(R = serde::de::DeserializeOwned)]
92    pub async fn costs(&self) -> Result<UsageResponse, OpenAIError> {
93        self.client
94            .get("/organization/costs", &self.request_options)
95            .await
96    }
97}