async-openai 0.42.0

Rust library for OpenAI
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
use serde::{Deserialize, Serialize};

use crate::types::responses::{
    Annotation, FunctionShellCallOutputContent, OutputContent, OutputItem, Response,
    ResponseLogProb, SummaryPart,
};

/// Event types for streaming responses from the Responses API
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type")]
pub enum ResponseStreamEvent {
    /// Emitted when there is a partial audio response.
    #[serde(rename = "response.audio.delta")]
    ResponseAudioDelta(ResponseAudioDeltaEvent),
    /// Emitted when the audio response is complete.
    #[serde(rename = "response.audio.done")]
    ResponseAudioDone(ResponseAudioDoneEvent),
    /// Emitted when there is a partial transcript of audio.
    #[serde(rename = "response.audio.transcript.delta")]
    ResponseAudioTranscriptDelta(ResponseAudioTranscriptDeltaEvent),
    /// Emitted when the full audio transcript is completed.
    #[serde(rename = "response.audio.transcript.done")]
    ResponseAudioTranscriptDone(ResponseAudioTranscriptDoneEvent),
    /// An event that is emitted when a response is created.
    #[serde(rename = "response.created")]
    ResponseCreated(ResponseCreatedEvent),
    /// Emitted when the response is in progress.
    #[serde(rename = "response.in_progress")]
    ResponseInProgress(ResponseInProgressEvent),
    /// Emitted when the model response is complete.
    #[serde(rename = "response.completed")]
    ResponseCompleted(ResponseCompletedEvent),
    /// An event that is emitted when a response fails.
    #[serde(rename = "response.failed")]
    ResponseFailed(ResponseFailedEvent),
    /// An event that is emitted when a response finishes as incomplete.
    #[serde(rename = "response.incomplete")]
    ResponseIncomplete(ResponseIncompleteEvent),
    /// Emitted when a new output item is added.
    #[serde(rename = "response.output_item.added")]
    ResponseOutputItemAdded(ResponseOutputItemAddedEvent),
    /// Emitted when an output item is marked done.
    #[serde(rename = "response.output_item.done")]
    ResponseOutputItemDone(ResponseOutputItemDoneEvent),
    /// Emitted when a new content part is added.
    #[serde(rename = "response.content_part.added")]
    ResponseContentPartAdded(ResponseContentPartAddedEvent),
    /// Emitted when a content part is done.
    #[serde(rename = "response.content_part.done")]
    ResponseContentPartDone(ResponseContentPartDoneEvent),
    /// Emitted when there is an additional text delta.
    #[serde(rename = "response.output_text.delta")]
    ResponseOutputTextDelta(ResponseTextDeltaEvent),
    /// Emitted when text content is finalized.
    #[serde(rename = "response.output_text.done")]
    ResponseOutputTextDone(ResponseTextDoneEvent),
    /// Emitted when there is a partial refusal text.
    #[serde(rename = "response.refusal.delta")]
    ResponseRefusalDelta(ResponseRefusalDeltaEvent),
    #[serde(rename = "response.refusal.done")]
    /// Emitted when refusal text is finalized.
    ResponseRefusalDone(ResponseRefusalDoneEvent),
    /// Emitted when there is a partial function-call arguments delta.
    #[serde(rename = "response.function_call_arguments.delta")]
    ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDeltaEvent),
    /// Emitted when function-call arguments are finalized.
    #[serde(rename = "response.function_call_arguments.done")]
    ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDoneEvent),
    /// Emitted when a file search call is initiated.
    #[serde(rename = "response.file_search_call.in_progress")]
    ResponseFileSearchCallInProgress(ResponseFileSearchCallInProgressEvent),
    /// Emitted when a file search is currently searching.
    #[serde(rename = "response.file_search_call.searching")]
    ResponseFileSearchCallSearching(ResponseFileSearchCallSearchingEvent),
    /// Emitted when a file search call is completed (results found).
    #[serde(rename = "response.file_search_call.completed")]
    ResponseFileSearchCallCompleted(ResponseFileSearchCallCompletedEvent),
    /// Emitted when a web search call is initiated.
    #[serde(rename = "response.web_search_call.in_progress")]
    ResponseWebSearchCallInProgress(ResponseWebSearchCallInProgressEvent),
    /// Emitted when a web search call is executing.
    #[serde(rename = "response.web_search_call.searching")]
    ResponseWebSearchCallSearching(ResponseWebSearchCallSearchingEvent),
    /// Emitted when a web search call is completed.
    #[serde(rename = "response.web_search_call.completed")]
    ResponseWebSearchCallCompleted(ResponseWebSearchCallCompletedEvent),
    /// Emitted when a new reasoning summary part is added.
    #[serde(rename = "response.reasoning_summary_part.added")]
    ResponseReasoningSummaryPartAdded(ResponseReasoningSummaryPartAddedEvent),
    /// Emitted when a reasoning summary part is completed.
    #[serde(rename = "response.reasoning_summary_part.done")]
    ResponseReasoningSummaryPartDone(ResponseReasoningSummaryPartDoneEvent),
    /// Emitted when a delta is added to a reasoning summary text.
    #[serde(rename = "response.reasoning_summary_text.delta")]
    ResponseReasoningSummaryTextDelta(ResponseReasoningSummaryTextDeltaEvent),
    /// Emitted when a reasoning summary text is completed.
    #[serde(rename = "response.reasoning_summary_text.done")]
    ResponseReasoningSummaryTextDone(ResponseReasoningSummaryTextDoneEvent),
    /// Emitted when a delta is added to a reasoning text.
    #[serde(rename = "response.reasoning_text.delta")]
    ResponseReasoningTextDelta(ResponseReasoningTextDeltaEvent),
    /// Emitted when a reasoning text is completed.
    #[serde(rename = "response.reasoning_text.done")]
    ResponseReasoningTextDone(ResponseReasoningTextDoneEvent),
    /// Emitted when an image generation tool call has completed and the final image is available.
    #[serde(rename = "response.image_generation_call.completed")]
    ResponseImageGenerationCallCompleted(ResponseImageGenCallCompletedEvent),
    /// Emitted when an image generation tool call is actively generating an image (intermediate state).
    #[serde(rename = "response.image_generation_call.generating")]
    ResponseImageGenerationCallGenerating(ResponseImageGenCallGeneratingEvent),
    /// Emitted when an image generation tool call is in progress.
    #[serde(rename = "response.image_generation_call.in_progress")]
    ResponseImageGenerationCallInProgress(ResponseImageGenCallInProgressEvent),
    /// Emitted when a partial image is available during image generation streaming.
    #[serde(rename = "response.image_generation_call.partial_image")]
    ResponseImageGenerationCallPartialImage(ResponseImageGenCallPartialImageEvent),
    /// Emitted when there is a delta (partial update) to the arguments of an MCP tool call.
    #[serde(rename = "response.mcp_call_arguments.delta")]
    ResponseMCPCallArgumentsDelta(ResponseMCPCallArgumentsDeltaEvent),
    /// Emitted when the arguments for an MCP tool call are finalized.
    #[serde(rename = "response.mcp_call_arguments.done")]
    ResponseMCPCallArgumentsDone(ResponseMCPCallArgumentsDoneEvent),
    /// Emitted when an MCP tool call has completed successfully.
    #[serde(rename = "response.mcp_call.completed")]
    ResponseMCPCallCompleted(ResponseMCPCallCompletedEvent),
    /// Emitted when an MCP tool call has failed.
    #[serde(rename = "response.mcp_call.failed")]
    ResponseMCPCallFailed(ResponseMCPCallFailedEvent),
    /// Emitted when an MCP tool call is in progress.
    #[serde(rename = "response.mcp_call.in_progress")]
    ResponseMCPCallInProgress(ResponseMCPCallInProgressEvent),
    /// Emitted when the list of available MCP tools has been successfully retrieved.
    #[serde(rename = "response.mcp_list_tools.completed")]
    ResponseMCPListToolsCompleted(ResponseMCPListToolsCompletedEvent),
    /// Emitted when the attempt to list available MCP tools has failed.
    #[serde(rename = "response.mcp_list_tools.failed")]
    ResponseMCPListToolsFailed(ResponseMCPListToolsFailedEvent),
    /// Emitted when the system is in the process of retrieving the list of available MCP tools.
    #[serde(rename = "response.mcp_list_tools.in_progress")]
    ResponseMCPListToolsInProgress(ResponseMCPListToolsInProgressEvent),
    /// Emitted when a code interpreter call is in progress.
    #[serde(rename = "response.code_interpreter_call.in_progress")]
    ResponseCodeInterpreterCallInProgress(ResponseCodeInterpreterCallInProgressEvent),
    /// Emitted when the code interpreter is actively interpreting the code snippet.
    #[serde(rename = "response.code_interpreter_call.interpreting")]
    ResponseCodeInterpreterCallInterpreting(ResponseCodeInterpreterCallInterpretingEvent),
    /// Emitted when the code interpreter call is completed.
    #[serde(rename = "response.code_interpreter_call.completed")]
    ResponseCodeInterpreterCallCompleted(ResponseCodeInterpreterCallCompletedEvent),
    /// Emitted when a partial code snippet is streamed by the code interpreter.
    #[serde(rename = "response.code_interpreter_call_code.delta")]
    ResponseCodeInterpreterCallCodeDelta(ResponseCodeInterpreterCallCodeDeltaEvent),
    /// Emitted when the code snippet is finalized by the code interpreter.
    #[serde(rename = "response.code_interpreter_call_code.done")]
    ResponseCodeInterpreterCallCodeDone(ResponseCodeInterpreterCallCodeDoneEvent),
    /// Emitted when an annotation is added to output text content.
    #[serde(rename = "response.output_text.annotation.added")]
    ResponseOutputTextAnnotationAdded(ResponseOutputTextAnnotationAddedEvent),
    /// Emitted when a response is queued and waiting to be processed.
    #[serde(rename = "response.queued")]
    ResponseQueued(ResponseQueuedEvent),
    /// Event representing a delta (partial update) to the input of a custom tool call.
    #[serde(rename = "response.custom_tool_call_input.delta")]
    ResponseCustomToolCallInputDelta(ResponseCustomToolCallInputDeltaEvent),
    /// Event indicating that input for a custom tool call is complete.
    #[serde(rename = "response.custom_tool_call_input.done")]
    ResponseCustomToolCallInputDone(ResponseCustomToolCallInputDoneEvent),
    /// Emitted when an error occurs.
    #[serde(rename = "error")]
    ResponseError(ResponseErrorEvent),
    #[serde(rename = "response.shell_call_command.added")]
    ResponseShellCallCommandAdded(ResponseShellCallCommandAddedStreamingEvent),
    #[serde(rename = "response.shell_call_command.delta")]
    ResponseShellCallCommandDelta(ResponseShellCallCommandDeltaStreamingEvent),
    #[serde(rename = "response.shell_call_command.done")]
    ResponseShellCallCommandDone(ResponseShellCallCommandDoneStreamingEvent),
    #[serde(rename = "response.shell_call_output_content.delta")]
    ResponseShellCallOutputContentDelta(ResponseShellCallOutputContentDeltaStreamingEvent),
    #[serde(rename = "response.shell_call_output_content.done")]
    ResponseShellCallOutputContentDone(ResponseShellCallOutputContentDoneStreamingEvent),
}

/// Emitted when there is a partial audio response.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseAudioDeltaEvent {
    /// A sequence number for this chunk of the stream response.
    pub sequence_number: u64,
    /// A chunk of Base64 encoded response audio bytes.
    pub delta: String,
}

/// Emitted when the audio response is complete.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseAudioDoneEvent {
    /// The sequence number of the delta.
    pub sequence_number: u64,
    /// The ID of the response associated with this event.
    pub response_id: String,
}

/// Emitted when there is a partial transcript of audio.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseAudioTranscriptDeltaEvent {
    /// The partial transcript of the audio response.
    pub delta: String,
    /// The sequence number of this event.
    pub sequence_number: u64,
    /// The ID of the response associated with this event.
    pub response_id: String,
}

/// Emitted when the full audio transcript is completed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseAudioTranscriptDoneEvent {
    /// The sequence number of this event.
    pub sequence_number: u64,
    /// The ID of the response associated with this event.
    pub response_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCreatedEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseInProgressEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCompletedEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFailedEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseIncompleteEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseOutputItemAddedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    /// The output item that was added. For reasoning items, `encrypted_content`
    /// may be incomplete while the item is in progress. Use the reasoning item
    /// from the corresponding `response.output_item.done` event when passing it
    /// as input to a subsequent request.
    pub item: OutputItem,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseOutputItemDoneEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item: OutputItem,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseContentPartAddedEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub part: OutputContent,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseContentPartDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub part: OutputContent,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseTextDeltaEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub delta: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub logprobs: Option<Vec<ResponseLogProb>>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseTextDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub text: String,
    pub logprobs: Option<Vec<ResponseLogProb>>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseRefusalDeltaEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseRefusalDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub refusal: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFunctionCallArgumentsDeltaEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFunctionCallArgumentsDoneEvent {
    /// <https://github.com/64bit/async-openai/issues/472>
    pub name: Option<String>,
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub arguments: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFileSearchCallInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFileSearchCallSearchingEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseFileSearchCallCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseWebSearchCallInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseWebSearchCallSearchingEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseWebSearchCallCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningSummaryPartAddedEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub summary_index: u32,
    pub part: SummaryPart,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningSummaryPartDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub summary_index: u32,
    pub part: SummaryPart,
    /// The completion status of the summary part. Omitted when the part completed
    /// normally and set to `incomplete` when generation was interrupted.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningSummaryTextDeltaEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub summary_index: u32,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningSummaryTextDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub summary_index: u32,
    pub text: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningTextDeltaEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseReasoningTextDoneEvent {
    pub sequence_number: u64,
    pub item_id: String,
    pub output_index: u32,
    pub content_index: u32,
    pub text: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseImageGenCallCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseImageGenCallGeneratingEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseImageGenCallInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseImageGenCallPartialImageEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub partial_image_index: u32,
    pub partial_image_b64: String,
    /// The image size that was used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<String>,

    /// The image quality that was used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quality: Option<String>,

    /// The background setting that was used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub background: Option<String>,

    /// The output format that was used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub output_format: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPCallArgumentsDeltaEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPCallArgumentsDoneEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub arguments: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPCallCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPCallFailedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPCallInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPListToolsCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPListToolsFailedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseMCPListToolsInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCodeInterpreterCallInProgressEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCodeInterpreterCallInterpretingEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCodeInterpreterCallCompletedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCodeInterpreterCallCodeDeltaEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCodeInterpreterCallCodeDoneEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub code: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseOutputTextAnnotationAddedEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub content_index: u32,
    pub annotation_index: u32,
    pub item_id: String,
    pub annotation: Option<Annotation>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseQueuedEvent {
    pub sequence_number: u64,
    pub response: Response,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCustomToolCallInputDeltaEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub delta: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseCustomToolCallInputDoneEvent {
    pub sequence_number: u64,
    pub output_index: u32,
    pub item_id: String,
    pub input: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseErrorEvent {
    pub sequence_number: u64,
    pub code: Option<String>,
    pub message: String,
    pub param: Option<String>,
}

/// A streaming event that indicated a shell command was added to a tool call.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseShellCallCommandAddedStreamingEvent {
    /// The sequence number of the event that was emitted.
    pub sequence_number: u64,
    /// The index of the output item that was updated.
    pub output_index: u32,
    /// The index of the shell command that was added.
    pub command_index: u32,
    /// The shell command that was added.
    pub command: String,
}

/// A streaming event that indicated a shell command was incrementally updated.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseShellCallCommandDeltaStreamingEvent {
    /// The sequence number of the event that was emitted.
    pub sequence_number: u64,
    /// The index of the output item that was updated.
    pub output_index: u32,
    /// The index of the shell command that was updated.
    pub command_index: u32,
    /// The shell command delta that was appended.
    pub delta: String,
    /// An obfuscation string that was added to pad the event payload.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub obfuscation: Option<String>,
}

/// A streaming event that indicated a shell command was completed.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseShellCallCommandDoneStreamingEvent {
    /// The sequence number of the event that was emitted.
    pub sequence_number: u64,
    /// The index of the output item that was updated.
    pub output_index: u32,
    /// The index of the shell command that was completed.
    pub command_index: u32,
    /// The final shell command that was emitted.
    pub command: String,
}

/// A streaming event that indicated shell call output was incrementally added.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseShellCallOutputContentDeltaStreamingEvent {
    /// The sequence number of the event that was emitted.
    pub sequence_number: u64,
    /// The ID of the output item that was updated.
    pub item_id: String,
    /// The index of the output item that was updated.
    pub output_index: u32,
    /// The index of the shell command that produced output.
    pub command_index: u32,
    /// The stdout/stderr delta that was emitted.
    pub delta: ShellCallOutputDelta,
}

/// A streaming event that indicated shell call output was completed.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseShellCallOutputContentDoneStreamingEvent {
    /// The sequence number of the event that was emitted.
    pub sequence_number: u64,
    /// The ID of the output item that was updated.
    pub item_id: String,
    /// The index of the output item that was updated.
    pub output_index: u32,
    /// The index of the shell command that produced output.
    pub command_index: u32,
    /// The output contents emitted for the shell command.
    pub output: Vec<FunctionShellCallOutputContent>,
}

/// A delta of stdout/stderr emitted while a shell call was running.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ShellCallOutputDelta {
    /// The stdout delta that was emitted.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stdout: Option<String>,
    /// The stderr delta that was emitted.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stderr: Option<String>,
}

/// Stream of response events
#[cfg(feature = "_api")]
pub type ResponseStream = crate::types::stream::StreamResponse<ResponseStreamEvent>;

// Implement EventType trait for all event types in this file
#[cfg(feature = "_api")]
macro_rules! impl_event_type {
    ($($ty:ty => $event_type:expr),* $(,)?) => {
        $(
            impl crate::traits::EventType for $ty {
                fn event_type(&self) -> &'static str {
                    $event_type
                }
            }
        )*
    };
}

// Apply macro for each event struct type in this file.
#[cfg(feature = "_api")]
impl_event_type! {
    ResponseAudioDeltaEvent => "response.audio.delta",
    ResponseAudioDoneEvent => "response.audio.done",
    ResponseAudioTranscriptDeltaEvent => "response.audio.transcript.delta",
    ResponseAudioTranscriptDoneEvent => "response.audio.transcript.done",
    ResponseShellCallCommandAddedStreamingEvent => "response.shell_call_command.added",
    ResponseShellCallCommandDeltaStreamingEvent => "response.shell_call_command.delta",
    ResponseShellCallCommandDoneStreamingEvent => "response.shell_call_command.done",
    ResponseShellCallOutputContentDeltaStreamingEvent => "response.shell_call_output_content.delta",
    ResponseShellCallOutputContentDoneStreamingEvent => "response.shell_call_output_content.done",
    ResponseCreatedEvent => "response.created",
    ResponseInProgressEvent => "response.in_progress",
    ResponseCompletedEvent => "response.completed",
    ResponseFailedEvent => "response.failed",
    ResponseIncompleteEvent => "response.incomplete",
    ResponseOutputItemAddedEvent => "response.output_item.added",
    ResponseOutputItemDoneEvent => "response.output_item.done",
    ResponseContentPartAddedEvent => "response.content_part.added",
    ResponseContentPartDoneEvent => "response.content_part.done",
    ResponseTextDeltaEvent => "response.output_text.delta",
    ResponseTextDoneEvent => "response.output_text.done",
    ResponseRefusalDeltaEvent => "response.refusal.delta",
    ResponseRefusalDoneEvent => "response.refusal.done",
    ResponseFunctionCallArgumentsDeltaEvent => "response.function_call_arguments.delta",
    ResponseFunctionCallArgumentsDoneEvent => "response.function_call_arguments.done",
    ResponseFileSearchCallInProgressEvent => "response.file_search_call.in_progress",
    ResponseFileSearchCallSearchingEvent => "response.file_search_call.searching",
    ResponseFileSearchCallCompletedEvent => "response.file_search_call.completed",
    ResponseWebSearchCallInProgressEvent => "response.web_search_call.in_progress",
    ResponseWebSearchCallSearchingEvent => "response.web_search_call.searching",
    ResponseWebSearchCallCompletedEvent => "response.web_search_call.completed",
    ResponseReasoningSummaryPartAddedEvent => "response.reasoning_summary_part.added",
    ResponseReasoningSummaryPartDoneEvent => "response.reasoning_summary_part.done",
    ResponseReasoningSummaryTextDeltaEvent => "response.reasoning_summary_text.delta",
    ResponseReasoningSummaryTextDoneEvent => "response.reasoning_summary_text.done",
    ResponseReasoningTextDeltaEvent => "response.reasoning_text.delta",
    ResponseReasoningTextDoneEvent => "response.reasoning_text.done",
    ResponseImageGenCallCompletedEvent => "response.image_generation_call.completed",
    ResponseImageGenCallGeneratingEvent => "response.image_generation_call.generating",
    ResponseImageGenCallInProgressEvent => "response.image_generation_call.in_progress",
    ResponseImageGenCallPartialImageEvent => "response.image_generation_call.partial_image",
    ResponseMCPCallArgumentsDeltaEvent => "response.mcp_call_arguments.delta",
    ResponseMCPCallArgumentsDoneEvent => "response.mcp_call_arguments.done",
    ResponseMCPCallCompletedEvent => "response.mcp_call.completed",
    ResponseMCPCallFailedEvent => "response.mcp_call.failed",
    ResponseMCPCallInProgressEvent => "response.mcp_call.in_progress",
    ResponseMCPListToolsCompletedEvent => "response.mcp_list_tools.completed",
    ResponseMCPListToolsFailedEvent => "response.mcp_list_tools.failed",
    ResponseMCPListToolsInProgressEvent => "response.mcp_list_tools.in_progress",
    ResponseCodeInterpreterCallInProgressEvent => "response.code_interpreter_call.in_progress",
    ResponseCodeInterpreterCallInterpretingEvent => "response.code_interpreter_call.interpreting",
    ResponseCodeInterpreterCallCompletedEvent => "response.code_interpreter_call.completed",
    ResponseCodeInterpreterCallCodeDeltaEvent => "response.code_interpreter_call_code.delta",
    ResponseCodeInterpreterCallCodeDoneEvent => "response.code_interpreter_call_code.done",
    ResponseOutputTextAnnotationAddedEvent => "response.output_text.annotation.added",
    ResponseQueuedEvent => "response.queued",
    ResponseCustomToolCallInputDeltaEvent => "response.custom_tool_call_input.delta",
    ResponseCustomToolCallInputDoneEvent => "response.custom_tool_call_input.done",
    ResponseErrorEvent => "error",
}

#[cfg(feature = "_api")]
impl crate::traits::EventType for ResponseStreamEvent {
    fn event_type(&self) -> &'static str {
        match self {
            Self::ResponseAudioDelta(event) => event.event_type(),
            Self::ResponseAudioDone(event) => event.event_type(),
            Self::ResponseAudioTranscriptDelta(event) => event.event_type(),
            Self::ResponseAudioTranscriptDone(event) => event.event_type(),
            Self::ResponseShellCallCommandAdded(event) => event.event_type(),
            Self::ResponseShellCallCommandDelta(event) => event.event_type(),
            Self::ResponseShellCallCommandDone(event) => event.event_type(),
            Self::ResponseShellCallOutputContentDelta(event) => event.event_type(),
            Self::ResponseShellCallOutputContentDone(event) => event.event_type(),
            Self::ResponseCreated(event) => event.event_type(),
            Self::ResponseInProgress(event) => event.event_type(),
            Self::ResponseCompleted(event) => event.event_type(),
            Self::ResponseFailed(event) => event.event_type(),
            Self::ResponseIncomplete(event) => event.event_type(),
            Self::ResponseOutputItemAdded(event) => event.event_type(),
            Self::ResponseOutputItemDone(event) => event.event_type(),
            Self::ResponseContentPartAdded(event) => event.event_type(),
            Self::ResponseContentPartDone(event) => event.event_type(),
            Self::ResponseOutputTextDelta(event) => event.event_type(),
            Self::ResponseOutputTextDone(event) => event.event_type(),
            Self::ResponseRefusalDelta(event) => event.event_type(),
            Self::ResponseRefusalDone(event) => event.event_type(),
            Self::ResponseFunctionCallArgumentsDelta(event) => event.event_type(),
            Self::ResponseFunctionCallArgumentsDone(event) => event.event_type(),
            Self::ResponseFileSearchCallInProgress(event) => event.event_type(),
            Self::ResponseFileSearchCallSearching(event) => event.event_type(),
            Self::ResponseFileSearchCallCompleted(event) => event.event_type(),
            Self::ResponseWebSearchCallInProgress(event) => event.event_type(),
            Self::ResponseWebSearchCallSearching(event) => event.event_type(),
            Self::ResponseWebSearchCallCompleted(event) => event.event_type(),
            Self::ResponseReasoningSummaryPartAdded(event) => event.event_type(),
            Self::ResponseReasoningSummaryPartDone(event) => event.event_type(),
            Self::ResponseReasoningSummaryTextDelta(event) => event.event_type(),
            Self::ResponseReasoningSummaryTextDone(event) => event.event_type(),
            Self::ResponseReasoningTextDelta(event) => event.event_type(),
            Self::ResponseReasoningTextDone(event) => event.event_type(),
            Self::ResponseImageGenerationCallCompleted(event) => event.event_type(),
            Self::ResponseImageGenerationCallGenerating(event) => event.event_type(),
            Self::ResponseImageGenerationCallInProgress(event) => event.event_type(),
            Self::ResponseImageGenerationCallPartialImage(event) => event.event_type(),
            Self::ResponseMCPCallArgumentsDelta(event) => event.event_type(),
            Self::ResponseMCPCallArgumentsDone(event) => event.event_type(),
            Self::ResponseMCPCallCompleted(event) => event.event_type(),
            Self::ResponseMCPCallFailed(event) => event.event_type(),
            Self::ResponseMCPCallInProgress(event) => event.event_type(),
            Self::ResponseMCPListToolsCompleted(event) => event.event_type(),
            Self::ResponseMCPListToolsFailed(event) => event.event_type(),
            Self::ResponseMCPListToolsInProgress(event) => event.event_type(),
            Self::ResponseCodeInterpreterCallInProgress(event) => event.event_type(),
            Self::ResponseCodeInterpreterCallInterpreting(event) => event.event_type(),
            Self::ResponseCodeInterpreterCallCompleted(event) => event.event_type(),
            Self::ResponseCodeInterpreterCallCodeDelta(event) => event.event_type(),
            Self::ResponseCodeInterpreterCallCodeDone(event) => event.event_type(),
            Self::ResponseOutputTextAnnotationAdded(event) => event.event_type(),
            Self::ResponseQueued(event) => event.event_type(),
            Self::ResponseCustomToolCallInputDelta(event) => event.event_type(),
            Self::ResponseCustomToolCallInputDone(event) => event.event_type(),
            Self::ResponseError(event) => event.event_type(),
        }
    }
}