1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//! Structures related to API Usage and Costs endpoints.
/// Define a private namespace for all its items.
mod private
{
// Serde imports
use serde::Deserialize;
/// Represents the monetary value and currency for a cost item.
///
/// # Used By
/// - `CostsResult`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct CostsResultAmount
{
/// Lowercase ISO-4217 currency code (e.g., "usd").
pub currency : String,
/// The numeric value of the cost.
pub value : f64,
}
/// Represents the aggregated cost details for a specific time bucket and grouping.
///
/// # Used By
/// - `UsageResult::Costs`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct CostsResult
{
/// The monetary value and currency.
pub amount : CostsResultAmount,
/// The invoice line item if grouped by `line_item`.
pub line_item : Option< String >,
/// Object type, always "organization.costs.result".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
}
/// Represents aggregated usage details for the Audio Speeches API within a time bucket.
///
/// # Used By
/// - `UsageResult::AudioSpeeches`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageAudioSpeechesResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// The number of characters processed.
pub characters : i32,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "`organization.usage.audio_speeches.result`".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for the Audio Transcriptions API within a time bucket.
///
/// # Used By
/// - `UsageResult::AudioTranscriptions`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageAudioTranscriptionsResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "`organization.usage.audio_transcriptions.result`".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The number of seconds processed.
pub seconds : i32,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for Code Interpreter sessions within a time bucket.
///
/// # Used By
/// - `UsageResult::CodeInterpreter`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageCodeInterpreterSessionsResult
{
/// The number of code interpreter sessions used.
pub num_sessions : i32, // Corrected field name from 'sessions' to 'num_sessions' based on example
/// Object type, always "`organization.usage.code_interpreter_sessions.result`".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
}
/// Represents aggregated usage details for the Completions API within a time bucket.
///
/// # Used By
/// - `UsageResult::Completions`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageCompletionsResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// Whether the usage result is for batch jobs if grouped by `batch`.
pub batch : Option< bool >,
/// Aggregated number of audio input tokens used (including cached).
pub input_audio_tokens : Option< i32 >,
/// Aggregated number of text input tokens used (including cached).
pub input_tokens : i32,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "organization.usage.completions.result".
pub object : String,
/// Aggregated number of audio output tokens used.
pub output_audio_tokens : Option< i32 >,
/// Aggregated number of text output tokens used.
pub output_tokens : i32,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// Aggregated number of cached text input tokens.
pub input_cached_tokens : Option< i32 >,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for the Embeddings API within a time bucket.
///
/// # Used By
/// - `UsageResult::Embeddings`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageEmbeddingsResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// The aggregated number of input tokens used.
pub input_tokens : i32,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "organization.usage.embeddings.result".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for the Images API within a time bucket.
///
/// # Used By
/// - `UsageResult::Images`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageImagesResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// The number of images processed.
pub images : i32,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "organization.usage.images.result".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The image size if grouped by `size` (e.g., "1024x1024").
pub size : Option< String >,
/// The source of the usage if grouped by `source` (e.g., "image.generation").
pub source : Option< String >,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for the Moderations API within a time bucket.
///
/// # Used By
/// - `UsageResult::Moderations`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageModerationsResult
{
/// The API key ID if grouped by `api_key_id`.
pub api_key_id : Option< String >,
/// The aggregated number of input tokens used.
pub input_tokens : i32,
/// The model name if grouped by `model`.
pub model : Option< String >,
/// The count of requests made to the model.
pub num_model_requests : i32,
/// Object type, always "organization.usage.moderations.result".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The user ID if grouped by `user_id`.
pub user_id : Option< String >,
}
/// Represents aggregated usage details for Vector Stores within a time bucket.
///
/// # Used By
/// - `UsageResult::VectorStores`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageVectorStoresResult
{
/// Object type, always "`organization.usage.vector_stores.result`".
pub object : String,
/// The project ID if grouped by `project_id`.
pub project_id : Option< String >,
/// The vector stores usage in bytes.
pub usage_bytes : i64,
}
/// Represents the aggregated usage or cost result within a time bucket, varying by endpoint.
///
/// # Used By
/// - `UsageTimeBucket`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ serde( untagged ) ]
#[ non_exhaustive ]
pub enum UsageResult
{
/// Audio Speeches API usage details.
AudioSpeeches( UsageAudioSpeechesResult ),
/// Audio Transcriptions API usage details.
AudioTranscriptions( UsageAudioTranscriptionsResult ),
/// Code Interpreter sessions usage details.
CodeInterpreter( UsageCodeInterpreterSessionsResult ),
/// Completions API usage details.
Completions( UsageCompletionsResult ),
/// Costs details.
Costs( CostsResult ),
/// Embeddings API usage details.
Embeddings( UsageEmbeddingsResult ),
/// Images API usage details.
Images( UsageImagesResult ),
/// Moderations API usage details.
Moderations( UsageModerationsResult ),
/// Vector Stores usage details.
VectorStores( UsageVectorStoresResult ),
}
/// Represents a time bucket containing aggregated usage or cost results.
///
/// # Used By
/// - `UsageResponse`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageTimeBucket
{
/// List of time buckets containing usage/cost data.
pub data : Vec< UsageResult >,
/// End timestamp of the bucket (Unix seconds).
pub end_time : i64,
/// Indicates if more data is available for pagination.
pub has_more : bool,
/// Pagination cursor for the next page.
pub next_page : Option< String >,
/// Object type, always "bucket".
pub object : String,
/// Start timestamp of the bucket (Unix seconds).
pub start_time : i64,
}
/// Represents the paginated response from a Usage or Costs API endpoint.
///
/// # Used By
/// - `/organization/costs` (GET)
/// - `/organization/usage/*` (GET endpoints)
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
#[ non_exhaustive ]
pub struct UsageResponse
{
/// List of time buckets containing usage/cost data.
pub data : Vec< UsageTimeBucket >,
/// Indicates if more data is available for pagination.
pub has_more : bool,
/// Pagination cursor for the next page.
pub next_page : Option< String >,
/// Object type, always "page".
pub object : String,
}
} // end mod private
crate ::mod_interface!
{
exposed use
{
CostsResultAmount,
CostsResult,
UsageAudioSpeechesResult,
UsageAudioTranscriptionsResult,
UsageCodeInterpreterSessionsResult,
UsageCompletionsResult,
UsageEmbeddingsResult,
UsageImagesResult,
UsageModerationsResult,
UsageVectorStoresResult,
UsageResult,
UsageTimeBucket,
UsageResponse
};
}