@ai-sdk/openai 4.0.0-beta.7 → 4.0.0-beta.74

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +636 -24
  2. package/README.md +2 -0
  3. package/dist/index.d.ts +240 -44
  4. package/dist/index.js +3345 -1683
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +390 -36
  7. package/dist/internal/index.js +2707 -1706
  8. package/dist/internal/index.js.map +1 -1
  9. package/docs/03-openai.mdx +413 -39
  10. package/package.json +16 -17
  11. package/src/chat/convert-openai-chat-usage.ts +1 -1
  12. package/src/chat/convert-to-openai-chat-messages.ts +96 -68
  13. package/src/chat/map-openai-finish-reason.ts +1 -1
  14. package/src/chat/openai-chat-api.ts +6 -2
  15. package/src/chat/{openai-chat-options.ts → openai-chat-language-model-options.ts} +11 -1
  16. package/src/chat/openai-chat-language-model.ts +82 -148
  17. package/src/chat/openai-chat-prepare-tools.ts +3 -3
  18. package/src/completion/convert-openai-completion-usage.ts +1 -1
  19. package/src/completion/convert-to-openai-completion-prompt.ts +1 -2
  20. package/src/completion/map-openai-finish-reason.ts +1 -1
  21. package/src/completion/openai-completion-api.ts +5 -2
  22. package/src/completion/{openai-completion-options.ts → openai-completion-language-model-options.ts} +5 -1
  23. package/src/completion/openai-completion-language-model.ts +53 -17
  24. package/src/embedding/{openai-embedding-options.ts → openai-embedding-model-options.ts} +5 -1
  25. package/src/embedding/openai-embedding-model.ts +22 -5
  26. package/src/files/openai-files-api.ts +17 -0
  27. package/src/files/openai-files-options.ts +22 -0
  28. package/src/files/openai-files.ts +100 -0
  29. package/src/image/openai-image-model-options.ts +123 -0
  30. package/src/image/openai-image-model.ts +62 -83
  31. package/src/index.ts +15 -6
  32. package/src/internal/index.ts +7 -6
  33. package/src/openai-config.ts +7 -7
  34. package/src/openai-language-model-capabilities.ts +5 -4
  35. package/src/openai-provider.ts +80 -9
  36. package/src/openai-stream-error.ts +181 -0
  37. package/src/openai-tools.ts +12 -1
  38. package/src/realtime/index.ts +2 -0
  39. package/src/realtime/openai-realtime-event-mapper.ts +436 -0
  40. package/src/realtime/openai-realtime-model-options.ts +3 -0
  41. package/src/realtime/openai-realtime-model.ts +111 -0
  42. package/src/responses/convert-openai-responses-usage.ts +1 -1
  43. package/src/responses/convert-to-openai-responses-input.ts +345 -90
  44. package/src/responses/map-openai-responses-finish-reason.ts +1 -1
  45. package/src/responses/openai-responses-api.ts +186 -17
  46. package/src/responses/{openai-responses-options.ts → openai-responses-language-model-options.ts} +55 -1
  47. package/src/responses/openai-responses-language-model.ts +330 -52
  48. package/src/responses/openai-responses-prepare-tools.ts +129 -18
  49. package/src/responses/openai-responses-provider-metadata.ts +12 -2
  50. package/src/skills/openai-skills-api.ts +31 -0
  51. package/src/skills/openai-skills.ts +83 -0
  52. package/src/speech/{openai-speech-options.ts → openai-speech-model-options.ts} +5 -1
  53. package/src/speech/openai-speech-model.ts +23 -7
  54. package/src/tool/apply-patch.ts +33 -32
  55. package/src/tool/code-interpreter.ts +40 -41
  56. package/src/tool/custom.ts +2 -8
  57. package/src/tool/file-search.ts +3 -3
  58. package/src/tool/image-generation.ts +2 -2
  59. package/src/tool/local-shell.ts +2 -2
  60. package/src/tool/mcp.ts +3 -3
  61. package/src/tool/shell.ts +9 -4
  62. package/src/tool/tool-search.ts +98 -0
  63. package/src/tool/web-search-preview.ts +2 -2
  64. package/src/tool/web-search.ts +10 -2
  65. package/src/transcription/{openai-transcription-options.ts → openai-transcription-model-options.ts} +5 -1
  66. package/src/transcription/openai-transcription-model.ts +35 -13
  67. package/dist/index.d.mts +0 -1107
  68. package/dist/index.mjs +0 -6509
  69. package/dist/index.mjs.map +0 -1
  70. package/dist/internal/index.d.mts +0 -1137
  71. package/dist/internal/index.mjs +0 -6322
  72. package/dist/internal/index.mjs.map +0 -1
  73. package/src/image/openai-image-options.ts +0 -31
@@ -1,7 +1,22 @@
1
- import { JSONSchema7 } from '@ai-sdk/provider';
2
- import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
1
+ import type { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider';
2
+ import {
3
+ lazySchema,
4
+ zodSchema,
5
+ type InferSchema,
6
+ } from '@ai-sdk/provider-utils';
3
7
  import { z } from 'zod/v4';
4
8
 
9
+ const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
10
+ z.union([
11
+ z.string(),
12
+ z.number(),
13
+ z.boolean(),
14
+ z.null(),
15
+ z.array(jsonValueSchema),
16
+ z.record(z.string(), jsonValueSchema.optional()),
17
+ ]),
18
+ );
19
+
5
20
  export type OpenAIResponsesInput = Array<OpenAIResponsesInputItem>;
6
21
 
7
22
  export type OpenAIResponsesInputItem =
@@ -20,8 +35,11 @@ export type OpenAIResponsesInputItem =
20
35
  | OpenAIResponsesShellCallOutput
21
36
  | OpenAIResponsesApplyPatchCall
22
37
  | OpenAIResponsesApplyPatchCallOutput
38
+ | OpenAIResponsesToolSearchCall
39
+ | OpenAIResponsesToolSearchOutput
23
40
  | OpenAIResponsesReasoning
24
- | OpenAIResponsesItemReference;
41
+ | OpenAIResponsesItemReference
42
+ | OpenAIResponsesCompactionItem;
25
43
 
26
44
  export type OpenAIResponsesIncludeValue =
27
45
  | 'web_search_call.action.sources'
@@ -82,6 +100,7 @@ export type OpenAIResponsesFunctionCall = {
82
100
  name: string;
83
101
  arguments: string;
84
102
  id?: string;
103
+ namespace?: string;
85
104
  };
86
105
 
87
106
  export type OpenAIResponsesFunctionCallOutput = {
@@ -93,6 +112,7 @@ export type OpenAIResponsesFunctionCallOutput = {
93
112
  | { type: 'input_text'; text: string }
94
113
  | { type: 'input_image'; image_url: string }
95
114
  | { type: 'input_file'; filename: string; file_data: string }
115
+ | { type: 'input_file'; file_url: string }
96
116
  >;
97
117
  };
98
118
 
@@ -199,11 +219,35 @@ export type OpenAIResponsesApplyPatchCallOutput = {
199
219
  output?: string;
200
220
  };
201
221
 
222
+ export type OpenAIResponsesToolSearchCall = {
223
+ type: 'tool_search_call';
224
+ id: string;
225
+ execution: 'server' | 'client';
226
+ call_id: string | null;
227
+ status: 'in_progress' | 'completed' | 'incomplete';
228
+ arguments: unknown;
229
+ };
230
+
231
+ export type OpenAIResponsesToolSearchOutput = {
232
+ type: 'tool_search_output';
233
+ id?: string;
234
+ execution: 'server' | 'client';
235
+ call_id: string | null;
236
+ status: 'in_progress' | 'completed' | 'incomplete';
237
+ tools: Array<JSONObject>;
238
+ };
239
+
202
240
  export type OpenAIResponsesItemReference = {
203
241
  type: 'item_reference';
204
242
  id: string;
205
243
  };
206
244
 
245
+ export type OpenAIResponsesCompactionItem = {
246
+ type: 'compaction';
247
+ id: string;
248
+ encrypted_content: string;
249
+ };
250
+
207
251
  /**
208
252
  * A filter used to compare a specified attribute key to a given value using a defined comparison operation.
209
253
  */
@@ -242,13 +286,22 @@ export type OpenAIResponsesFileSearchToolCompoundFilter = {
242
286
  >;
243
287
  };
244
288
 
289
+ export type OpenAIResponsesFunctionTool = {
290
+ type: 'function';
291
+ name: string;
292
+ description: string | undefined;
293
+ parameters: JSONSchema7;
294
+ strict?: boolean;
295
+ defer_loading?: boolean;
296
+ };
297
+
245
298
  export type OpenAIResponsesTool =
299
+ | OpenAIResponsesFunctionTool
246
300
  | {
247
- type: 'function';
301
+ type: 'namespace';
248
302
  name: string;
249
- description: string | undefined;
250
- parameters: JSONSchema7;
251
- strict?: boolean;
303
+ description: string;
304
+ tools: Array<OpenAIResponsesFunctionTool>;
252
305
  }
253
306
  | {
254
307
  type: 'apply_patch';
@@ -407,6 +460,12 @@ export type OpenAIResponsesTool =
407
460
  path: string;
408
461
  }>;
409
462
  };
463
+ }
464
+ | {
465
+ type: 'tool_search';
466
+ execution?: 'server' | 'client';
467
+ description?: string;
468
+ parameters?: Record<string, unknown>;
410
469
  };
411
470
 
412
471
  export type OpenAIResponsesReasoning = {
@@ -419,6 +478,30 @@ export type OpenAIResponsesReasoning = {
419
478
  }>;
420
479
  };
421
480
 
481
+ // Captured from the Responses API when OpenAI returned an early
482
+ // insufficient_quota stream error after HTTP 200. This shape differs from the
483
+ // currently documented ResponseErrorEvent below.
484
+ const openaiResponsesNestedErrorChunkSchema = z.object({
485
+ type: z.literal('error'),
486
+ sequence_number: z.number(),
487
+ error: z.object({
488
+ type: z.string(),
489
+ code: z.string(),
490
+ message: z.string(),
491
+ param: z.string().nullish(),
492
+ }),
493
+ });
494
+
495
+ // Current OpenAI OpenAPI docs define ResponseErrorEvent with top-level
496
+ // code/message/param fields.
497
+ const openaiResponsesErrorChunkSchema = z.object({
498
+ type: z.literal('error'),
499
+ sequence_number: z.number(),
500
+ code: z.string().nullish(),
501
+ message: z.string(),
502
+ param: z.string().nullish(),
503
+ });
504
+
422
505
  export const openaiResponsesChunkSchema = lazySchema(() =>
423
506
  zodSchema(
424
507
  z.union([
@@ -458,6 +541,32 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
458
541
  service_tier: z.string().nullish(),
459
542
  }),
460
543
  }),
544
+ z.object({
545
+ type: z.literal('response.failed'),
546
+ sequence_number: z.number(),
547
+ response: z.object({
548
+ error: z
549
+ .object({
550
+ code: z.string().nullish(),
551
+ message: z.string(),
552
+ })
553
+ .nullish(),
554
+ incomplete_details: z.object({ reason: z.string() }).nullish(),
555
+ usage: z
556
+ .object({
557
+ input_tokens: z.number(),
558
+ input_tokens_details: z
559
+ .object({ cached_tokens: z.number().nullish() })
560
+ .nullish(),
561
+ output_tokens: z.number(),
562
+ output_tokens_details: z
563
+ .object({ reasoning_tokens: z.number().nullish() })
564
+ .nullish(),
565
+ })
566
+ .nullish(),
567
+ service_tier: z.string().nullish(),
568
+ }),
569
+ }),
461
570
  z.object({
462
571
  type: z.literal('response.created'),
463
572
  response: z.object({
@@ -487,6 +596,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
487
596
  call_id: z.string(),
488
597
  name: z.string(),
489
598
  arguments: z.string(),
599
+ namespace: z.string().nullish(),
490
600
  }),
491
601
  z.object({
492
602
  type: z.literal('web_search_call'),
@@ -573,6 +683,11 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
573
683
  commands: z.array(z.string()),
574
684
  }),
575
685
  }),
686
+ z.object({
687
+ type: z.literal('compaction'),
688
+ id: z.string(),
689
+ encrypted_content: z.string().nullish(),
690
+ }),
576
691
  z.object({
577
692
  type: z.literal('shell_call_output'),
578
693
  id: z.string(),
@@ -592,6 +707,22 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
592
707
  }),
593
708
  ),
594
709
  }),
710
+ z.object({
711
+ type: z.literal('tool_search_call'),
712
+ id: z.string(),
713
+ execution: z.enum(['server', 'client']),
714
+ call_id: z.string().nullable(),
715
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
716
+ arguments: z.unknown(),
717
+ }),
718
+ z.object({
719
+ type: z.literal('tool_search_output'),
720
+ id: z.string(),
721
+ execution: z.enum(['server', 'client']),
722
+ call_id: z.string().nullable(),
723
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
724
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
725
+ }),
595
726
  ]),
596
727
  }),
597
728
  z.object({
@@ -615,6 +746,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
615
746
  name: z.string(),
616
747
  arguments: z.string(),
617
748
  status: z.literal('completed'),
749
+ namespace: z.string().nullish(),
618
750
  }),
619
751
  z.object({
620
752
  type: z.literal('custom_tool_call'),
@@ -652,6 +784,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
652
784
  z.object({
653
785
  type: z.literal('search'),
654
786
  query: z.string().nullish(),
787
+ queries: z.array(z.string()).nullish(),
655
788
  sources: z
656
789
  .array(
657
790
  z.discriminatedUnion('type', [
@@ -796,6 +929,11 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
796
929
  commands: z.array(z.string()),
797
930
  }),
798
931
  }),
932
+ z.object({
933
+ type: z.literal('compaction'),
934
+ id: z.string(),
935
+ encrypted_content: z.string(),
936
+ }),
799
937
  z.object({
800
938
  type: z.literal('shell_call_output'),
801
939
  id: z.string(),
@@ -815,6 +953,22 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
815
953
  }),
816
954
  ),
817
955
  }),
956
+ z.object({
957
+ type: z.literal('tool_search_call'),
958
+ id: z.string(),
959
+ execution: z.enum(['server', 'client']),
960
+ call_id: z.string().nullable(),
961
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
962
+ arguments: z.unknown(),
963
+ }),
964
+ z.object({
965
+ type: z.literal('tool_search_output'),
966
+ id: z.string(),
967
+ execution: z.enum(['server', 'client']),
968
+ call_id: z.string().nullable(),
969
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
970
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
971
+ }),
818
972
  ]),
819
973
  }),
820
974
  z.object({
@@ -907,16 +1061,8 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
907
1061
  output_index: z.number(),
908
1062
  diff: z.string(),
909
1063
  }),
910
- z.object({
911
- type: z.literal('error'),
912
- sequence_number: z.number(),
913
- error: z.object({
914
- type: z.string(),
915
- code: z.string(),
916
- message: z.string(),
917
- param: z.string().nullish(),
918
- }),
919
- }),
1064
+ openaiResponsesNestedErrorChunkSchema,
1065
+ openaiResponsesErrorChunkSchema,
920
1066
  z
921
1067
  .object({ type: z.string() })
922
1068
  .loose()
@@ -1028,6 +1174,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1028
1174
  z.object({
1029
1175
  type: z.literal('search'),
1030
1176
  query: z.string().nullish(),
1177
+ queries: z.array(z.string()).nullish(),
1031
1178
  sources: z
1032
1179
  .array(
1033
1180
  z.discriminatedUnion('type', [
@@ -1109,6 +1256,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1109
1256
  name: z.string(),
1110
1257
  arguments: z.string(),
1111
1258
  id: z.string(),
1259
+ namespace: z.string().nullish(),
1112
1260
  }),
1113
1261
  z.object({
1114
1262
  type: z.literal('custom_tool_call'),
@@ -1219,6 +1367,11 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1219
1367
  commands: z.array(z.string()),
1220
1368
  }),
1221
1369
  }),
1370
+ z.object({
1371
+ type: z.literal('compaction'),
1372
+ id: z.string(),
1373
+ encrypted_content: z.string(),
1374
+ }),
1222
1375
  z.object({
1223
1376
  type: z.literal('shell_call_output'),
1224
1377
  id: z.string(),
@@ -1238,6 +1391,22 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1238
1391
  }),
1239
1392
  ),
1240
1393
  }),
1394
+ z.object({
1395
+ type: z.literal('tool_search_call'),
1396
+ id: z.string(),
1397
+ execution: z.enum(['server', 'client']),
1398
+ call_id: z.string().nullable(),
1399
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1400
+ arguments: z.unknown(),
1401
+ }),
1402
+ z.object({
1403
+ type: z.literal('tool_search_output'),
1404
+ id: z.string(),
1405
+ execution: z.enum(['server', 'client']),
1406
+ call_id: z.string().nullable(),
1407
+ status: z.enum(['in_progress', 'completed', 'incomplete']),
1408
+ tools: z.array(z.record(z.string(), jsonValueSchema.optional())),
1409
+ }),
1241
1410
  ]),
1242
1411
  )
1243
1412
  .optional(),
@@ -1,4 +1,8 @@
1
- import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
2
6
  import { z } from 'zod/v4';
3
7
 
4
8
  /**
@@ -41,8 +45,14 @@ export const openaiResponsesReasoningModelIds = [
41
45
  'gpt-5.3-codex',
42
46
  'gpt-5.4',
43
47
  'gpt-5.4-2026-03-05',
48
+ 'gpt-5.4-mini',
49
+ 'gpt-5.4-mini-2026-03-17',
50
+ 'gpt-5.4-nano',
51
+ 'gpt-5.4-nano-2026-03-17',
44
52
  'gpt-5.4-pro',
45
53
  'gpt-5.4-pro-2026-03-05',
54
+ 'gpt-5.5',
55
+ 'gpt-5.5-2026-04-23',
46
56
  ] as const;
47
57
 
48
58
  export const openaiResponsesModelIds = [
@@ -103,8 +113,14 @@ export type OpenAIResponsesModelId =
103
113
  | 'gpt-5.3-codex'
104
114
  | 'gpt-5.4'
105
115
  | 'gpt-5.4-2026-03-05'
116
+ | 'gpt-5.4-mini'
117
+ | 'gpt-5.4-mini-2026-03-17'
118
+ | 'gpt-5.4-nano'
119
+ | 'gpt-5.4-nano-2026-03-17'
106
120
  | 'gpt-5.4-pro'
107
121
  | 'gpt-5.4-pro-2026-03-05'
122
+ | 'gpt-5.5'
123
+ | 'gpt-5.5-2026-04-23'
108
124
  | 'gpt-5-2025-08-07'
109
125
  | 'gpt-5-chat-latest'
110
126
  | 'gpt-5-codex'
@@ -253,6 +269,15 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
253
269
  */
254
270
  store: z.boolean().nullish(),
255
271
 
272
+ /**
273
+ * Whether to pass through non-image file types as generic input files.
274
+ *
275
+ * By default, inline file inputs are restricted to images and PDFs.
276
+ * Enable this when the target OpenAI Responses model supports additional
277
+ * file media types, such as text/csv.
278
+ */
279
+ passThroughUnsupportedFiles: z.boolean().optional(),
280
+
256
281
  /**
257
282
  * Whether to use strict JSON schema validation.
258
283
  * Defaults to `true`.
@@ -300,6 +325,35 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
300
325
  * and defaults `systemMessageMode` to `developer` unless overridden.
301
326
  */
302
327
  forceReasoning: z.boolean().optional(),
328
+
329
+ /**
330
+ * Enable server-side context management (compaction).
331
+ */
332
+ contextManagement: z
333
+ .array(
334
+ z.object({
335
+ type: z.literal('compaction'),
336
+ compactThreshold: z.number(),
337
+ }),
338
+ )
339
+ .nullish(),
340
+
341
+ /**
342
+ * Restrict the callable tools to a subset while keeping the full tools
343
+ * list intact, so prompt caching is preserved across requests with
344
+ * different allowlists.
345
+ *
346
+ * When set, this overrides the request-level `toolChoice` and emits
347
+ * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
348
+ *
349
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
350
+ */
351
+ allowedTools: z
352
+ .object({
353
+ toolNames: z.array(z.string()).min(1),
354
+ mode: z.enum(['auto', 'required']).optional(),
355
+ })
356
+ .optional(),
303
357
  }),
304
358
  ),
305
359
  );