async_openai/types/admin/
usage.rs

1use serde::{Deserialize, Serialize};
2
3/// Width of each time bucket in response.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5#[serde(rename_all = "lowercase")]
6pub enum UsageBucketWidth {
7    #[serde(rename = "1m")]
8    OneMinute,
9    #[serde(rename = "1h")]
10    OneHour,
11    #[serde(rename = "1d")]
12    OneDay,
13}
14
15/// Fields to group usage data by.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(rename_all = "snake_case")]
18pub enum UsageGroupBy {
19    ProjectId,
20    UserId,
21    ApiKeyId,
22    Model,
23    Batch,
24    ServiceTier,
25}
26
27/// Query parameters for organization usage endpoints.
28#[derive(Debug, Clone, Serialize, Default)]
29pub struct UsageQueryParams {
30    /// Start time (Unix seconds) of the query time range, inclusive.
31    pub start_time: u64,
32    /// End time (Unix seconds) of the query time range, exclusive.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub end_time: Option<u64>,
35    /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub bucket_width: Option<UsageBucketWidth>,
38    /// Return only usage for these projects.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub project_ids: Option<Vec<String>>,
41    /// Return only usage for these users.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub user_ids: Option<Vec<String>>,
44    /// Return only usage for these API keys.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub api_key_ids: Option<Vec<String>>,
47    /// Return only usage for these models.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub models: Option<Vec<String>>,
50    /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default, return both.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub batch: Option<bool>,
53    /// Group the usage data by the specified fields.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub group_by: Option<Vec<UsageGroupBy>>,
56    /// Specifies the number of buckets to return.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub limit: Option<u32>,
59    /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous response.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub page: Option<String>,
62}
63
64/// Response structure for organization usage endpoints.
65#[derive(Debug, Clone, Deserialize)]
66pub struct UsageResponse {
67    /// The object type, which is always `page`.
68    pub object: String,
69    /// List of time buckets containing usage data.
70    pub data: Vec<UsageTimeBucket>,
71    /// Whether there are more pages available.
72    pub has_more: bool,
73    /// Cursor for the next page.
74    pub next_page: Option<String>,
75}
76
77/// A time bucket containing usage results.
78#[derive(Debug, Clone, Deserialize)]
79pub struct UsageTimeBucket {
80    /// The object type, which is always `bucket`.
81    pub object: String,
82    /// Start time of the bucket (Unix seconds).
83    pub start_time: u64,
84    /// End time of the bucket (Unix seconds).
85    pub end_time: u64,
86    /// Start time of the bucket in ISO 8601 format.
87    #[serde(default)]
88    pub start_time_iso: Option<String>,
89    /// End time of the bucket in ISO 8601 format.
90    #[serde(default)]
91    pub end_time_iso: Option<String>,
92    /// Usage results for this time bucket.
93    pub results: Vec<UsageResult>,
94}
95
96/// Discriminated union of all possible usage result types.
97#[derive(Debug, Clone, Deserialize)]
98#[serde(untagged)]
99pub enum UsageResult {
100    AudioSpeeches(UsageAudioSpeechesResult),
101    AudioTranscriptions(UsageAudioTranscriptionsResult),
102    CodeInterpreterSessions(UsageCodeInterpreterSessionsResult),
103    Completions(UsageCompletionsResult),
104    Embeddings(UsageEmbeddingsResult),
105    Images(UsageImagesResult),
106    Moderations(UsageModerationsResult),
107    VectorStores(UsageVectorStoresResult),
108    Costs(CostsResult),
109}
110
111/// The aggregated audio speeches usage details of the specific time bucket.
112#[derive(Debug, Clone, Deserialize)]
113pub struct UsageAudioSpeechesResult {
114    /// The object type, which is always `organization.usage.audio_speeches.result`.
115    pub object: String,
116    /// The number of characters processed.
117    pub characters: u64,
118    /// The count of requests made to the model.
119    pub num_model_requests: u64,
120    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
121    pub project_id: Option<String>,
122    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
123    pub user_id: Option<String>,
124    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
125    pub api_key_id: Option<String>,
126    /// When `group_by=model`, this field provides the model name of the grouped usage result.
127    pub model: Option<String>,
128}
129
130/// The aggregated audio transcriptions usage details of the specific time bucket.
131#[derive(Debug, Clone, Deserialize)]
132pub struct UsageAudioTranscriptionsResult {
133    /// The object type, which is always `organization.usage.audio_transcriptions.result`.
134    pub object: String,
135    /// The number of seconds processed.
136    pub seconds: u64,
137    /// The count of requests made to the model.
138    pub num_model_requests: u64,
139    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
140    pub project_id: Option<String>,
141    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
142    pub user_id: Option<String>,
143    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
144    pub api_key_id: Option<String>,
145    /// When `group_by=model`, this field provides the model name of the grouped usage result.
146    pub model: Option<String>,
147}
148
149/// The aggregated code interpreter sessions usage details of the specific time bucket.
150#[derive(Debug, Clone, Deserialize)]
151pub struct UsageCodeInterpreterSessionsResult {
152    /// The object type, which is always `organization.usage.code_interpreter_sessions.result`.
153    pub object: String,
154    /// The number of code interpreter sessions.
155    pub num_sessions: u64,
156    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
157    pub project_id: Option<String>,
158    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
159    pub api_key_id: Option<String>,
160}
161
162/// The aggregated completions usage details of the specific time bucket.
163#[derive(Debug, Clone, Deserialize)]
164pub struct UsageCompletionsResult {
165    /// The object type, which is always `organization.usage.completions.result`.
166    pub object: String,
167    /// The aggregated number of text input tokens used, including cached tokens. For customers subscribe to scale tier, this includes scale tier tokens.
168    pub input_tokens: u64,
169    /// The aggregated number of text output tokens used. For customers subscribe to scale tier, this includes scale tier tokens.
170    pub output_tokens: u64,
171    /// The aggregated number of text input tokens that has been cached from previous requests. For customers subscribe to scale tier, this includes scale tier tokens.
172    #[serde(default)]
173    pub input_cached_tokens: Option<u64>,
174    /// The aggregated number of uncached input tokens.
175    #[serde(default)]
176    pub input_uncached_tokens: Option<u64>,
177    /// The aggregated number of text input tokens used.
178    #[serde(default)]
179    pub input_text_tokens: Option<u64>,
180    /// The aggregated number of text output tokens used.
181    #[serde(default)]
182    pub output_text_tokens: Option<u64>,
183    /// The aggregated number of cached text input tokens.
184    #[serde(default)]
185    pub input_cached_text_tokens: Option<u64>,
186    /// The aggregated number of audio input tokens used, including cached tokens.
187    #[serde(default)]
188    pub input_audio_tokens: Option<u64>,
189    /// The aggregated number of cached audio input tokens.
190    #[serde(default)]
191    pub input_cached_audio_tokens: Option<u64>,
192    /// The aggregated number of audio output tokens used.
193    #[serde(default)]
194    pub output_audio_tokens: Option<u64>,
195    /// The aggregated number of image input tokens used.
196    #[serde(default)]
197    pub input_image_tokens: Option<u64>,
198    /// The aggregated number of cached image input tokens.
199    #[serde(default)]
200    pub input_cached_image_tokens: Option<u64>,
201    /// The aggregated number of image output tokens used.
202    #[serde(default)]
203    pub output_image_tokens: Option<u64>,
204    /// The count of requests made to the model.
205    pub num_model_requests: u64,
206    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
207    pub project_id: Option<String>,
208    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
209    pub user_id: Option<String>,
210    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
211    pub api_key_id: Option<String>,
212    /// When `group_by=model`, this field provides the model name of the grouped usage result.
213    pub model: Option<String>,
214    /// When `group_by=batch`, this field tells whether the grouped usage result is batch or not.
215    pub batch: Option<bool>,
216    /// When `group_by=service_tier`, this field provides the service tier of the grouped usage result.
217    pub service_tier: Option<String>,
218}
219
220/// The aggregated embeddings usage details of the specific time bucket.
221#[derive(Debug, Clone, Deserialize)]
222pub struct UsageEmbeddingsResult {
223    /// The object type, which is always `organization.usage.embeddings.result`.
224    pub object: String,
225    /// The aggregated number of input tokens used.
226    pub input_tokens: u64,
227    /// The count of requests made to the model.
228    pub num_model_requests: u64,
229    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
230    pub project_id: Option<String>,
231    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
232    pub user_id: Option<String>,
233    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
234    pub api_key_id: Option<String>,
235    /// When `group_by=model`, this field provides the model name of the grouped usage result.
236    pub model: Option<String>,
237}
238
239/// The aggregated images usage details of the specific time bucket.
240#[derive(Debug, Clone, Deserialize)]
241pub struct UsageImagesResult {
242    /// The object type, which is always `organization.usage.images.result`.
243    pub object: String,
244    /// The number of images processed.
245    pub images: u64,
246    /// The count of requests made to the model.
247    pub num_model_requests: u64,
248    /// When `group_by=source`, this field provides the source of the grouped usage result, possible values are `image.generation`, `image.edit`, `image.variation`.
249    pub source: Option<String>,
250    /// When `group_by=size`, this field provides the image size of the grouped usage result.
251    pub size: Option<String>,
252    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
253    pub project_id: Option<String>,
254    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
255    pub user_id: Option<String>,
256    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
257    pub api_key_id: Option<String>,
258    /// When `group_by=model`, this field provides the model name of the grouped usage result.
259    pub model: Option<String>,
260}
261
262/// The aggregated moderations usage details of the specific time bucket.
263#[derive(Debug, Clone, Deserialize)]
264pub struct UsageModerationsResult {
265    /// The object type, which is always `organization.usage.moderations.result`.
266    pub object: String,
267    /// The aggregated number of input tokens used.
268    pub input_tokens: u64,
269    /// The count of requests made to the model.
270    pub num_model_requests: u64,
271    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
272    pub project_id: Option<String>,
273    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
274    pub user_id: Option<String>,
275    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
276    pub api_key_id: Option<String>,
277    /// When `group_by=model`, this field provides the model name of the grouped usage result.
278    pub model: Option<String>,
279}
280
281/// The aggregated vector stores usage details of the specific time bucket.
282#[derive(Debug, Clone, Deserialize)]
283pub struct UsageVectorStoresResult {
284    /// The object type, which is always `organization.usage.vector_stores.result`.
285    pub object: String,
286    /// The vector stores usage in bytes.
287    pub usage_bytes: u64,
288    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
289    pub project_id: Option<String>,
290}
291
292/// The aggregated costs details of the specific time bucket.
293#[derive(Debug, Clone, Deserialize)]
294pub struct CostsResult {
295    /// The object type, which is always `organization.costs.result`.
296    pub object: String,
297    /// The monetary value in its associated currency.
298    pub amount: CostsAmount,
299    /// When `group_by=line_item`, this field provides the line item of the grouped costs result.
300    pub line_item: Option<String>,
301    /// When `group_by=project_id`, this field provides the project ID of the grouped costs result.
302    pub project_id: Option<String>,
303    /// The organization ID.
304    #[serde(default)]
305    pub organization_id: Option<String>,
306}
307
308/// The monetary value in its associated currency.
309#[derive(Debug, Clone, Deserialize)]
310pub struct CostsAmount {
311    /// The numeric value of the cost.
312    pub value: f64,
313    /// Lowercase ISO-4217 currency e.g. "usd"
314    pub currency: String,
315}