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