Skip to main content

outfox_openai/spec/admin/usage/
usage_.rs

1use serde::Deserialize;
2
3/// Response structure for organization usage endpoints.
4#[derive(Debug, Clone, Deserialize)]
5pub struct UsageResponse {
6    /// The object type, which is always `page`.
7    pub object: String,
8    /// List of time buckets containing usage data.
9    pub data: Vec<UsageTimeBucket>,
10    /// Whether there are more pages available.
11    pub has_more: bool,
12    /// Cursor for the next page.
13    pub next_page: Option<String>,
14}
15
16/// A time bucket containing usage results.
17#[derive(Debug, Clone, Deserialize)]
18pub struct UsageTimeBucket {
19    /// The object type, which is always `bucket`.
20    pub object: String,
21    /// Start time of the bucket (Unix seconds).
22    pub start_time: u64,
23    /// End time of the bucket (Unix seconds).
24    pub end_time: u64,
25    /// Start time of the bucket in ISO 8601 format.
26    #[serde(default)]
27    pub start_time_iso: Option<String>,
28    /// End time of the bucket in ISO 8601 format.
29    #[serde(default)]
30    pub end_time_iso: Option<String>,
31    /// Usage results for this time bucket.
32    pub results: Vec<UsageResult>,
33}
34
35/// Discriminated union of all possible usage result types.
36#[derive(Debug, Clone, Deserialize)]
37#[serde(untagged)]
38pub enum UsageResult {
39    AudioSpeeches(UsageAudioSpeechesResult),
40    AudioTranscriptions(UsageAudioTranscriptionsResult),
41    CodeInterpreterSessions(UsageCodeInterpreterSessionsResult),
42    Completions(UsageCompletionsResult),
43    Embeddings(UsageEmbeddingsResult),
44    Images(UsageImagesResult),
45    Moderations(UsageModerationsResult),
46    VectorStores(UsageVectorStoresResult),
47    Costs(CostsResult),
48}
49
50/// The aggregated audio speeches usage details of the specific time bucket.
51#[derive(Debug, Clone, Deserialize)]
52pub struct UsageAudioSpeechesResult {
53    /// The object type, which is always `organization.usage.audio_speeches.result`.
54    pub object: String,
55    /// The number of characters processed.
56    pub characters: u64,
57    /// The count of requests made to the model.
58    pub num_model_requests: u64,
59    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
60    pub project_id: Option<String>,
61    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
62    pub user_id: Option<String>,
63    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
64    pub api_key_id: Option<String>,
65    /// When `group_by=model`, this field provides the model name of the grouped usage result.
66    pub model: Option<String>,
67}
68
69/// The aggregated audio transcriptions usage details of the specific time bucket.
70#[derive(Debug, Clone, Deserialize)]
71pub struct UsageAudioTranscriptionsResult {
72    /// The object type, which is always `organization.usage.audio_transcriptions.result`.
73    pub object: String,
74    /// The number of seconds processed.
75    pub seconds: u64,
76    /// The count of requests made to the model.
77    pub num_model_requests: u64,
78    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
79    pub project_id: Option<String>,
80    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
81    pub user_id: Option<String>,
82    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
83    pub api_key_id: Option<String>,
84    /// When `group_by=model`, this field provides the model name of the grouped usage result.
85    pub model: Option<String>,
86}
87
88/// The aggregated code interpreter sessions usage details of the specific time bucket.
89#[derive(Debug, Clone, Deserialize)]
90pub struct UsageCodeInterpreterSessionsResult {
91    /// The object type, which is always `organization.usage.code_interpreter_sessions.result`.
92    pub object: String,
93    /// The number of code interpreter sessions.
94    pub num_sessions: u64,
95    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
96    pub project_id: Option<String>,
97    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
98    pub api_key_id: Option<String>,
99}
100
101/// The aggregated completions usage details of the specific time bucket.
102#[derive(Debug, Clone, Deserialize)]
103pub struct UsageCompletionsResult {
104    /// The object type, which is always `organization.usage.completions.result`.
105    pub object: String,
106    /// The aggregated number of text input tokens used, including cached tokens. For customers
107    /// subscribe to scale tier, this includes scale tier tokens.
108    pub input_tokens: u64,
109    /// The aggregated number of text output tokens used. For customers subscribe to scale tier,
110    /// this includes scale tier tokens.
111    pub output_tokens: u64,
112    /// The aggregated number of text input tokens that has been cached from previous requests. For
113    /// customers subscribe to scale tier, this includes scale tier tokens.
114    #[serde(default)]
115    pub input_cached_tokens: Option<u64>,
116    /// The aggregated number of uncached input tokens.
117    #[serde(default)]
118    pub input_uncached_tokens: Option<u64>,
119    /// The aggregated number of text input tokens used.
120    #[serde(default)]
121    pub input_text_tokens: Option<u64>,
122    /// The aggregated number of text output tokens used.
123    #[serde(default)]
124    pub output_text_tokens: Option<u64>,
125    /// The aggregated number of cached text input tokens.
126    #[serde(default)]
127    pub input_cached_text_tokens: Option<u64>,
128    /// The aggregated number of audio input tokens used, including cached tokens.
129    #[serde(default)]
130    pub input_audio_tokens: Option<u64>,
131    /// The aggregated number of cached audio input tokens.
132    #[serde(default)]
133    pub input_cached_audio_tokens: Option<u64>,
134    /// The aggregated number of audio output tokens used.
135    #[serde(default)]
136    pub output_audio_tokens: Option<u64>,
137    /// The aggregated number of image input tokens used.
138    #[serde(default)]
139    pub input_image_tokens: Option<u64>,
140    /// The aggregated number of cached image input tokens.
141    #[serde(default)]
142    pub input_cached_image_tokens: Option<u64>,
143    /// The aggregated number of image output tokens used.
144    #[serde(default)]
145    pub output_image_tokens: Option<u64>,
146    /// The count of requests made to the model.
147    pub num_model_requests: u64,
148    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
149    pub project_id: Option<String>,
150    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
151    pub user_id: Option<String>,
152    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
153    pub api_key_id: Option<String>,
154    /// When `group_by=model`, this field provides the model name of the grouped usage result.
155    pub model: Option<String>,
156    /// When `group_by=batch`, this field tells whether the grouped usage result is batch or not.
157    pub batch: Option<bool>,
158    /// When `group_by=service_tier`, this field provides the service tier of the grouped usage
159    /// result.
160    pub service_tier: Option<String>,
161}
162
163/// The aggregated embeddings usage details of the specific time bucket.
164#[derive(Debug, Clone, Deserialize)]
165pub struct UsageEmbeddingsResult {
166    /// The object type, which is always `organization.usage.embeddings.result`.
167    pub object: String,
168    /// The aggregated number of input tokens used.
169    pub input_tokens: u64,
170    /// The count of requests made to the model.
171    pub num_model_requests: u64,
172    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
173    pub project_id: Option<String>,
174    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
175    pub user_id: Option<String>,
176    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
177    pub api_key_id: Option<String>,
178    /// When `group_by=model`, this field provides the model name of the grouped usage result.
179    pub model: Option<String>,
180}
181
182/// The aggregated images usage details of the specific time bucket.
183#[derive(Debug, Clone, Deserialize)]
184pub struct UsageImagesResult {
185    /// The object type, which is always `organization.usage.images.result`.
186    pub object: String,
187    /// The number of images processed.
188    pub images: u64,
189    /// The count of requests made to the model.
190    pub num_model_requests: u64,
191    /// When `group_by=source`, this field provides the source of the grouped usage result,
192    /// possible values are `image.generation`, `image.edit`, `image.variation`.
193    pub source: Option<String>,
194    /// When `group_by=size`, this field provides the image size of the grouped usage result.
195    pub size: Option<String>,
196    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
197    pub project_id: Option<String>,
198    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
199    pub user_id: Option<String>,
200    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
201    pub api_key_id: Option<String>,
202    /// When `group_by=model`, this field provides the model name of the grouped usage result.
203    pub model: Option<String>,
204}
205
206/// The aggregated moderations usage details of the specific time bucket.
207#[derive(Debug, Clone, Deserialize)]
208pub struct UsageModerationsResult {
209    /// The object type, which is always `organization.usage.moderations.result`.
210    pub object: String,
211    /// The aggregated number of input tokens used.
212    pub input_tokens: u64,
213    /// The count of requests made to the model.
214    pub num_model_requests: u64,
215    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
216    pub project_id: Option<String>,
217    /// When `group_by=user_id`, this field provides the user ID of the grouped usage result.
218    pub user_id: Option<String>,
219    /// When `group_by=api_key_id`, this field provides the API key ID of the grouped usage result.
220    pub api_key_id: Option<String>,
221    /// When `group_by=model`, this field provides the model name of the grouped usage result.
222    pub model: Option<String>,
223}
224
225/// The aggregated vector stores usage details of the specific time bucket.
226#[derive(Debug, Clone, Deserialize)]
227pub struct UsageVectorStoresResult {
228    /// The object type, which is always `organization.usage.vector_stores.result`.
229    pub object: String,
230    /// The vector stores usage in bytes.
231    pub usage_bytes: u64,
232    /// When `group_by=project_id`, this field provides the project ID of the grouped usage result.
233    pub project_id: Option<String>,
234}
235
236/// The aggregated costs details of the specific time bucket.
237#[derive(Debug, Clone, Deserialize)]
238pub struct CostsResult {
239    /// The object type, which is always `organization.costs.result`.
240    pub object: String,
241    /// The monetary value in its associated currency.
242    pub amount: CostsAmount,
243    /// When `group_by=line_item`, this field provides the line item of the grouped costs result.
244    pub line_item: Option<String>,
245    /// When `group_by=project_id`, this field provides the project ID of the grouped costs result.
246    pub project_id: Option<String>,
247    /// The organization ID.
248    #[serde(default)]
249    pub organization_id: Option<String>,
250}
251
252/// The monetary value in its associated currency.
253#[derive(Debug, Clone, Deserialize)]
254pub struct CostsAmount {
255    /// The numeric value of the cost.
256    pub value: f64,
257    /// Lowercase ISO-4217 currency e.g. "usd"
258    pub currency: String,
259}