openai-types 0.1.3

Typed OpenAI API models — zero dependencies beyond serde
Documentation
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
// AUTO-GENERATED by py2rust — do not edit.
// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
// Domain: audio
#![allow(unused_imports)]

use serde::{Deserialize, Serialize};
use super::*;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum SpeechCreateParamsResponseFormat {
    #[serde(rename = "mp3")]
    Mp3,
    #[serde(rename = "opus")]
    Opus,
    #[serde(rename = "aac")]
    Aac,
    #[serde(rename = "flac")]
    Flac,
    #[serde(rename = "wav")]
    Wav,
    #[serde(rename = "pcm")]
    Pcm,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum SpeechCreateParamsStreamFormat {
    #[serde(rename = "sse")]
    Sse,
    #[serde(rename = "audio")]
    Audio,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct SpeechCreateParams {
    /// The text to generate audio for. The maximum length is 4096 characters.
    pub input: String,
    /// One of the available [TTS models](https://platform.openai.com/docs/models#tts):
    pub model: String,
    /// The voice to use when generating the audio.
    pub voice: Voice,
    /// Control the voice of your generated audio with additional instructions.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub instructions: Option<String>,
    /// The format to audio in.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub response_format: Option<SpeechCreateParamsResponseFormat>,
    /// The speed of the generated audio.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub speed: Option<f64>,
    /// The format to stream the audio in.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub stream_format: Option<SpeechCreateParamsStreamFormat>,
}

/// Custom voice reference.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct VoiceID {
    /// The custom voice ID, e.g. `voice_1234`.
    pub id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum Voice {
    Alloy,
    Ash,
    Ballad,
    Coral,
    Echo,
    Sage,
    Shimmer,
    Verse,
    Marin,
    Cedar,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum SpeechModel {
    #[serde(rename = "tts-1")]
    Tts1,
    #[serde(rename = "tts-1-hd")]
    Tts1Hd,
    #[serde(rename = "gpt-4o-mini-tts")]
    Gpt4oMiniTts,
    #[serde(rename = "gpt-4o-mini-tts-2025-12-15")]
    Gpt4oMiniTts20251215,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct Logprob {
    /// The token in the transcription.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub token: Option<String>,
    /// The bytes of the token.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub bytes: Option<Vec<f64>>,
    /// The log probability of the token.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub logprob: Option<f64>,
}

/// Details about the input tokens billed for this request.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct UsageTokensInputTokenDetails {
    /// Number of audio tokens billed for this request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub audio_tokens: Option<i64>,
    /// Number of text tokens billed for this request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub text_tokens: Option<i64>,
}

/// Usage statistics for models billed by token usage.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct UsageTokens {
    /// Number of input tokens billed for this request.
    pub input_tokens: i64,
    /// Number of output tokens generated.
    pub output_tokens: i64,
    /// Total number of tokens used (input + output).
    pub total_tokens: i64,
    /// The type of the usage object. Always `tokens` for this variant.
    #[serde(rename = "type")]
    pub type_: String,
    /// Details about the input tokens billed for this request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub input_token_details: Option<UsageTokensInputTokenDetails>,
}

/// Usage statistics for models billed by audio input duration.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct UsageDuration {
    /// Duration of the input audio in seconds.
    pub seconds: f64,
    /// The type of the usage object. Always `duration` for this variant.
    #[serde(rename = "type")]
    pub type_: String,
}

pub type Usage = serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionCreateParamsBase {
    /// The audio file object (not file name) to transcribe, in one of these formats:
    pub file: serde_json::Value,
    /// ID of the model to use.
    pub model: String,
    /// Controls how the audio is cut into chunks.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub chunking_strategy: Option<ChunkingStrategy>,
    /// Additional information to include in the transcription response. `logprobs` will
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub include: Option<Vec<TranscriptionInclude>>,
    /// Optional list of speaker names that correspond to the audio samples provided in
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub known_speaker_names: Option<serde_json::Value>,
    /// Optional list of audio samples (as
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub known_speaker_references: Option<serde_json::Value>,
    /// The language of the input audio.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub language: Option<String>,
    /// An optional text to guide the model's style or continue a previous audio
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub prompt: Option<String>,
    /// The format of the output, in one of these options: `json`, `text`, `srt`,
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub response_format: Option<AudioResponseFormat>,
    /// The sampling temperature, between 0 and 1.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub temperature: Option<f64>,
    /// The timestamp granularities to populate for this transcription.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub timestamp_granularities: Option<Vec<serde_json::Value>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct ChunkingStrategyVadConfig {
    /// Must be set to `server_vad` to enable manual chunking using server side VAD.
    #[serde(rename = "type")]
    pub type_: String,
    /// Amount of audio to include before the VAD detected speech (in milliseconds).
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub prefix_padding_ms: Option<i64>,
    /// Duration of silence to detect speech stop (in milliseconds). With shorter values
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub silence_duration_ms: Option<i64>,
    /// Sensitivity threshold (0.0 to 1.0) for voice activity detection.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub threshold: Option<f64>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum ChunkingStrategy {
    Auto,
}

pub type TranscriptionCreateParams = serde_json::Value;

pub type TranscriptionCreateResponse = serde_json::Value;

/// Represents a diarized transcription response returned by the model, including the combined transcript and speaker-segment annotations.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionDiarized {
    /// Duration of the input audio in seconds.
    pub duration: f64,
    /// Segments of the transcript annotated with timestamps and speaker labels.
    pub segments: Vec<TranscriptionDiarizedSegment>,
    /// The type of task that was run. Always `transcribe`.
    pub task: String,
    /// The concatenated transcript text for the entire audio input.
    pub text: String,
    /// Token or duration usage statistics for the request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub usage: Option<Usage>,
}

/// A segment of diarized transcript text with speaker metadata.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionDiarizedSegment {
    /// Unique identifier for the segment.
    pub id: String,
    /// End timestamp of the segment in seconds.
    pub end: f64,
    /// Speaker label for this segment.
    pub speaker: String,
    /// Start timestamp of the segment in seconds.
    pub start: f64,
    /// Transcript text for this segment.
    pub text: String,
    /// The type of the segment. Always `transcript.text.segment`.
    #[serde(rename = "type")]
    pub type_: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum TranscriptionInclude {
    #[serde(rename = "logprobs")]
    Logprobs,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionSegment {
    /// Unique identifier of the segment.
    pub id: i64,
    /// Average logprob of the segment.
    pub avg_logprob: f64,
    /// Compression ratio of the segment.
    pub compression_ratio: f64,
    /// End time of the segment in seconds.
    pub end: f64,
    /// Probability of no speech in the segment.
    pub no_speech_prob: f64,
    /// Seek offset of the segment.
    pub seek: i64,
    /// Start time of the segment in seconds.
    pub start: f64,
    /// Temperature parameter used for generating the segment.
    pub temperature: f64,
    /// Text content of the segment.
    pub text: String,
    /// Array of token IDs for the text content.
    pub tokens: Vec<i64>,
}

pub type TranscriptionStreamEvent = serde_json::Value;

/// Emitted when there is an additional text delta.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionTextDeltaEvent {
    /// The text delta that was additionally transcribed.
    pub delta: String,
    /// The type of the event. Always `transcript.text.delta`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The log probabilities of the delta.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub logprobs: Option<Vec<Logprob>>,
    /// Identifier of the diarized segment that this delta belongs to.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub segment_id: Option<String>,
}

/// Details about the input tokens billed for this request.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct UsageInputTokenDetails {
    /// Number of audio tokens billed for this request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub audio_tokens: Option<i64>,
    /// Number of text tokens billed for this request.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub text_tokens: Option<i64>,
}

/// Emitted when the transcription is complete.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionTextDoneEvent {
    /// The text that was transcribed.
    pub text: String,
    /// The type of the event. Always `transcript.text.done`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The log probabilities of the individual tokens in the transcription.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub logprobs: Option<Vec<Logprob>>,
    /// Usage statistics for models billed by token usage.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub usage: Option<Usage>,
}

/// Emitted when a diarized transcription returns a completed segment with speaker information. Only emitted when you [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription) with `stream` set to `true` and `response_format` set to `diarized_json`.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionTextSegmentEvent {
    /// Unique identifier for the segment.
    pub id: String,
    /// End timestamp of the segment in seconds.
    pub end: f64,
    /// Speaker label for this segment.
    pub speaker: String,
    /// Start timestamp of the segment in seconds.
    pub start: f64,
    /// Transcript text for this segment.
    pub text: String,
    /// The type of the event. Always `transcript.text.segment`.
    #[serde(rename = "type")]
    pub type_: String,
}

/// Represents a verbose json transcription response returned by model, based on the provided input.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionVerbose {
    /// The duration of the input audio.
    pub duration: f64,
    /// The language of the input audio.
    pub language: String,
    /// The transcribed text.
    pub text: String,
    /// Segments of the transcribed text and their corresponding details.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub segments: Option<Vec<TranscriptionSegment>>,
    /// Usage statistics for models billed by audio input duration.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub usage: Option<Usage>,
    /// Extracted words and their corresponding timestamps.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub words: Option<Vec<TranscriptionWord>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranscriptionWord {
    /// End time of the word in seconds.
    pub end: f64,
    /// Start time of the word in seconds.
    pub start: f64,
    /// The text content of the word.
    pub word: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum TranslationCreateParamsResponseFormat {
    #[serde(rename = "json")]
    Json,
    #[serde(rename = "text")]
    Text,
    #[serde(rename = "srt")]
    Srt,
    #[serde(rename = "verbose_json")]
    VerboseJson,
    #[serde(rename = "vtt")]
    Vtt,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranslationCreateParams {
    /// The audio file object (not file name) translate, in one of these formats: flac,
    pub file: serde_json::Value,
    /// ID of the model to use.
    pub model: String,
    /// An optional text to guide the model's style or continue a previous audio
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub prompt: Option<String>,
    /// The format of the output, in one of these options: `json`, `text`, `srt`,
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub response_format: Option<TranslationCreateParamsResponseFormat>,
    /// The sampling temperature, between 0 and 1.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub temperature: Option<f64>,
}

pub type TranslationCreateResponse = serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TranslationVerbose {
    /// The duration of the input audio.
    pub duration: f64,
    /// The language of the output translation (always `english`).
    pub language: String,
    /// The translated text.
    pub text: String,
    /// Segments of the translated text and their corresponding details.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub segments: Option<Vec<TranscriptionSegment>>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum AudioModel {
    #[serde(rename = "whisper-1")]
    Whisper1,
    #[serde(rename = "gpt-4o-transcribe")]
    Gpt4oTranscribe,
    #[serde(rename = "gpt-4o-mini-transcribe")]
    Gpt4oMiniTranscribe,
    #[serde(rename = "gpt-4o-mini-transcribe-2025-12-15")]
    Gpt4oMiniTranscribe20251215,
    #[serde(rename = "gpt-4o-transcribe-diarize")]
    Gpt4oTranscribeDiarize,
}