Skip to main content

async_openai/types/responses/
stream.rs

1use serde::{Deserialize, Serialize};
2
3use crate::types::responses::{
4    Annotation, FunctionShellCallOutputContent, OutputContent, OutputItem, Response,
5    ResponseLogProb, SummaryPart,
6};
7
8/// Event types for streaming responses from the Responses API
9#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
10#[serde(tag = "type")]
11pub enum ResponseStreamEvent {
12    #[serde(rename = "response.compaction.compacting")]
13    CompactionCompacting(ResponseCompactionCompactingEvent),
14    /// Emitted when there is a partial audio response.
15    #[serde(rename = "response.audio.delta")]
16    ResponseAudioDelta(ResponseAudioDeltaEvent),
17    /// Emitted when the audio response is complete.
18    #[serde(rename = "response.audio.done")]
19    ResponseAudioDone(ResponseAudioDoneEvent),
20    /// Emitted when there is a partial transcript of audio.
21    #[serde(rename = "response.audio.transcript.delta")]
22    ResponseAudioTranscriptDelta(ResponseAudioTranscriptDeltaEvent),
23    /// Emitted when the full audio transcript is completed.
24    #[serde(rename = "response.audio.transcript.done")]
25    ResponseAudioTranscriptDone(ResponseAudioTranscriptDoneEvent),
26    /// An event that is emitted when a response is created.
27    #[serde(rename = "response.created")]
28    ResponseCreated(ResponseCreatedEvent),
29    /// Emitted when the response is in progress.
30    #[serde(rename = "response.in_progress")]
31    ResponseInProgress(ResponseInProgressEvent),
32    /// Emitted when the model response is complete.
33    #[serde(rename = "response.completed")]
34    ResponseCompleted(ResponseCompletedEvent),
35    /// An event that is emitted when a response fails.
36    #[serde(rename = "response.failed")]
37    ResponseFailed(ResponseFailedEvent),
38    /// An event that is emitted when a response finishes as incomplete.
39    #[serde(rename = "response.incomplete")]
40    ResponseIncomplete(ResponseIncompleteEvent),
41    /// Emitted when a new output item is added.
42    #[serde(rename = "response.output_item.added")]
43    ResponseOutputItemAdded(ResponseOutputItemAddedEvent),
44    /// Emitted when an output item is marked done.
45    #[serde(rename = "response.output_item.done")]
46    ResponseOutputItemDone(ResponseOutputItemDoneEvent),
47    /// Emitted when a new content part is added.
48    #[serde(rename = "response.content_part.added")]
49    ResponseContentPartAdded(ResponseContentPartAddedEvent),
50    /// Emitted when a content part is done.
51    #[serde(rename = "response.content_part.done")]
52    ResponseContentPartDone(ResponseContentPartDoneEvent),
53    /// Emitted when there is an additional text delta.
54    #[serde(rename = "response.output_text.delta")]
55    ResponseOutputTextDelta(ResponseTextDeltaEvent),
56    /// Emitted when text content is finalized.
57    #[serde(rename = "response.output_text.done")]
58    ResponseOutputTextDone(ResponseTextDoneEvent),
59    /// Emitted when there is a partial refusal text.
60    #[serde(rename = "response.refusal.delta")]
61    ResponseRefusalDelta(ResponseRefusalDeltaEvent),
62    #[serde(rename = "response.refusal.done")]
63    /// Emitted when refusal text is finalized.
64    ResponseRefusalDone(ResponseRefusalDoneEvent),
65    /// Emitted when there is a partial function-call arguments delta.
66    #[serde(rename = "response.function_call_arguments.delta")]
67    ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDeltaEvent),
68    /// Emitted when function-call arguments are finalized.
69    #[serde(rename = "response.function_call_arguments.done")]
70    ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDoneEvent),
71    /// Emitted when a file search call is initiated.
72    #[serde(rename = "response.file_search_call.in_progress")]
73    ResponseFileSearchCallInProgress(ResponseFileSearchCallInProgressEvent),
74    /// Emitted when a file search is currently searching.
75    #[serde(rename = "response.file_search_call.searching")]
76    ResponseFileSearchCallSearching(ResponseFileSearchCallSearchingEvent),
77    /// Emitted when a file search call is completed (results found).
78    #[serde(rename = "response.file_search_call.completed")]
79    ResponseFileSearchCallCompleted(ResponseFileSearchCallCompletedEvent),
80    /// Emitted when a web search call is initiated.
81    #[serde(rename = "response.web_search_call.in_progress")]
82    ResponseWebSearchCallInProgress(ResponseWebSearchCallInProgressEvent),
83    /// Emitted when a web search call is executing.
84    #[serde(rename = "response.web_search_call.searching")]
85    ResponseWebSearchCallSearching(ResponseWebSearchCallSearchingEvent),
86    /// Emitted when a web search call is completed.
87    #[serde(rename = "response.web_search_call.completed")]
88    ResponseWebSearchCallCompleted(ResponseWebSearchCallCompletedEvent),
89    /// Emitted when a new reasoning summary part is added.
90    #[serde(rename = "response.reasoning_summary_part.added")]
91    ResponseReasoningSummaryPartAdded(ResponseReasoningSummaryPartAddedEvent),
92    /// Emitted when a reasoning summary part is completed.
93    #[serde(rename = "response.reasoning_summary_part.done")]
94    ResponseReasoningSummaryPartDone(ResponseReasoningSummaryPartDoneEvent),
95    /// Emitted when a delta is added to a reasoning summary text.
96    #[serde(rename = "response.reasoning_summary_text.delta")]
97    ResponseReasoningSummaryTextDelta(ResponseReasoningSummaryTextDeltaEvent),
98    /// Emitted when a reasoning summary text is completed.
99    #[serde(rename = "response.reasoning_summary_text.done")]
100    ResponseReasoningSummaryTextDone(ResponseReasoningSummaryTextDoneEvent),
101    /// Emitted when a delta is added to a reasoning text.
102    #[serde(rename = "response.reasoning_text.delta")]
103    ResponseReasoningTextDelta(ResponseReasoningTextDeltaEvent),
104    /// Emitted when a reasoning text is completed.
105    #[serde(rename = "response.reasoning_text.done")]
106    ResponseReasoningTextDone(ResponseReasoningTextDoneEvent),
107    /// Emitted when an image generation tool call has completed and the final image is available.
108    #[serde(rename = "response.image_generation_call.completed")]
109    ResponseImageGenerationCallCompleted(ResponseImageGenCallCompletedEvent),
110    /// Emitted when an image generation tool call is actively generating an image (intermediate state).
111    #[serde(rename = "response.image_generation_call.generating")]
112    ResponseImageGenerationCallGenerating(ResponseImageGenCallGeneratingEvent),
113    /// Emitted when an image generation tool call is in progress.
114    #[serde(rename = "response.image_generation_call.in_progress")]
115    ResponseImageGenerationCallInProgress(ResponseImageGenCallInProgressEvent),
116    /// Emitted when a partial image is available during image generation streaming.
117    #[serde(rename = "response.image_generation_call.partial_image")]
118    ResponseImageGenerationCallPartialImage(ResponseImageGenCallPartialImageEvent),
119    /// Emitted when there is a delta (partial update) to the arguments of an MCP tool call.
120    #[serde(rename = "response.mcp_call_arguments.delta")]
121    ResponseMCPCallArgumentsDelta(ResponseMCPCallArgumentsDeltaEvent),
122    /// Emitted when the arguments for an MCP tool call are finalized.
123    #[serde(rename = "response.mcp_call_arguments.done")]
124    ResponseMCPCallArgumentsDone(ResponseMCPCallArgumentsDoneEvent),
125    /// Emitted when an MCP tool call has completed successfully.
126    #[serde(rename = "response.mcp_call.completed")]
127    ResponseMCPCallCompleted(ResponseMCPCallCompletedEvent),
128    /// Emitted when an MCP tool call has failed.
129    #[serde(rename = "response.mcp_call.failed")]
130    ResponseMCPCallFailed(ResponseMCPCallFailedEvent),
131    /// Emitted when an MCP tool call is in progress.
132    #[serde(rename = "response.mcp_call.in_progress")]
133    ResponseMCPCallInProgress(ResponseMCPCallInProgressEvent),
134    /// Emitted when the list of available MCP tools has been successfully retrieved.
135    #[serde(rename = "response.mcp_list_tools.completed")]
136    ResponseMCPListToolsCompleted(ResponseMCPListToolsCompletedEvent),
137    /// Emitted when the attempt to list available MCP tools has failed.
138    #[serde(rename = "response.mcp_list_tools.failed")]
139    ResponseMCPListToolsFailed(ResponseMCPListToolsFailedEvent),
140    /// Emitted when the system is in the process of retrieving the list of available MCP tools.
141    #[serde(rename = "response.mcp_list_tools.in_progress")]
142    ResponseMCPListToolsInProgress(ResponseMCPListToolsInProgressEvent),
143    /// Emitted when a code interpreter call is in progress.
144    #[serde(rename = "response.code_interpreter_call.in_progress")]
145    ResponseCodeInterpreterCallInProgress(ResponseCodeInterpreterCallInProgressEvent),
146    /// Emitted when the code interpreter is actively interpreting the code snippet.
147    #[serde(rename = "response.code_interpreter_call.interpreting")]
148    ResponseCodeInterpreterCallInterpreting(ResponseCodeInterpreterCallInterpretingEvent),
149    /// Emitted when the code interpreter call is completed.
150    #[serde(rename = "response.code_interpreter_call.completed")]
151    ResponseCodeInterpreterCallCompleted(ResponseCodeInterpreterCallCompletedEvent),
152    /// Emitted when a partial code snippet is streamed by the code interpreter.
153    #[serde(rename = "response.code_interpreter_call_code.delta")]
154    ResponseCodeInterpreterCallCodeDelta(ResponseCodeInterpreterCallCodeDeltaEvent),
155    /// Emitted when the code snippet is finalized by the code interpreter.
156    #[serde(rename = "response.code_interpreter_call_code.done")]
157    ResponseCodeInterpreterCallCodeDone(ResponseCodeInterpreterCallCodeDoneEvent),
158    /// Emitted when an annotation is added to output text content.
159    #[serde(rename = "response.output_text.annotation.added")]
160    ResponseOutputTextAnnotationAdded(ResponseOutputTextAnnotationAddedEvent),
161    /// Emitted when a response is queued and waiting to be processed.
162    #[serde(rename = "response.queued")]
163    ResponseQueued(ResponseQueuedEvent),
164    /// Event representing a delta (partial update) to the input of a custom tool call.
165    #[serde(rename = "response.custom_tool_call_input.delta")]
166    ResponseCustomToolCallInputDelta(ResponseCustomToolCallInputDeltaEvent),
167    /// Event indicating that input for a custom tool call is complete.
168    #[serde(rename = "response.custom_tool_call_input.done")]
169    ResponseCustomToolCallInputDone(ResponseCustomToolCallInputDoneEvent),
170    /// Emitted when an error occurs.
171    #[serde(rename = "error")]
172    ResponseError(ResponseErrorEvent),
173    #[serde(rename = "response.shell_call_command.added")]
174    ResponseShellCallCommandAdded(ResponseShellCallCommandAddedStreamingEvent),
175    #[serde(rename = "response.shell_call_command.delta")]
176    ResponseShellCallCommandDelta(ResponseShellCallCommandDeltaStreamingEvent),
177    #[serde(rename = "response.shell_call_command.done")]
178    ResponseShellCallCommandDone(ResponseShellCallCommandDoneStreamingEvent),
179    #[serde(rename = "response.shell_call_output_content.delta")]
180    ResponseShellCallOutputContentDelta(ResponseShellCallOutputContentDeltaStreamingEvent),
181    #[serde(rename = "response.shell_call_output_content.done")]
182    ResponseShellCallOutputContentDone(ResponseShellCallOutputContentDoneStreamingEvent),
183}
184
185/// Emitted when there is a partial audio response.
186#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
187pub struct ResponseAudioDeltaEvent {
188    /// A sequence number for this chunk of the stream response.
189    pub sequence_number: u64,
190    /// A chunk of Base64 encoded response audio bytes.
191    pub delta: String,
192}
193
194/// Emitted when the audio response is complete.
195#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
196pub struct ResponseAudioDoneEvent {
197    /// The sequence number of the delta.
198    pub sequence_number: u64,
199    /// The ID of the response associated with this event.
200    pub response_id: String,
201}
202
203/// Emitted when there is a partial transcript of audio.
204#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
205pub struct ResponseAudioTranscriptDeltaEvent {
206    /// The partial transcript of the audio response.
207    pub delta: String,
208    /// The sequence number of this event.
209    pub sequence_number: u64,
210    /// The ID of the response associated with this event.
211    pub response_id: String,
212}
213
214/// Emitted when the full audio transcript is completed.
215#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
216pub struct ResponseAudioTranscriptDoneEvent {
217    /// The sequence number of this event.
218    pub sequence_number: u64,
219    /// The ID of the response associated with this event.
220    pub response_id: String,
221}
222
223#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
224pub struct ResponseCreatedEvent {
225    pub sequence_number: u64,
226    pub response: Response,
227}
228
229#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
230pub struct ResponseInProgressEvent {
231    pub sequence_number: u64,
232    pub response: Response,
233}
234
235#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
236pub struct ResponseCompletedEvent {
237    pub sequence_number: u64,
238    pub response: Response,
239}
240
241#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
242pub struct ResponseFailedEvent {
243    pub sequence_number: u64,
244    pub response: Response,
245}
246
247#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
248pub struct ResponseIncompleteEvent {
249    pub sequence_number: u64,
250    pub response: Response,
251}
252
253#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
254pub struct ResponseOutputItemAddedEvent {
255    pub sequence_number: u64,
256    pub output_index: u32,
257    /// The output item that was added. For reasoning items, `encrypted_content`
258    /// may be incomplete while the item is in progress. Use the reasoning item
259    /// from the corresponding `response.output_item.done` event when passing it
260    /// as input to a subsequent request.
261    pub item: OutputItem,
262}
263
264#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
265pub struct ResponseOutputItemDoneEvent {
266    pub sequence_number: u64,
267    pub output_index: u32,
268    pub item: OutputItem,
269}
270
271#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
272pub struct ResponseContentPartAddedEvent {
273    pub sequence_number: u64,
274    pub item_id: String,
275    pub output_index: u32,
276    pub content_index: u32,
277    pub part: OutputContent,
278}
279
280#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
281pub struct ResponseContentPartDoneEvent {
282    pub sequence_number: u64,
283    pub item_id: String,
284    pub output_index: u32,
285    pub content_index: u32,
286    pub part: OutputContent,
287}
288
289#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
290pub struct ResponseTextDeltaEvent {
291    pub sequence_number: u64,
292    pub item_id: String,
293    pub output_index: u32,
294    pub content_index: u32,
295    pub delta: String,
296    #[serde(default, skip_serializing_if = "Option::is_none")]
297    pub logprobs: Option<Vec<ResponseLogProb>>,
298}
299
300#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
301pub struct ResponseTextDoneEvent {
302    pub sequence_number: u64,
303    pub item_id: String,
304    pub output_index: u32,
305    pub content_index: u32,
306    pub text: String,
307    pub logprobs: Option<Vec<ResponseLogProb>>,
308}
309
310#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
311pub struct ResponseRefusalDeltaEvent {
312    pub sequence_number: u64,
313    pub item_id: String,
314    pub output_index: u32,
315    pub content_index: u32,
316    pub delta: String,
317}
318
319#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
320pub struct ResponseRefusalDoneEvent {
321    pub sequence_number: u64,
322    pub item_id: String,
323    pub output_index: u32,
324    pub content_index: u32,
325    pub refusal: String,
326}
327
328#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
329pub struct ResponseFunctionCallArgumentsDeltaEvent {
330    pub sequence_number: u64,
331    pub item_id: String,
332    pub output_index: u32,
333    pub delta: String,
334}
335
336#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
337pub struct ResponseFunctionCallArgumentsDoneEvent {
338    /// <https://github.com/64bit/async-openai/issues/472>
339    pub name: Option<String>,
340    pub sequence_number: u64,
341    pub item_id: String,
342    pub output_index: u32,
343    pub arguments: String,
344}
345
346#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
347pub struct ResponseFileSearchCallInProgressEvent {
348    pub sequence_number: u64,
349    pub output_index: u32,
350    pub item_id: String,
351}
352
353#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
354pub struct ResponseFileSearchCallSearchingEvent {
355    pub sequence_number: u64,
356    pub output_index: u32,
357    pub item_id: String,
358}
359
360#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
361pub struct ResponseFileSearchCallCompletedEvent {
362    pub sequence_number: u64,
363    pub output_index: u32,
364    pub item_id: String,
365}
366
367#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
368pub struct ResponseWebSearchCallInProgressEvent {
369    pub sequence_number: u64,
370    pub output_index: u32,
371    pub item_id: String,
372}
373
374#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
375pub struct ResponseWebSearchCallSearchingEvent {
376    pub sequence_number: u64,
377    pub output_index: u32,
378    pub item_id: String,
379}
380
381#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
382pub struct ResponseWebSearchCallCompletedEvent {
383    pub sequence_number: u64,
384    pub output_index: u32,
385    pub item_id: String,
386}
387
388#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
389pub struct ResponseReasoningSummaryPartAddedEvent {
390    pub sequence_number: u64,
391    pub item_id: String,
392    pub output_index: u32,
393    pub summary_index: u32,
394    pub part: SummaryPart,
395}
396
397#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
398pub struct ResponseReasoningSummaryPartDoneEvent {
399    pub sequence_number: u64,
400    pub item_id: String,
401    pub output_index: u32,
402    pub summary_index: u32,
403    pub part: SummaryPart,
404    /// The completion status of the summary part. Omitted when the part completed
405    /// normally and set to `incomplete` when generation was interrupted.
406    #[serde(skip_serializing_if = "Option::is_none")]
407    pub status: Option<String>,
408}
409
410#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
411pub struct ResponseReasoningSummaryTextDeltaEvent {
412    pub sequence_number: u64,
413    pub item_id: String,
414    pub output_index: u32,
415    pub summary_index: u32,
416    pub delta: String,
417}
418
419#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
420pub struct ResponseReasoningSummaryTextDoneEvent {
421    pub sequence_number: u64,
422    pub item_id: String,
423    pub output_index: u32,
424    pub summary_index: u32,
425    pub text: String,
426}
427
428#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
429pub struct ResponseReasoningTextDeltaEvent {
430    pub sequence_number: u64,
431    pub item_id: String,
432    pub output_index: u32,
433    pub content_index: u32,
434    pub delta: String,
435}
436
437#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
438pub struct ResponseReasoningTextDoneEvent {
439    pub sequence_number: u64,
440    pub item_id: String,
441    pub output_index: u32,
442    pub content_index: u32,
443    pub text: String,
444}
445
446#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
447pub struct ResponseImageGenCallCompletedEvent {
448    pub sequence_number: u64,
449    pub output_index: u32,
450    pub item_id: String,
451}
452
453#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
454pub struct ResponseImageGenCallGeneratingEvent {
455    pub sequence_number: u64,
456    pub output_index: u32,
457    pub item_id: String,
458}
459
460#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
461pub struct ResponseImageGenCallInProgressEvent {
462    pub sequence_number: u64,
463    pub output_index: u32,
464    pub item_id: String,
465}
466
467#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
468pub struct ResponseImageGenCallPartialImageEvent {
469    pub sequence_number: u64,
470    pub output_index: u32,
471    pub item_id: String,
472    pub partial_image_index: u32,
473    pub partial_image_b64: String,
474    /// The image size that was used.
475    #[serde(skip_serializing_if = "Option::is_none")]
476    pub size: Option<String>,
477
478    /// The image quality that was used.
479    #[serde(skip_serializing_if = "Option::is_none")]
480    pub quality: Option<String>,
481
482    /// The background setting that was used.
483    #[serde(skip_serializing_if = "Option::is_none")]
484    pub background: Option<String>,
485
486    /// The output format that was used.
487    #[serde(skip_serializing_if = "Option::is_none")]
488    pub output_format: Option<String>,
489}
490
491#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
492pub struct ResponseMCPCallArgumentsDeltaEvent {
493    pub sequence_number: u64,
494    pub output_index: u32,
495    pub item_id: String,
496    pub delta: String,
497}
498
499#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
500pub struct ResponseMCPCallArgumentsDoneEvent {
501    pub sequence_number: u64,
502    pub output_index: u32,
503    pub item_id: String,
504    pub arguments: String,
505}
506
507#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
508pub struct ResponseMCPCallCompletedEvent {
509    pub sequence_number: u64,
510    pub output_index: u32,
511    pub item_id: String,
512}
513
514#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
515pub struct ResponseMCPCallFailedEvent {
516    pub sequence_number: u64,
517    pub output_index: u32,
518    pub item_id: String,
519}
520
521#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
522pub struct ResponseMCPCallInProgressEvent {
523    pub sequence_number: u64,
524    pub output_index: u32,
525    pub item_id: String,
526}
527
528#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
529pub struct ResponseMCPListToolsCompletedEvent {
530    pub sequence_number: u64,
531    pub output_index: u32,
532    pub item_id: String,
533}
534
535#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
536pub struct ResponseMCPListToolsFailedEvent {
537    pub sequence_number: u64,
538    pub output_index: u32,
539    pub item_id: String,
540}
541
542#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
543pub struct ResponseMCPListToolsInProgressEvent {
544    pub sequence_number: u64,
545    pub output_index: u32,
546    pub item_id: String,
547}
548
549#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
550pub struct ResponseCodeInterpreterCallInProgressEvent {
551    pub sequence_number: u64,
552    pub output_index: u32,
553    pub item_id: String,
554}
555
556#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
557pub struct ResponseCodeInterpreterCallInterpretingEvent {
558    pub sequence_number: u64,
559    pub output_index: u32,
560    pub item_id: String,
561}
562
563#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
564pub struct ResponseCodeInterpreterCallCompletedEvent {
565    pub sequence_number: u64,
566    pub output_index: u32,
567    pub item_id: String,
568}
569
570#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
571pub struct ResponseCodeInterpreterCallCodeDeltaEvent {
572    pub sequence_number: u64,
573    pub output_index: u32,
574    pub item_id: String,
575    pub delta: String,
576}
577
578#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
579pub struct ResponseCodeInterpreterCallCodeDoneEvent {
580    pub sequence_number: u64,
581    pub output_index: u32,
582    pub item_id: String,
583    pub code: String,
584}
585
586#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
587pub struct ResponseOutputTextAnnotationAddedEvent {
588    pub sequence_number: u64,
589    pub output_index: u32,
590    pub content_index: u32,
591    pub annotation_index: u32,
592    pub item_id: String,
593    pub annotation: Option<Annotation>,
594}
595
596#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
597pub struct ResponseQueuedEvent {
598    pub sequence_number: u64,
599    pub response: Response,
600}
601
602#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
603pub struct ResponseCustomToolCallInputDeltaEvent {
604    pub sequence_number: u64,
605    pub output_index: u32,
606    pub item_id: String,
607    pub delta: String,
608}
609
610#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
611pub struct ResponseCustomToolCallInputDoneEvent {
612    pub sequence_number: u64,
613    pub output_index: u32,
614    pub item_id: String,
615    pub input: String,
616}
617
618#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
619pub struct ResponseErrorEvent {
620    pub sequence_number: u64,
621    pub code: Option<String>,
622    pub message: String,
623    pub param: Option<String>,
624}
625
626/// A streaming event that indicated a shell command was added to a tool call.
627#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
628pub struct ResponseShellCallCommandAddedStreamingEvent {
629    /// The sequence number of the event that was emitted.
630    pub sequence_number: u64,
631    /// The index of the output item that was updated.
632    pub output_index: u32,
633    /// The index of the shell command that was added.
634    pub command_index: u32,
635    /// The shell command that was added.
636    pub command: String,
637}
638
639/// A streaming event that indicated a shell command was incrementally updated.
640#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
641pub struct ResponseShellCallCommandDeltaStreamingEvent {
642    /// The sequence number of the event that was emitted.
643    pub sequence_number: u64,
644    /// The index of the output item that was updated.
645    pub output_index: u32,
646    /// The index of the shell command that was updated.
647    pub command_index: u32,
648    /// The shell command delta that was appended.
649    pub delta: String,
650    /// An obfuscation string that was added to pad the event payload.
651    #[serde(skip_serializing_if = "Option::is_none")]
652    pub obfuscation: Option<String>,
653}
654
655/// A streaming event that indicated a shell command was completed.
656#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
657pub struct ResponseShellCallCommandDoneStreamingEvent {
658    /// The sequence number of the event that was emitted.
659    pub sequence_number: u64,
660    /// The index of the output item that was updated.
661    pub output_index: u32,
662    /// The index of the shell command that was completed.
663    pub command_index: u32,
664    /// The final shell command that was emitted.
665    pub command: String,
666}
667
668/// A streaming event that indicated shell call output was incrementally added.
669#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
670pub struct ResponseShellCallOutputContentDeltaStreamingEvent {
671    /// The sequence number of the event that was emitted.
672    pub sequence_number: u64,
673    /// The ID of the output item that was updated.
674    pub item_id: String,
675    /// The index of the output item that was updated.
676    pub output_index: u32,
677    /// The index of the shell command that produced output.
678    pub command_index: u32,
679    /// The stdout/stderr delta that was emitted.
680    pub delta: ShellCallOutputDelta,
681}
682
683/// A streaming event that indicated shell call output was completed.
684#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
685pub struct ResponseShellCallOutputContentDoneStreamingEvent {
686    /// The sequence number of the event that was emitted.
687    pub sequence_number: u64,
688    /// The ID of the output item that was updated.
689    pub item_id: String,
690    /// The index of the output item that was updated.
691    pub output_index: u32,
692    /// The index of the shell command that produced output.
693    pub command_index: u32,
694    /// The output contents emitted for the shell command.
695    pub output: Vec<FunctionShellCallOutputContent>,
696}
697
698/// A delta of stdout/stderr emitted while a shell call was running.
699#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
700pub struct ShellCallOutputDelta {
701    /// The stdout delta that was emitted.
702    #[serde(skip_serializing_if = "Option::is_none")]
703    pub stdout: Option<String>,
704    /// The stderr delta that was emitted.
705    #[serde(skip_serializing_if = "Option::is_none")]
706    pub stderr: Option<String>,
707}
708
709#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
710pub struct ResponseCompactionCompactingEvent {
711    pub sequence_number: u64,
712    pub output_index: u64,
713    pub item_id: String,
714}
715
716/// Stream of response events
717#[cfg(feature = "_api")]
718pub type ResponseStream = crate::types::stream::StreamResponse<ResponseStreamEvent>;
719
720// Implement EventType trait for all event types in this file
721#[cfg(feature = "_api")]
722macro_rules! impl_event_type {
723    ($($ty:ty => $event_type:expr),* $(,)?) => {
724        $(
725            impl crate::traits::EventType for $ty {
726                fn event_type(&self) -> &'static str {
727                    $event_type
728                }
729            }
730        )*
731    };
732}
733
734// Apply macro for each event struct type in this file.
735#[cfg(feature = "_api")]
736impl_event_type! {
737    ResponseCompactionCompactingEvent => "response.compaction.compacting",
738    ResponseAudioDeltaEvent => "response.audio.delta",
739    ResponseAudioDoneEvent => "response.audio.done",
740    ResponseAudioTranscriptDeltaEvent => "response.audio.transcript.delta",
741    ResponseAudioTranscriptDoneEvent => "response.audio.transcript.done",
742    ResponseShellCallCommandAddedStreamingEvent => "response.shell_call_command.added",
743    ResponseShellCallCommandDeltaStreamingEvent => "response.shell_call_command.delta",
744    ResponseShellCallCommandDoneStreamingEvent => "response.shell_call_command.done",
745    ResponseShellCallOutputContentDeltaStreamingEvent => "response.shell_call_output_content.delta",
746    ResponseShellCallOutputContentDoneStreamingEvent => "response.shell_call_output_content.done",
747    ResponseCreatedEvent => "response.created",
748    ResponseInProgressEvent => "response.in_progress",
749    ResponseCompletedEvent => "response.completed",
750    ResponseFailedEvent => "response.failed",
751    ResponseIncompleteEvent => "response.incomplete",
752    ResponseOutputItemAddedEvent => "response.output_item.added",
753    ResponseOutputItemDoneEvent => "response.output_item.done",
754    ResponseContentPartAddedEvent => "response.content_part.added",
755    ResponseContentPartDoneEvent => "response.content_part.done",
756    ResponseTextDeltaEvent => "response.output_text.delta",
757    ResponseTextDoneEvent => "response.output_text.done",
758    ResponseRefusalDeltaEvent => "response.refusal.delta",
759    ResponseRefusalDoneEvent => "response.refusal.done",
760    ResponseFunctionCallArgumentsDeltaEvent => "response.function_call_arguments.delta",
761    ResponseFunctionCallArgumentsDoneEvent => "response.function_call_arguments.done",
762    ResponseFileSearchCallInProgressEvent => "response.file_search_call.in_progress",
763    ResponseFileSearchCallSearchingEvent => "response.file_search_call.searching",
764    ResponseFileSearchCallCompletedEvent => "response.file_search_call.completed",
765    ResponseWebSearchCallInProgressEvent => "response.web_search_call.in_progress",
766    ResponseWebSearchCallSearchingEvent => "response.web_search_call.searching",
767    ResponseWebSearchCallCompletedEvent => "response.web_search_call.completed",
768    ResponseReasoningSummaryPartAddedEvent => "response.reasoning_summary_part.added",
769    ResponseReasoningSummaryPartDoneEvent => "response.reasoning_summary_part.done",
770    ResponseReasoningSummaryTextDeltaEvent => "response.reasoning_summary_text.delta",
771    ResponseReasoningSummaryTextDoneEvent => "response.reasoning_summary_text.done",
772    ResponseReasoningTextDeltaEvent => "response.reasoning_text.delta",
773    ResponseReasoningTextDoneEvent => "response.reasoning_text.done",
774    ResponseImageGenCallCompletedEvent => "response.image_generation_call.completed",
775    ResponseImageGenCallGeneratingEvent => "response.image_generation_call.generating",
776    ResponseImageGenCallInProgressEvent => "response.image_generation_call.in_progress",
777    ResponseImageGenCallPartialImageEvent => "response.image_generation_call.partial_image",
778    ResponseMCPCallArgumentsDeltaEvent => "response.mcp_call_arguments.delta",
779    ResponseMCPCallArgumentsDoneEvent => "response.mcp_call_arguments.done",
780    ResponseMCPCallCompletedEvent => "response.mcp_call.completed",
781    ResponseMCPCallFailedEvent => "response.mcp_call.failed",
782    ResponseMCPCallInProgressEvent => "response.mcp_call.in_progress",
783    ResponseMCPListToolsCompletedEvent => "response.mcp_list_tools.completed",
784    ResponseMCPListToolsFailedEvent => "response.mcp_list_tools.failed",
785    ResponseMCPListToolsInProgressEvent => "response.mcp_list_tools.in_progress",
786    ResponseCodeInterpreterCallInProgressEvent => "response.code_interpreter_call.in_progress",
787    ResponseCodeInterpreterCallInterpretingEvent => "response.code_interpreter_call.interpreting",
788    ResponseCodeInterpreterCallCompletedEvent => "response.code_interpreter_call.completed",
789    ResponseCodeInterpreterCallCodeDeltaEvent => "response.code_interpreter_call_code.delta",
790    ResponseCodeInterpreterCallCodeDoneEvent => "response.code_interpreter_call_code.done",
791    ResponseOutputTextAnnotationAddedEvent => "response.output_text.annotation.added",
792    ResponseQueuedEvent => "response.queued",
793    ResponseCustomToolCallInputDeltaEvent => "response.custom_tool_call_input.delta",
794    ResponseCustomToolCallInputDoneEvent => "response.custom_tool_call_input.done",
795    ResponseErrorEvent => "error",
796}
797
798#[cfg(feature = "_api")]
799impl crate::traits::EventType for ResponseStreamEvent {
800    fn event_type(&self) -> &'static str {
801        match self {
802            Self::CompactionCompacting(event) => event.event_type(),
803            Self::ResponseAudioDelta(event) => event.event_type(),
804            Self::ResponseAudioDone(event) => event.event_type(),
805            Self::ResponseAudioTranscriptDelta(event) => event.event_type(),
806            Self::ResponseAudioTranscriptDone(event) => event.event_type(),
807            Self::ResponseShellCallCommandAdded(event) => event.event_type(),
808            Self::ResponseShellCallCommandDelta(event) => event.event_type(),
809            Self::ResponseShellCallCommandDone(event) => event.event_type(),
810            Self::ResponseShellCallOutputContentDelta(event) => event.event_type(),
811            Self::ResponseShellCallOutputContentDone(event) => event.event_type(),
812            Self::ResponseCreated(event) => event.event_type(),
813            Self::ResponseInProgress(event) => event.event_type(),
814            Self::ResponseCompleted(event) => event.event_type(),
815            Self::ResponseFailed(event) => event.event_type(),
816            Self::ResponseIncomplete(event) => event.event_type(),
817            Self::ResponseOutputItemAdded(event) => event.event_type(),
818            Self::ResponseOutputItemDone(event) => event.event_type(),
819            Self::ResponseContentPartAdded(event) => event.event_type(),
820            Self::ResponseContentPartDone(event) => event.event_type(),
821            Self::ResponseOutputTextDelta(event) => event.event_type(),
822            Self::ResponseOutputTextDone(event) => event.event_type(),
823            Self::ResponseRefusalDelta(event) => event.event_type(),
824            Self::ResponseRefusalDone(event) => event.event_type(),
825            Self::ResponseFunctionCallArgumentsDelta(event) => event.event_type(),
826            Self::ResponseFunctionCallArgumentsDone(event) => event.event_type(),
827            Self::ResponseFileSearchCallInProgress(event) => event.event_type(),
828            Self::ResponseFileSearchCallSearching(event) => event.event_type(),
829            Self::ResponseFileSearchCallCompleted(event) => event.event_type(),
830            Self::ResponseWebSearchCallInProgress(event) => event.event_type(),
831            Self::ResponseWebSearchCallSearching(event) => event.event_type(),
832            Self::ResponseWebSearchCallCompleted(event) => event.event_type(),
833            Self::ResponseReasoningSummaryPartAdded(event) => event.event_type(),
834            Self::ResponseReasoningSummaryPartDone(event) => event.event_type(),
835            Self::ResponseReasoningSummaryTextDelta(event) => event.event_type(),
836            Self::ResponseReasoningSummaryTextDone(event) => event.event_type(),
837            Self::ResponseReasoningTextDelta(event) => event.event_type(),
838            Self::ResponseReasoningTextDone(event) => event.event_type(),
839            Self::ResponseImageGenerationCallCompleted(event) => event.event_type(),
840            Self::ResponseImageGenerationCallGenerating(event) => event.event_type(),
841            Self::ResponseImageGenerationCallInProgress(event) => event.event_type(),
842            Self::ResponseImageGenerationCallPartialImage(event) => event.event_type(),
843            Self::ResponseMCPCallArgumentsDelta(event) => event.event_type(),
844            Self::ResponseMCPCallArgumentsDone(event) => event.event_type(),
845            Self::ResponseMCPCallCompleted(event) => event.event_type(),
846            Self::ResponseMCPCallFailed(event) => event.event_type(),
847            Self::ResponseMCPCallInProgress(event) => event.event_type(),
848            Self::ResponseMCPListToolsCompleted(event) => event.event_type(),
849            Self::ResponseMCPListToolsFailed(event) => event.event_type(),
850            Self::ResponseMCPListToolsInProgress(event) => event.event_type(),
851            Self::ResponseCodeInterpreterCallInProgress(event) => event.event_type(),
852            Self::ResponseCodeInterpreterCallInterpreting(event) => event.event_type(),
853            Self::ResponseCodeInterpreterCallCompleted(event) => event.event_type(),
854            Self::ResponseCodeInterpreterCallCodeDelta(event) => event.event_type(),
855            Self::ResponseCodeInterpreterCallCodeDone(event) => event.event_type(),
856            Self::ResponseOutputTextAnnotationAdded(event) => event.event_type(),
857            Self::ResponseQueued(event) => event.event_type(),
858            Self::ResponseCustomToolCallInputDelta(event) => event.event_type(),
859            Self::ResponseCustomToolCallInputDone(event) => event.event_type(),
860            Self::ResponseError(event) => event.event_type(),
861        }
862    }
863}