Skip to main content

outfox_openai/admin/
usage.rs

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