@ai-sdk/open-responses 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1239 @@
1
+ import { JSONSchema7 } from '@ai-sdk/provider';
2
+ import { lazySchema } from '@ai-sdk/provider-utils';
3
+ import { z } from 'zod/v4';
4
+ import { zodSchema } from '@ai-sdk/provider-utils';
5
+
6
+ export const openResponsesErrorSchema = lazySchema(() =>
7
+ zodSchema(
8
+ z.object({
9
+ error: z.object({
10
+ message: z.string(),
11
+ type: z.string(),
12
+ param: z.string(),
13
+ code: z.string(),
14
+ }),
15
+ }),
16
+ ),
17
+ );
18
+
19
+ // ============================================================================
20
+ // Enums
21
+ // ============================================================================
22
+
23
+ /**
24
+ * The status of a function call or message item.
25
+ */
26
+ export type FunctionCallStatus = 'in_progress' | 'completed' | 'incomplete';
27
+
28
+ /**
29
+ * Image detail level for input images.
30
+ */
31
+ export type ImageDetail = 'low' | 'high' | 'auto';
32
+
33
+ /**
34
+ * Reasoning effort level.
35
+ */
36
+ export type ReasoningEffortEnum = 'none' | 'low' | 'medium' | 'high' | 'xhigh';
37
+
38
+ /**
39
+ * Reasoning summary level.
40
+ */
41
+ export type ReasoningSummaryEnum = 'concise' | 'detailed' | 'auto';
42
+
43
+ /**
44
+ * Tool choice value enum.
45
+ */
46
+ export type ToolChoiceValueEnum = 'none' | 'auto' | 'required';
47
+
48
+ /**
49
+ * Verbosity level for text output.
50
+ */
51
+ export type VerbosityEnum = 'low' | 'medium' | 'high';
52
+
53
+ // ============================================================================
54
+ // Content Types
55
+ // ============================================================================
56
+
57
+ /**
58
+ * A text input to the model.
59
+ */
60
+ export type InputTextContentParam = {
61
+ type: 'input_text';
62
+ text: string;
63
+ };
64
+
65
+ /**
66
+ * An image input to the model.
67
+ */
68
+ export type InputImageContentParam = {
69
+ type: 'input_image';
70
+ image_url?: string;
71
+ detail?: ImageDetail;
72
+ };
73
+
74
+ /**
75
+ * A file input to the model.
76
+ */
77
+ export type InputFileContentParam = {
78
+ type: 'input_file';
79
+ filename?: string;
80
+ file_data?: string;
81
+ file_url?: string;
82
+ };
83
+
84
+ /**
85
+ * A video input to the model.
86
+ */
87
+ export type InputVideoContent = {
88
+ type: 'input_video';
89
+ video_url: string;
90
+ };
91
+
92
+ /**
93
+ * A text output from the model.
94
+ */
95
+ export type OutputTextContentParam = {
96
+ type: 'output_text';
97
+ text: string;
98
+ annotations?: UrlCitationParam[];
99
+ };
100
+
101
+ /**
102
+ * A refusal from the model.
103
+ */
104
+ export type RefusalContentParam = {
105
+ type: 'refusal';
106
+ refusal: string;
107
+ };
108
+
109
+ /**
110
+ * A URL citation annotation.
111
+ */
112
+ export type UrlCitationParam = {
113
+ type: 'url_citation';
114
+ start_index: number;
115
+ end_index: number;
116
+ url: string;
117
+ title: string;
118
+ };
119
+
120
+ /**
121
+ * Reasoning summary content.
122
+ */
123
+ export type ReasoningSummaryContentParam = {
124
+ type: 'summary_text';
125
+ text: string;
126
+ };
127
+
128
+ // ============================================================================
129
+ // Message Item Types
130
+ // ============================================================================
131
+
132
+ /**
133
+ * An internal identifier for an item to reference.
134
+ */
135
+ export type ItemReferenceParam = {
136
+ type?: 'item_reference';
137
+ id: string;
138
+ };
139
+
140
+ /**
141
+ * A reasoning item.
142
+ */
143
+ export type ReasoningItemParam = {
144
+ id?: string;
145
+ type: 'reasoning';
146
+ summary: ReasoningSummaryContentParam[];
147
+ content?: unknown;
148
+ encrypted_content?: string;
149
+ };
150
+
151
+ /**
152
+ * A user message item.
153
+ */
154
+ export type UserMessageItemParam = {
155
+ id?: string;
156
+ type: 'message';
157
+ role: 'user';
158
+ content:
159
+ | string
160
+ | Array<
161
+ InputTextContentParam | InputImageContentParam | InputFileContentParam
162
+ >;
163
+ status?: string;
164
+ };
165
+
166
+ /**
167
+ * A system message item.
168
+ */
169
+ export type SystemMessageItemParam = {
170
+ id?: string;
171
+ type: 'message';
172
+ role: 'system';
173
+ content: string | InputTextContentParam[];
174
+ status?: string;
175
+ };
176
+
177
+ /**
178
+ * A developer message item.
179
+ */
180
+ export type DeveloperMessageItemParam = {
181
+ id?: string;
182
+ type: 'message';
183
+ role: 'developer';
184
+ content: string | InputTextContentParam[];
185
+ status?: string;
186
+ };
187
+
188
+ /**
189
+ * An assistant message item.
190
+ */
191
+ export type AssistantMessageItemParam = {
192
+ id?: string;
193
+ type: 'message';
194
+ role: 'assistant';
195
+ content: string | Array<OutputTextContentParam | RefusalContentParam>;
196
+ status?: string;
197
+ };
198
+
199
+ /**
200
+ * A function call item.
201
+ */
202
+ export type FunctionCallItemParam = {
203
+ id?: string;
204
+ call_id: string;
205
+ type: 'function_call';
206
+ name: string;
207
+ arguments: string;
208
+ status?: FunctionCallStatus;
209
+ };
210
+
211
+ /**
212
+ * A function call output item.
213
+ */
214
+ export type FunctionCallOutputItemParam = {
215
+ id?: string;
216
+ call_id: string;
217
+ type: 'function_call_output';
218
+ output:
219
+ | string
220
+ | Array<
221
+ | InputTextContentParam
222
+ | InputImageContentParam
223
+ | InputFileContentParam
224
+ | InputVideoContent
225
+ >;
226
+ status?: FunctionCallStatus;
227
+ };
228
+
229
+ // ============================================================================
230
+ // Tool Types
231
+ // ============================================================================
232
+
233
+ /**
234
+ * A function tool parameter.
235
+ */
236
+ export type FunctionToolParam = {
237
+ name: string;
238
+ description?: string;
239
+ parameters?: JSONSchema7;
240
+ strict?: boolean;
241
+ type: 'function';
242
+ };
243
+
244
+ /**
245
+ * A specific function tool choice.
246
+ */
247
+ export type SpecificFunctionParam = {
248
+ type: 'function';
249
+ name: string;
250
+ };
251
+
252
+ /**
253
+ * Allowed tools parameter.
254
+ */
255
+ export type AllowedToolsParam = {
256
+ type: 'allowed_tools';
257
+ tools: SpecificFunctionParam[];
258
+ mode?: ToolChoiceValueEnum;
259
+ };
260
+
261
+ /**
262
+ * Controls which tool the model should use, if any.
263
+ */
264
+ export type ToolChoiceParam =
265
+ | ToolChoiceValueEnum
266
+ | SpecificFunctionParam
267
+ | AllowedToolsParam;
268
+
269
+ // ============================================================================
270
+ // Configuration Types
271
+ // ============================================================================
272
+
273
+ /**
274
+ * Set of 16 key-value pairs that can be attached to an object.
275
+ */
276
+ export type MetadataParam = Record<string, string>;
277
+
278
+ /**
279
+ * Text response format (plain text).
280
+ */
281
+ export type TextResponseFormat = {
282
+ type: 'text';
283
+ };
284
+
285
+ /**
286
+ * JSON schema response format.
287
+ */
288
+ export type JsonSchemaResponseFormatParam = {
289
+ type: 'json_schema';
290
+ description?: string;
291
+ name?: string;
292
+ schema?: JSONSchema7;
293
+ strict?: boolean;
294
+ };
295
+
296
+ /**
297
+ * Configuration options for text output.
298
+ */
299
+ export type TextParam = {
300
+ format?: TextResponseFormat | JsonSchemaResponseFormatParam;
301
+ verbosity?: VerbosityEnum;
302
+ };
303
+
304
+ /**
305
+ * Options that control streamed response behavior.
306
+ */
307
+ export type StreamOptionsParam = {
308
+ include_obfuscation?: boolean;
309
+ };
310
+
311
+ /**
312
+ * Configuration options for reasoning behavior.
313
+ */
314
+ export type ReasoningParam = {
315
+ effort?: ReasoningEffortEnum;
316
+ summary?: ReasoningSummaryEnum;
317
+ };
318
+
319
+ // ============================================================================
320
+ // Response-Specific Types
321
+ // ============================================================================
322
+
323
+ /**
324
+ * The status of a message item in the response.
325
+ */
326
+ export type MessageStatus = 'in_progress' | 'completed' | 'incomplete';
327
+
328
+ /**
329
+ * Truncation enum for responses.
330
+ */
331
+ export type TruncationEnum = 'auto' | 'disabled';
332
+
333
+ /**
334
+ * Service tier enum.
335
+ */
336
+ export type ServiceTierEnum = 'auto' | 'default' | 'flex' | 'priority';
337
+
338
+ /**
339
+ * A top log probability of a token.
340
+ */
341
+ export type TopLogProb = {
342
+ token: string;
343
+ logprob: number;
344
+ bytes: number[];
345
+ };
346
+
347
+ /**
348
+ * The log probability of a token.
349
+ */
350
+ export type LogProb = {
351
+ token: string;
352
+ logprob: number;
353
+ bytes: number[];
354
+ top_logprobs: TopLogProb[];
355
+ };
356
+
357
+ /**
358
+ * A URL citation annotation in a response.
359
+ */
360
+ export type UrlCitationBody = {
361
+ type: 'url_citation';
362
+ url: string;
363
+ start_index: number;
364
+ end_index: number;
365
+ title: string;
366
+ };
367
+
368
+ /**
369
+ * An annotation that applies to a span of output text.
370
+ */
371
+ export type Annotation = UrlCitationBody;
372
+
373
+ /**
374
+ * A text input content in a response.
375
+ */
376
+ export type InputTextContent = {
377
+ type: 'input_text';
378
+ text: string;
379
+ };
380
+
381
+ /**
382
+ * A text output from the model in a response.
383
+ */
384
+ export type OutputTextContent = {
385
+ type: 'output_text';
386
+ text: string;
387
+ annotations: Annotation[];
388
+ logprobs: LogProb[];
389
+ };
390
+
391
+ /**
392
+ * A refusal from the model in a response.
393
+ */
394
+ export type RefusalContent = {
395
+ type: 'refusal';
396
+ refusal: string;
397
+ };
398
+
399
+ /**
400
+ * Reasoning text from the model.
401
+ */
402
+ export type ReasoningTextContent = {
403
+ type: 'reasoning_text';
404
+ text: string;
405
+ };
406
+
407
+ /**
408
+ * A summary text from the model.
409
+ */
410
+ export type SummaryTextContent = {
411
+ type: 'summary_text';
412
+ text: string;
413
+ };
414
+
415
+ /**
416
+ * An image input content in a response.
417
+ */
418
+ export type InputImageContent = {
419
+ type: 'input_image';
420
+ image_url?: string;
421
+ detail: ImageDetail;
422
+ };
423
+
424
+ /**
425
+ * A file input content in a response.
426
+ */
427
+ export type InputFileContent = {
428
+ type: 'input_file';
429
+ filename?: string;
430
+ file_url?: string;
431
+ };
432
+
433
+ /**
434
+ * A message in the response.
435
+ */
436
+ export type Message = {
437
+ type: 'message';
438
+ id: string;
439
+ status: MessageStatus;
440
+ role: 'user' | 'assistant' | 'system' | 'developer';
441
+ content: InputTextContent[];
442
+ };
443
+
444
+ /**
445
+ * A function tool call that was generated by the model.
446
+ */
447
+ export type FunctionCall = {
448
+ type: 'function_call';
449
+ id: string;
450
+ call_id: string;
451
+ name: string;
452
+ arguments: string;
453
+ status: FunctionCallStatus;
454
+ };
455
+
456
+ /**
457
+ * A function tool call output that was returned.
458
+ */
459
+ export type FunctionCallOutput = {
460
+ type: 'function_call_output';
461
+ id: string;
462
+ call_id: string;
463
+ output:
464
+ | string
465
+ | Array<InputTextContent | InputImageContent | InputFileContent>;
466
+ status: FunctionCallStatus;
467
+ };
468
+
469
+ /**
470
+ * A reasoning item that was generated by the model.
471
+ */
472
+ export type ReasoningBody = {
473
+ type: 'reasoning';
474
+ id: string;
475
+ content?: InputTextContent[];
476
+ summary: InputTextContent[];
477
+ encrypted_content?: string;
478
+ };
479
+
480
+ /**
481
+ * Output item field union type.
482
+ */
483
+ export type OutputItem =
484
+ | FunctionCall
485
+ | FunctionCallOutput
486
+ | Message
487
+ | ReasoningBody;
488
+
489
+ /**
490
+ * Details about why the response was incomplete.
491
+ */
492
+ export type IncompleteDetails = {
493
+ reason: string;
494
+ };
495
+
496
+ /**
497
+ * An error that occurred while generating the response.
498
+ */
499
+ export type ResponseError = {
500
+ code: string;
501
+ message: string;
502
+ };
503
+
504
+ /**
505
+ * A function tool in a response.
506
+ */
507
+ export type FunctionTool = {
508
+ type: 'function';
509
+ name: string;
510
+ description?: string;
511
+ parameters?: JSONSchema7;
512
+ strict?: boolean;
513
+ };
514
+
515
+ /**
516
+ * Function tool choice in a response.
517
+ */
518
+ export type FunctionToolChoice = {
519
+ type: 'function';
520
+ name?: string;
521
+ };
522
+
523
+ /**
524
+ * Allowed tool choice in a response.
525
+ */
526
+ export type AllowedToolChoice = {
527
+ type: 'allowed_tools';
528
+ tools: FunctionToolChoice[];
529
+ mode: ToolChoiceValueEnum;
530
+ };
531
+
532
+ /**
533
+ * Tool choice in a response.
534
+ */
535
+ export type ResponseToolChoice =
536
+ | ToolChoiceValueEnum
537
+ | FunctionToolChoice
538
+ | AllowedToolChoice;
539
+
540
+ /**
541
+ * JSON object response format.
542
+ */
543
+ export type JsonObjectResponseFormat = {
544
+ type: 'json_object';
545
+ };
546
+
547
+ /**
548
+ * JSON schema response format in a response.
549
+ */
550
+ export type JsonSchemaResponseFormat = {
551
+ type: 'json_schema';
552
+ name: string;
553
+ description?: string;
554
+ schema: unknown;
555
+ strict: boolean;
556
+ };
557
+
558
+ /**
559
+ * Text field in a response.
560
+ */
561
+ export type TextField = {
562
+ format?:
563
+ | TextResponseFormat
564
+ | JsonObjectResponseFormat
565
+ | JsonSchemaResponseFormat;
566
+ verbosity?: VerbosityEnum;
567
+ };
568
+
569
+ /**
570
+ * A breakdown of input token usage that was recorded.
571
+ */
572
+ export type InputTokensDetails = {
573
+ cached_tokens: number;
574
+ };
575
+
576
+ /**
577
+ * A breakdown of output token usage that was recorded.
578
+ */
579
+ export type OutputTokensDetails = {
580
+ reasoning_tokens: number;
581
+ };
582
+
583
+ /**
584
+ * Token usage statistics that were recorded for the response.
585
+ */
586
+ export type Usage = {
587
+ input_tokens: number;
588
+ output_tokens: number;
589
+ total_tokens: number;
590
+ input_tokens_details: InputTokensDetails;
591
+ output_tokens_details: OutputTokensDetails;
592
+ };
593
+
594
+ /**
595
+ * Reasoning configuration and outputs that were produced for this response.
596
+ */
597
+ export type Reasoning = {
598
+ effort?: ReasoningEffortEnum;
599
+ summary?: ReasoningSummaryEnum;
600
+ };
601
+
602
+ // ============================================================================
603
+ // Request Body
604
+ // ============================================================================
605
+
606
+ /**
607
+ * Body that is sent to the Open Responses API.
608
+ */
609
+ export type OpenResponsesRequestBody = {
610
+ /**
611
+ * The model to use for this request, e.g. 'gpt-5.2'.
612
+ */
613
+ model: string;
614
+
615
+ /**
616
+ * Context for the model: either a string (interpreted as a user message),
617
+ * or an array of structured message items.
618
+ */
619
+ input:
620
+ | string
621
+ | Array<
622
+ | ItemReferenceParam
623
+ | ReasoningItemParam
624
+ | UserMessageItemParam
625
+ | SystemMessageItemParam
626
+ | DeveloperMessageItemParam
627
+ | AssistantMessageItemParam
628
+ | FunctionCallItemParam
629
+ | FunctionCallOutputItemParam
630
+ >;
631
+
632
+ /**
633
+ * The ID of the response to use as the prior turn for this request.
634
+ */
635
+ previous_response_id?: string;
636
+
637
+ /**
638
+ * Options specifying extra values to include in the response.
639
+ */
640
+ include?: Array<
641
+ 'reasoning.encrypted_content' | 'message.output_text.logprobs'
642
+ >;
643
+
644
+ /**
645
+ * A list of tools that the model may call while generating the response.
646
+ */
647
+ tools?: FunctionToolParam[];
648
+
649
+ /**
650
+ * Controls which tool the model should use, if any.
651
+ */
652
+ tool_choice?: ToolChoiceParam;
653
+
654
+ /**
655
+ * Structured metadata as up to 16 key-value pairs.
656
+ */
657
+ metadata?: MetadataParam;
658
+
659
+ /**
660
+ * Configuration options for text output.
661
+ */
662
+ text?: TextParam;
663
+
664
+ /**
665
+ * Sampling temperature to use, between 0 and 2.
666
+ */
667
+ temperature?: number;
668
+
669
+ /**
670
+ * Nucleus sampling parameter, between 0 and 1.
671
+ */
672
+ top_p?: number;
673
+
674
+ /**
675
+ * Penalizes new tokens based on whether they appear in the text so far.
676
+ */
677
+ presence_penalty?: number;
678
+
679
+ /**
680
+ * Penalizes new tokens based on their frequency in the text so far.
681
+ */
682
+ frequency_penalty?: number;
683
+
684
+ /**
685
+ * Whether the model may call multiple tools in parallel.
686
+ */
687
+ parallel_tool_calls?: boolean;
688
+
689
+ /**
690
+ * Whether to stream response events as server-sent events.
691
+ */
692
+ stream?: boolean;
693
+
694
+ /**
695
+ * Options that control streamed response behavior.
696
+ */
697
+ stream_options?: StreamOptionsParam;
698
+
699
+ /**
700
+ * Whether to run the request in the background and return immediately.
701
+ */
702
+ background?: boolean;
703
+
704
+ /**
705
+ * Maximum number of tokens the model may generate.
706
+ */
707
+ max_output_tokens?: number;
708
+
709
+ /**
710
+ * Maximum number of tool calls the model may make while generating the response.
711
+ */
712
+ max_tool_calls?: number;
713
+
714
+ /**
715
+ * Configuration options for reasoning behavior.
716
+ */
717
+ reasoning?: ReasoningParam;
718
+
719
+ /**
720
+ * A stable identifier used for safety monitoring and abuse detection.
721
+ */
722
+ safety_identifier?: string;
723
+
724
+ /**
725
+ * A key to use when reading/writing to the prompt cache.
726
+ */
727
+ prompt_cache_key?: string;
728
+
729
+ /**
730
+ * Controls how input is truncated if it exceeds the model's context window.
731
+ * - 'auto': Let the service decide how to truncate.
732
+ * - 'disabled': Disable truncation. Context overflow yields 400 error.
733
+ */
734
+ truncation?: 'auto' | 'disabled';
735
+
736
+ /**
737
+ * Additional instructions to guide the model for this request.
738
+ */
739
+ instructions?: string;
740
+
741
+ /**
742
+ * Whether to store the response so it can be retrieved later.
743
+ */
744
+ store?: boolean;
745
+
746
+ /**
747
+ * The service tier to use for this request.
748
+ * - 'auto' | 'default' | 'flex' | 'priority'
749
+ */
750
+ service_tier?: 'auto' | 'default' | 'flex' | 'priority';
751
+
752
+ /**
753
+ * Number of most likely tokens to return at each position, with logprobs.
754
+ */
755
+ top_logprobs?: number;
756
+ };
757
+
758
+ // ============================================================================
759
+ // Response Body
760
+ // ============================================================================
761
+
762
+ /**
763
+ * Response body from the Open Responses API.
764
+ */
765
+ export type OpenResponsesResponseBody = {
766
+ /**
767
+ * The unique ID of the response that was created.
768
+ */
769
+ id: string;
770
+
771
+ /**
772
+ * The object type, which is always 'response'.
773
+ */
774
+ object: 'response';
775
+
776
+ /**
777
+ * The Unix timestamp (in seconds) for when the response was created.
778
+ */
779
+ created_at: number;
780
+
781
+ /**
782
+ * The Unix timestamp (in seconds) for when the response was completed, if it was completed.
783
+ */
784
+ completed_at?: number;
785
+
786
+ /**
787
+ * The status that was set for the response.
788
+ */
789
+ status: string;
790
+
791
+ /**
792
+ * Details about why the response was incomplete, if applicable.
793
+ */
794
+ incomplete_details?: IncompleteDetails;
795
+
796
+ /**
797
+ * The model that generated this response.
798
+ */
799
+ model: string;
800
+
801
+ /**
802
+ * The ID of the previous response in the chain that was referenced, if any.
803
+ */
804
+ previous_response_id?: string;
805
+
806
+ /**
807
+ * Additional instructions that were used to guide the model for this response.
808
+ */
809
+ instructions?: string;
810
+
811
+ /**
812
+ * The output items that were generated by the model.
813
+ */
814
+ output: OutputItem[];
815
+
816
+ /**
817
+ * The error that occurred, if the response failed.
818
+ */
819
+ error?: ResponseError;
820
+
821
+ /**
822
+ * The tools that were available to the model during response generation.
823
+ */
824
+ tools?: FunctionTool[];
825
+
826
+ /**
827
+ * The tool choice configuration that was used.
828
+ */
829
+ tool_choice?: ResponseToolChoice;
830
+
831
+ /**
832
+ * How the input was truncated by the service when it exceeded the model context window.
833
+ */
834
+ truncation?: TruncationEnum;
835
+
836
+ /**
837
+ * Whether the model was allowed to call multiple tools in parallel.
838
+ */
839
+ parallel_tool_calls?: boolean;
840
+
841
+ /**
842
+ * Configuration options for text output that were used.
843
+ */
844
+ text?: TextField;
845
+
846
+ /**
847
+ * The nucleus sampling parameter that was used for this response.
848
+ */
849
+ top_p?: number;
850
+
851
+ /**
852
+ * The presence penalty that was used.
853
+ */
854
+ presence_penalty?: number;
855
+
856
+ /**
857
+ * The frequency penalty that was used.
858
+ */
859
+ frequency_penalty?: number;
860
+
861
+ /**
862
+ * The number of most likely tokens that were returned at each position.
863
+ */
864
+ top_logprobs?: number;
865
+
866
+ /**
867
+ * The sampling temperature that was used for this response.
868
+ */
869
+ temperature?: number;
870
+
871
+ /**
872
+ * Reasoning configuration and outputs that were produced for this response.
873
+ */
874
+ reasoning?: Reasoning;
875
+
876
+ /**
877
+ * Token usage statistics that were recorded for the response, if available.
878
+ */
879
+ usage?: Usage;
880
+
881
+ /**
882
+ * The maximum number of tokens the model was allowed to generate for this response.
883
+ */
884
+ max_output_tokens?: number;
885
+
886
+ /**
887
+ * The maximum number of tool calls the model was allowed to make.
888
+ */
889
+ max_tool_calls?: number;
890
+
891
+ /**
892
+ * Whether this response was stored so it can be retrieved later.
893
+ */
894
+ store?: boolean;
895
+
896
+ /**
897
+ * Whether this request was run in the background.
898
+ */
899
+ background?: boolean;
900
+
901
+ /**
902
+ * The service tier that was used for this response.
903
+ */
904
+ service_tier?: string;
905
+
906
+ /**
907
+ * Developer-defined metadata that was associated with the response.
908
+ */
909
+ metadata?: unknown;
910
+
911
+ /**
912
+ * A stable identifier that was used for safety monitoring and abuse detection.
913
+ */
914
+ safety_identifier?: string;
915
+
916
+ /**
917
+ * A key that was used to read from or write to the prompt cache.
918
+ */
919
+ prompt_cache_key?: string;
920
+ };
921
+
922
+ // ============================================================================
923
+ // Streaming Chunk Types
924
+ // ============================================================================
925
+
926
+ /**
927
+ * Content part for streaming - output text.
928
+ */
929
+ export type OutputTextContentPart = {
930
+ type: 'output_text';
931
+ text: string;
932
+ annotations: Annotation[];
933
+ };
934
+
935
+ /**
936
+ * Content part for streaming - refusal.
937
+ */
938
+ export type RefusalContentPart = {
939
+ type: 'refusal';
940
+ refusal: string;
941
+ };
942
+
943
+ /**
944
+ * Union of content parts that can appear in streaming.
945
+ */
946
+ export type ContentPart = OutputTextContentPart | RefusalContentPart;
947
+
948
+ // ----------------------------------------------------------------------------
949
+ // State Machine Events
950
+ // ----------------------------------------------------------------------------
951
+
952
+ /**
953
+ * Emitted when a response is created.
954
+ */
955
+ export type ResponseCreatedEvent = {
956
+ type: 'response.created';
957
+ sequence_number: number;
958
+ response: OpenResponsesResponseBody;
959
+ };
960
+
961
+ /**
962
+ * Emitted when a response transitions to in_progress status.
963
+ */
964
+ export type ResponseInProgressEvent = {
965
+ type: 'response.in_progress';
966
+ sequence_number: number;
967
+ response: OpenResponsesResponseBody;
968
+ };
969
+
970
+ /**
971
+ * Emitted when a response completes successfully.
972
+ */
973
+ export type ResponseCompletedEvent = {
974
+ type: 'response.completed';
975
+ sequence_number: number;
976
+ response: OpenResponsesResponseBody;
977
+ };
978
+
979
+ /**
980
+ * Emitted when a response fails.
981
+ */
982
+ export type ResponseFailedEvent = {
983
+ type: 'response.failed';
984
+ sequence_number: number;
985
+ response: OpenResponsesResponseBody;
986
+ };
987
+
988
+ /**
989
+ * Emitted when a response is incomplete (e.g., token budget exhausted).
990
+ */
991
+ export type ResponseIncompleteEvent = {
992
+ type: 'response.incomplete';
993
+ sequence_number: number;
994
+ response: OpenResponsesResponseBody;
995
+ };
996
+
997
+ // ----------------------------------------------------------------------------
998
+ // Delta Events - Output Items
999
+ // ----------------------------------------------------------------------------
1000
+
1001
+ /**
1002
+ * Emitted when a new output item is added to the response.
1003
+ */
1004
+ export type ResponseOutputItemAddedEvent = {
1005
+ type: 'response.output_item.added';
1006
+ sequence_number: number;
1007
+ output_index: number;
1008
+ item: OutputItem;
1009
+ };
1010
+
1011
+ /**
1012
+ * Emitted when an output item is completed.
1013
+ */
1014
+ export type ResponseOutputItemDoneEvent = {
1015
+ type: 'response.output_item.done';
1016
+ sequence_number: number;
1017
+ output_index: number;
1018
+ item: OutputItem;
1019
+ };
1020
+
1021
+ // ----------------------------------------------------------------------------
1022
+ // Delta Events - Content Parts
1023
+ // ----------------------------------------------------------------------------
1024
+
1025
+ /**
1026
+ * Emitted when a new content part is added to an item.
1027
+ */
1028
+ export type ResponseContentPartAddedEvent = {
1029
+ type: 'response.content_part.added';
1030
+ sequence_number: number;
1031
+ item_id: string;
1032
+ output_index: number;
1033
+ content_index: number;
1034
+ part: ContentPart;
1035
+ };
1036
+
1037
+ /**
1038
+ * Emitted when a content part is completed.
1039
+ */
1040
+ export type ResponseContentPartDoneEvent = {
1041
+ type: 'response.content_part.done';
1042
+ sequence_number: number;
1043
+ item_id: string;
1044
+ output_index: number;
1045
+ content_index: number;
1046
+ part: ContentPart;
1047
+ };
1048
+
1049
+ // ----------------------------------------------------------------------------
1050
+ // Delta Events - Text Output
1051
+ // ----------------------------------------------------------------------------
1052
+
1053
+ /**
1054
+ * Emitted when text is appended to an output.
1055
+ */
1056
+ export type ResponseOutputTextDeltaEvent = {
1057
+ type: 'response.output_text.delta';
1058
+ sequence_number: number;
1059
+ item_id: string;
1060
+ output_index: number;
1061
+ content_index: number;
1062
+ delta: string;
1063
+ logprobs?: LogProb[];
1064
+ };
1065
+
1066
+ /**
1067
+ * Emitted when text output is complete.
1068
+ */
1069
+ export type ResponseOutputTextDoneEvent = {
1070
+ type: 'response.output_text.done';
1071
+ sequence_number: number;
1072
+ item_id: string;
1073
+ output_index: number;
1074
+ content_index: number;
1075
+ text: string;
1076
+ logprobs?: LogProb[];
1077
+ };
1078
+
1079
+ // ----------------------------------------------------------------------------
1080
+ // Delta Events - Refusal
1081
+ // ----------------------------------------------------------------------------
1082
+
1083
+ /**
1084
+ * Emitted when refusal text is appended.
1085
+ */
1086
+ export type ResponseRefusalDeltaEvent = {
1087
+ type: 'response.refusal.delta';
1088
+ sequence_number: number;
1089
+ item_id: string;
1090
+ output_index: number;
1091
+ content_index: number;
1092
+ delta: string;
1093
+ };
1094
+
1095
+ /**
1096
+ * Emitted when refusal is complete.
1097
+ */
1098
+ export type ResponseRefusalDoneEvent = {
1099
+ type: 'response.refusal.done';
1100
+ sequence_number: number;
1101
+ item_id: string;
1102
+ output_index: number;
1103
+ content_index: number;
1104
+ refusal: string;
1105
+ };
1106
+
1107
+ // ----------------------------------------------------------------------------
1108
+ // Delta Events - Function Call Arguments
1109
+ // ----------------------------------------------------------------------------
1110
+
1111
+ /**
1112
+ * Emitted when function call arguments are appended.
1113
+ */
1114
+ export type ResponseFunctionCallArgumentsDeltaEvent = {
1115
+ type: 'response.function_call_arguments.delta';
1116
+ sequence_number: number;
1117
+ item_id: string;
1118
+ output_index: number;
1119
+ call_id: string;
1120
+ delta: string;
1121
+ };
1122
+
1123
+ /**
1124
+ * Emitted when function call arguments are complete.
1125
+ */
1126
+ export type ResponseFunctionCallArgumentsDoneEvent = {
1127
+ type: 'response.function_call_arguments.done';
1128
+ sequence_number: number;
1129
+ item_id: string;
1130
+ output_index: number;
1131
+ call_id: string;
1132
+ arguments: string;
1133
+ };
1134
+
1135
+ // ----------------------------------------------------------------------------
1136
+ // Delta Events - Reasoning
1137
+ // ----------------------------------------------------------------------------
1138
+
1139
+ /**
1140
+ * Emitted when reasoning summary text is appended.
1141
+ */
1142
+ export type ResponseReasoningSummaryTextDeltaEvent = {
1143
+ type: 'response.reasoning_summary_text.delta';
1144
+ sequence_number: number;
1145
+ item_id: string;
1146
+ output_index: number;
1147
+ summary_index: number;
1148
+ delta: string;
1149
+ };
1150
+
1151
+ /**
1152
+ * Emitted when reasoning summary text is complete.
1153
+ */
1154
+ export type ResponseReasoningSummaryTextDoneEvent = {
1155
+ type: 'response.reasoning_summary_text.done';
1156
+ sequence_number: number;
1157
+ item_id: string;
1158
+ output_index: number;
1159
+ summary_index: number;
1160
+ text: string;
1161
+ };
1162
+
1163
+ /**
1164
+ * Emitted when a reasoning summary part is added.
1165
+ */
1166
+ export type ResponseReasoningSummaryPartAddedEvent = {
1167
+ type: 'response.reasoning_summary_part.added';
1168
+ sequence_number: number;
1169
+ item_id: string;
1170
+ output_index: number;
1171
+ summary_index: number;
1172
+ part: SummaryTextContent;
1173
+ };
1174
+
1175
+ /**
1176
+ * Emitted when a reasoning summary part is complete.
1177
+ */
1178
+ export type ResponseReasoningSummaryPartDoneEvent = {
1179
+ type: 'response.reasoning_summary_part.done';
1180
+ sequence_number: number;
1181
+ item_id: string;
1182
+ output_index: number;
1183
+ summary_index: number;
1184
+ part: SummaryTextContent;
1185
+ };
1186
+
1187
+ // ----------------------------------------------------------------------------
1188
+ // Error Event
1189
+ // ----------------------------------------------------------------------------
1190
+
1191
+ /**
1192
+ * Emitted when an error occurs during streaming.
1193
+ */
1194
+ export type ResponseErrorEvent = {
1195
+ type: 'error';
1196
+ sequence_number: number;
1197
+ error: ResponseError;
1198
+ };
1199
+
1200
+ // ----------------------------------------------------------------------------
1201
+ // Union Type for All Streaming Chunks
1202
+ // ----------------------------------------------------------------------------
1203
+
1204
+ /**
1205
+ * Union of all streaming chunk event types from the Open Responses API.
1206
+ *
1207
+ * Streaming events fall into two categories:
1208
+ * - **State Machine Events**: Represent status changes (e.g., `response.in_progress`, `response.completed`)
1209
+ * - **Delta Events**: Represent incremental changes (e.g., `response.output_text.delta`, `response.output_item.added`)
1210
+ */
1211
+ export type OpenResponsesChunk =
1212
+ // State Machine Events
1213
+ | ResponseCreatedEvent
1214
+ | ResponseInProgressEvent
1215
+ | ResponseCompletedEvent
1216
+ | ResponseFailedEvent
1217
+ | ResponseIncompleteEvent
1218
+ // Delta Events - Output Items
1219
+ | ResponseOutputItemAddedEvent
1220
+ | ResponseOutputItemDoneEvent
1221
+ // Delta Events - Content Parts
1222
+ | ResponseContentPartAddedEvent
1223
+ | ResponseContentPartDoneEvent
1224
+ // Delta Events - Text Output
1225
+ | ResponseOutputTextDeltaEvent
1226
+ | ResponseOutputTextDoneEvent
1227
+ // Delta Events - Refusal
1228
+ | ResponseRefusalDeltaEvent
1229
+ | ResponseRefusalDoneEvent
1230
+ // Delta Events - Function Call Arguments
1231
+ | ResponseFunctionCallArgumentsDeltaEvent
1232
+ | ResponseFunctionCallArgumentsDoneEvent
1233
+ // Delta Events - Reasoning
1234
+ | ResponseReasoningSummaryTextDeltaEvent
1235
+ | ResponseReasoningSummaryTextDoneEvent
1236
+ | ResponseReasoningSummaryPartAddedEvent
1237
+ | ResponseReasoningSummaryPartDoneEvent
1238
+ // Error Event
1239
+ | ResponseErrorEvent;