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
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct UsageBucket<U> {
/// The object type, which is always "bucket".
pub object: String,
/// Start time (Unix seconds) of the query time range, inclusive.
pub start_time: u32,
/// End time (Unix seconds) of the query time range, exclusive.
pub end_time: u32,
/// The usage data for this bucket.
pub results: Vec<U>,
}
#[derive(Serialize, Deserialize, Debug, Default, Builder, Clone, PartialEq)]
#[builder(name = "UsageParametersBuilder")]
#[builder(setter(into, strip_option), default)]
pub struct UsageParameters {
/// Start time (Unix seconds) of the query time range, inclusive.
pub start_time: u32,
/// End time (Unix seconds) of the query time range, exclusive.
pub end_time: Option<u32>,
/// Width of each time bucket in response. By default, return 1 day.
pub bucket_width: Option<BucketWidth>,
/// Return only usages for these sources.
pub sources: Option<Vec<ImageSource>>,
/// Return only usages for these image sizes.
pub sizes: Option<Vec<ImageSize>>,
/// Return only usage for these projects.
pub project_ids: Option<Vec<String>>,
/// Return only usage for these users.
pub user_ids: Option<Vec<String>>,
/// Return only usage for these API keys.
pub api_key_ids: Option<Vec<String>>,
/// Return only usage for these models.
pub models: Option<Vec<String>>,
/// If true, return batch jobs only. If false, return non-batch jobs only. By default, return both.
pub batch: Option<bool>,
/// Group the usage data by the specified fields.
pub group_by: Option<Vec<GroupBy>>,
/// Specifies the number of buckets to return.
pub limit: Option<u32>,
/// A cursor for use in pagination. Corresponding to the next_page field from the previous response.
pub page: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CompletionUsage {
/// The object type, which is always "organization.usage.completions.result".
pub object: String,
/// The aggregated number of text input tokens used, including cached tokens.
pub input_tokens: u32,
/// The aggregated number of text input tokens that has been cached from previous requests.
pub input_cached_tokens: u32,
/// The aggregated number of text output tokens used.
pub output_tokens: u32,
/// The aggregated number of audio input tokens used, including cached tokens.
pub input_audio_tokens: Option<u32>,
/// The aggregated number of audio output tokens used.
pub output_audio_tokens: Option<u32>,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
/// When group_by=batch, this field tells whether the grouped usage result is batch or not.
pub batch: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct EmbeddingUsage {
/// The object type, which is always "organization.usage.embeddings.result".
pub object: String,
/// The aggregated number of input tokens used.
pub input_tokens: u32,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ModerationUsage {
/// The object type, which is always "organization.usage.moderations.result".
pub object: String,
/// The aggregated number of input tokens used.
pub input_tokens: u32,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ImageUsage {
/// The object type, which is always "organization.usage.images.result".
pub object: String,
/// The number of images processed.
pub images: u32,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=source, this field provides the source of the grouped usage result.
pub source: Option<ImageSource>,
/// When group_by=size, this field provides the image size of the grouped usage result.
pub size: Option<ImageSize>,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct AudioSpeechUsage {
/// The object type, which is always "organization.usage.audio_speeches.result".
pub object: String,
/// The number of characters processed.
pub characters: u32,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct AudioTranscriptionUsage {
/// The object type, which is always "organization.usage.audio_transcriptions.result".
pub object: String,
/// The number of seconds processed.
pub seconds: u32,
/// The count of requests made to the model.
pub num_model_requests: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
/// When group_by=user_id, this field provides the user ID of the grouped usage result.
pub user_id: Option<String>,
/// When group_by=api_key_id, this field provides the API key ID of the grouped usage result.
pub api_key_id: Option<String>,
/// When group_by=model, this field provides the model name of the grouped usage result.
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct VectorStoreUsage {
/// The object type, which is always "organization.usage.vector_stores.result".
pub object: String,
/// The vector stores usage in bytes.
pub usage_bytes: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CodeInterpreterSessionUsage {
/// The object type, which is always "organization.usage.code_interpreter_sessions.result".
pub object: String,
/// The number of code interpreter sessions.
pub sessions: u32,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CostUsage {
/// The object type, which is always "organization.usage.code_interpreter_sessions.result".
pub object: String,
/// The monetary value in its associated currency.
pub amount: Amount,
/// When group_by=line_item, this field provides the line item of the grouped costs result.
pub line_item: Option<String>,
/// When group_by=project_id, this field provides the project ID of the grouped usage result.
pub project_id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum BucketWidth {
#[serde(rename = "1m")]
Minute,
#[serde(rename = "1h")]
Hour,
#[serde(rename = "1d")]
Day,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum GroupBy {
ProjectId,
UserId,
ApiKeyId,
Model,
Batch,
LineItem,
Size,
Source,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Amount {
/// The numeric value of the cost.
pub value: f32,
/// Lowercase ISO-4217 currency e.g. "usd"
pub currency: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ImageSource {
#[serde(rename = "image.generation")]
ImageGeneration,
#[serde(rename = "unsplimage.editash")]
ImageEdit,
#[serde(rename = "image.variation")]
ImageVariation,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ImageSize {
#[serde(rename = "256x256")]
Size256X256,
#[serde(rename = "512x512")]
Size512X512,
#[serde(rename = "1024x1024")]
Size1024X1024,
#[serde(rename = "1024x1536")]
Size1024X1536,
#[serde(rename = "1536x1024")]
Size1536X1024,
#[serde(rename = "1792x1024")]
Size1792X1024,
#[serde(rename = "1024x1792")]
Size1024X1792,
#[serde(rename = "auto")]
Auto,
}