@ai-sdk/openai 2.0.0-alpha.9 → 2.0.0-beta.2

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.
package/dist/index.js CHANGED
@@ -26,12 +26,12 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/openai-provider.ts
29
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
29
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
30
30
 
31
31
  // src/openai-chat-language-model.ts
32
32
  var import_provider3 = require("@ai-sdk/provider");
33
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
34
- var import_zod3 = require("zod");
33
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
34
+ var import_v45 = require("zod/v4");
35
35
 
36
36
  // src/convert-to-openai-chat-messages.ts
37
37
  var import_provider = require("@ai-sdk/provider");
@@ -165,7 +165,7 @@ function convertToOpenAIChatMessages({
165
165
  type: "function",
166
166
  function: {
167
167
  name: part.toolName,
168
- arguments: JSON.stringify(part.args)
168
+ arguments: JSON.stringify(part.input)
169
169
  }
170
170
  });
171
171
  break;
@@ -181,10 +181,23 @@ function convertToOpenAIChatMessages({
181
181
  }
182
182
  case "tool": {
183
183
  for (const toolResponse of content) {
184
+ const output = toolResponse.output;
185
+ let contentValue;
186
+ switch (output.type) {
187
+ case "text":
188
+ case "error-text":
189
+ contentValue = output.value;
190
+ break;
191
+ case "content":
192
+ case "json":
193
+ case "error-json":
194
+ contentValue = JSON.stringify(output.value);
195
+ break;
196
+ }
184
197
  messages.push({
185
198
  role: "tool",
186
199
  tool_call_id: toolResponse.toolCallId,
187
- content: JSON.stringify(toolResponse.result)
200
+ content: contentValue
188
201
  });
189
202
  }
190
203
  break;
@@ -229,15 +242,15 @@ function mapOpenAIFinishReason(finishReason) {
229
242
  }
230
243
 
231
244
  // src/openai-chat-options.ts
232
- var import_zod = require("zod");
233
- var openaiProviderOptions = import_zod.z.object({
245
+ var import_v4 = require("zod/v4");
246
+ var openaiProviderOptions = import_v4.z.object({
234
247
  /**
235
248
  * Modify the likelihood of specified tokens appearing in the completion.
236
249
  *
237
250
  * Accepts a JSON object that maps tokens (specified by their token ID in
238
251
  * the GPT tokenizer) to an associated bias value from -100 to 100.
239
252
  */
240
- logitBias: import_zod.z.record(import_zod.z.coerce.number(), import_zod.z.number()).optional(),
253
+ logitBias: import_v4.z.record(import_v4.z.coerce.number(), import_v4.z.number()).optional(),
241
254
  /**
242
255
  * Return the log probabilities of the tokens.
243
256
  *
@@ -247,56 +260,63 @@ var openaiProviderOptions = import_zod.z.object({
247
260
  * Setting to a number will return the log probabilities of the top n
248
261
  * tokens that were generated.
249
262
  */
250
- logprobs: import_zod.z.union([import_zod.z.boolean(), import_zod.z.number()]).optional(),
263
+ logprobs: import_v4.z.union([import_v4.z.boolean(), import_v4.z.number()]).optional(),
251
264
  /**
252
265
  * Whether to enable parallel function calling during tool use. Default to true.
253
266
  */
254
- parallelToolCalls: import_zod.z.boolean().optional(),
267
+ parallelToolCalls: import_v4.z.boolean().optional(),
255
268
  /**
256
269
  * A unique identifier representing your end-user, which can help OpenAI to
257
270
  * monitor and detect abuse.
258
271
  */
259
- user: import_zod.z.string().optional(),
272
+ user: import_v4.z.string().optional(),
260
273
  /**
261
274
  * Reasoning effort for reasoning models. Defaults to `medium`.
262
275
  */
263
- reasoningEffort: import_zod.z.enum(["low", "medium", "high"]).optional(),
276
+ reasoningEffort: import_v4.z.enum(["low", "medium", "high"]).optional(),
264
277
  /**
265
278
  * Maximum number of completion tokens to generate. Useful for reasoning models.
266
279
  */
267
- maxCompletionTokens: import_zod.z.number().optional(),
280
+ maxCompletionTokens: import_v4.z.number().optional(),
268
281
  /**
269
282
  * Whether to enable persistence in responses API.
270
283
  */
271
- store: import_zod.z.boolean().optional(),
284
+ store: import_v4.z.boolean().optional(),
272
285
  /**
273
286
  * Metadata to associate with the request.
274
287
  */
275
- metadata: import_zod.z.record(import_zod.z.string()).optional(),
288
+ metadata: import_v4.z.record(import_v4.z.string().max(64), import_v4.z.string().max(512)).optional(),
276
289
  /**
277
290
  * Parameters for prediction mode.
278
291
  */
279
- prediction: import_zod.z.record(import_zod.z.any()).optional(),
292
+ prediction: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
280
293
  /**
281
294
  * Whether to use structured outputs.
282
295
  *
283
296
  * @default true
284
297
  */
285
- structuredOutputs: import_zod.z.boolean().optional()
298
+ structuredOutputs: import_v4.z.boolean().optional(),
299
+ /**
300
+ * Service tier for the request. Set to 'flex' for 50% cheaper processing
301
+ * at the cost of increased latency. Only available for o3 and o4-mini models.
302
+ *
303
+ * @default 'auto'
304
+ */
305
+ serviceTier: import_v4.z.enum(["auto", "flex"]).optional()
286
306
  });
287
307
 
288
308
  // src/openai-error.ts
289
- var import_zod2 = require("zod");
309
+ var import_v42 = require("zod/v4");
290
310
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
291
- var openaiErrorDataSchema = import_zod2.z.object({
292
- error: import_zod2.z.object({
293
- message: import_zod2.z.string(),
311
+ var openaiErrorDataSchema = import_v42.z.object({
312
+ error: import_v42.z.object({
313
+ message: import_v42.z.string(),
294
314
  // The additional information below is handled loosely to support
295
315
  // OpenAI-compatible providers that have slightly different error
296
316
  // responses:
297
- type: import_zod2.z.string().nullish(),
298
- param: import_zod2.z.any().nullish(),
299
- code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
317
+ type: import_v42.z.string().nullish(),
318
+ param: import_v42.z.any().nullish(),
319
+ code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
300
320
  })
301
321
  });
302
322
  var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -306,6 +326,76 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
306
326
 
307
327
  // src/openai-prepare-tools.ts
308
328
  var import_provider2 = require("@ai-sdk/provider");
329
+
330
+ // src/tool/file-search.ts
331
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
332
+ var import_v43 = require("zod/v4");
333
+ var fileSearchArgsSchema = import_v43.z.object({
334
+ /**
335
+ * List of vector store IDs to search through. If not provided, searches all available vector stores.
336
+ */
337
+ vectorStoreIds: import_v43.z.array(import_v43.z.string()).optional(),
338
+ /**
339
+ * Maximum number of search results to return. Defaults to 10.
340
+ */
341
+ maxResults: import_v43.z.number().optional(),
342
+ /**
343
+ * Type of search to perform. Defaults to 'auto'.
344
+ */
345
+ searchType: import_v43.z.enum(["auto", "keyword", "semantic"]).optional()
346
+ });
347
+ var fileSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
348
+ id: "openai.file_search",
349
+ name: "file_search",
350
+ inputSchema: import_v43.z.object({
351
+ query: import_v43.z.string()
352
+ })
353
+ });
354
+
355
+ // src/tool/web-search-preview.ts
356
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
357
+ var import_v44 = require("zod/v4");
358
+ var webSearchPreviewArgsSchema = import_v44.z.object({
359
+ /**
360
+ * Search context size to use for the web search.
361
+ * - high: Most comprehensive context, highest cost, slower response
362
+ * - medium: Balanced context, cost, and latency (default)
363
+ * - low: Least context, lowest cost, fastest response
364
+ */
365
+ searchContextSize: import_v44.z.enum(["low", "medium", "high"]).optional(),
366
+ /**
367
+ * User location information to provide geographically relevant search results.
368
+ */
369
+ userLocation: import_v44.z.object({
370
+ /**
371
+ * Type of location (always 'approximate')
372
+ */
373
+ type: import_v44.z.literal("approximate"),
374
+ /**
375
+ * Two-letter ISO country code (e.g., 'US', 'GB')
376
+ */
377
+ country: import_v44.z.string().optional(),
378
+ /**
379
+ * City name (free text, e.g., 'Minneapolis')
380
+ */
381
+ city: import_v44.z.string().optional(),
382
+ /**
383
+ * Region name (free text, e.g., 'Minnesota')
384
+ */
385
+ region: import_v44.z.string().optional(),
386
+ /**
387
+ * IANA timezone (e.g., 'America/Chicago')
388
+ */
389
+ timezone: import_v44.z.string().optional()
390
+ }).optional()
391
+ });
392
+ var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
393
+ id: "openai.web_search_preview",
394
+ name: "web_search_preview",
395
+ inputSchema: import_v44.z.object({})
396
+ });
397
+
398
+ // src/openai-prepare-tools.ts
309
399
  function prepareTools({
310
400
  tools,
311
401
  toolChoice,
@@ -318,18 +408,47 @@ function prepareTools({
318
408
  }
319
409
  const openaiTools2 = [];
320
410
  for (const tool of tools) {
321
- if (tool.type === "provider-defined") {
322
- toolWarnings.push({ type: "unsupported-tool", tool });
323
- } else {
324
- openaiTools2.push({
325
- type: "function",
326
- function: {
327
- name: tool.name,
328
- description: tool.description,
329
- parameters: tool.parameters,
330
- strict: structuredOutputs ? true : void 0
411
+ switch (tool.type) {
412
+ case "function":
413
+ openaiTools2.push({
414
+ type: "function",
415
+ function: {
416
+ name: tool.name,
417
+ description: tool.description,
418
+ parameters: tool.inputSchema,
419
+ strict: structuredOutputs ? true : void 0
420
+ }
421
+ });
422
+ break;
423
+ case "provider-defined":
424
+ switch (tool.id) {
425
+ case "openai.file_search": {
426
+ const args = fileSearchArgsSchema.parse(tool.args);
427
+ openaiTools2.push({
428
+ type: "file_search",
429
+ vector_store_ids: args.vectorStoreIds,
430
+ max_results: args.maxResults,
431
+ search_type: args.searchType
432
+ });
433
+ break;
434
+ }
435
+ case "openai.web_search_preview": {
436
+ const args = webSearchPreviewArgsSchema.parse(tool.args);
437
+ openaiTools2.push({
438
+ type: "web_search_preview",
439
+ search_context_size: args.searchContextSize,
440
+ user_location: args.userLocation
441
+ });
442
+ break;
443
+ }
444
+ default:
445
+ toolWarnings.push({ type: "unsupported-tool", tool });
446
+ break;
331
447
  }
332
- });
448
+ break;
449
+ default:
450
+ toolWarnings.push({ type: "unsupported-tool", tool });
451
+ break;
333
452
  }
334
453
  }
335
454
  if (toolChoice == null) {
@@ -391,7 +510,7 @@ var OpenAIChatLanguageModel = class {
391
510
  }) {
392
511
  var _a, _b, _c;
393
512
  const warnings = [];
394
- const openaiOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
513
+ const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
395
514
  provider: "openai",
396
515
  providerOptions,
397
516
  schema: openaiProviderOptions
@@ -453,6 +572,7 @@ var OpenAIChatLanguageModel = class {
453
572
  metadata: openaiOptions.metadata,
454
573
  prediction: openaiOptions.prediction,
455
574
  reasoning_effort: openaiOptions.reasoningEffort,
575
+ service_tier: openaiOptions.serviceTier,
456
576
  // messages:
457
577
  messages
458
578
  };
@@ -526,6 +646,14 @@ var OpenAIChatLanguageModel = class {
526
646
  });
527
647
  }
528
648
  }
649
+ if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
650
+ warnings.push({
651
+ type: "unsupported-setting",
652
+ setting: "serviceTier",
653
+ details: "flex processing is only available for o3 and o4-mini models"
654
+ });
655
+ baseArgs.service_tier = void 0;
656
+ }
529
657
  const {
530
658
  tools: openaiTools2,
531
659
  toolChoice: openaiToolChoice,
@@ -551,15 +679,15 @@ var OpenAIChatLanguageModel = class {
551
679
  responseHeaders,
552
680
  value: response,
553
681
  rawValue: rawResponse
554
- } = await (0, import_provider_utils3.postJsonToApi)({
682
+ } = await (0, import_provider_utils5.postJsonToApi)({
555
683
  url: this.config.url({
556
684
  path: "/chat/completions",
557
685
  modelId: this.modelId
558
686
  }),
559
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
687
+ headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
560
688
  body,
561
689
  failedResponseHandler: openaiFailedResponseHandler,
562
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
690
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
563
691
  openaiChatResponseSchema
564
692
  ),
565
693
  abortSignal: options.abortSignal,
@@ -574,10 +702,9 @@ var OpenAIChatLanguageModel = class {
574
702
  for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
575
703
  content.push({
576
704
  type: "tool-call",
577
- toolCallType: "function",
578
- toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
705
+ toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
579
706
  toolName: toolCall.function.name,
580
- args: toolCall.function.arguments
707
+ input: toolCall.function.arguments
581
708
  });
582
709
  }
583
710
  const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
@@ -621,15 +748,15 @@ var OpenAIChatLanguageModel = class {
621
748
  include_usage: true
622
749
  }
623
750
  };
624
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
751
+ const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
625
752
  url: this.config.url({
626
753
  path: "/chat/completions",
627
754
  modelId: this.modelId
628
755
  }),
629
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
756
+ headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
630
757
  body,
631
758
  failedResponseHandler: openaiFailedResponseHandler,
632
- successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
759
+ successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
633
760
  openaiChatChunkSchema
634
761
  ),
635
762
  abortSignal: options.abortSignal,
@@ -643,6 +770,7 @@ var OpenAIChatLanguageModel = class {
643
770
  totalTokens: void 0
644
771
  };
645
772
  let isFirstChunk = true;
773
+ let isActiveText = false;
646
774
  const providerMetadata = { openai: {} };
647
775
  return {
648
776
  stream: response.pipeThrough(
@@ -652,6 +780,9 @@ var OpenAIChatLanguageModel = class {
652
780
  },
653
781
  transform(chunk, controller) {
654
782
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
783
+ if (options.includeRawChunks) {
784
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
785
+ }
655
786
  if (!chunk.success) {
656
787
  finishReason = "error";
657
788
  controller.enqueue({ type: "error", error: chunk.error });
@@ -695,9 +826,14 @@ var OpenAIChatLanguageModel = class {
695
826
  }
696
827
  const delta = choice.delta;
697
828
  if (delta.content != null) {
829
+ if (!isActiveText) {
830
+ controller.enqueue({ type: "text-start", id: "0" });
831
+ isActiveText = true;
832
+ }
698
833
  controller.enqueue({
699
- type: "text",
700
- text: delta.content
834
+ type: "text-delta",
835
+ id: "0",
836
+ delta: delta.content
701
837
  });
702
838
  }
703
839
  if (delta.tool_calls != null) {
@@ -722,6 +858,11 @@ var OpenAIChatLanguageModel = class {
722
858
  message: `Expected 'function.name' to be a string.`
723
859
  });
724
860
  }
861
+ controller.enqueue({
862
+ type: "tool-input-start",
863
+ id: toolCallDelta.id,
864
+ toolName: toolCallDelta.function.name
865
+ });
725
866
  toolCalls[index] = {
726
867
  id: toolCallDelta.id,
727
868
  type: "function",
@@ -735,20 +876,21 @@ var OpenAIChatLanguageModel = class {
735
876
  if (((_o = toolCall2.function) == null ? void 0 : _o.name) != null && ((_p = toolCall2.function) == null ? void 0 : _p.arguments) != null) {
736
877
  if (toolCall2.function.arguments.length > 0) {
737
878
  controller.enqueue({
738
- type: "tool-call-delta",
739
- toolCallType: "function",
740
- toolCallId: toolCall2.id,
741
- toolName: toolCall2.function.name,
742
- argsTextDelta: toolCall2.function.arguments
879
+ type: "tool-input-delta",
880
+ id: toolCall2.id,
881
+ delta: toolCall2.function.arguments
743
882
  });
744
883
  }
745
- if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
884
+ if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
885
+ controller.enqueue({
886
+ type: "tool-input-end",
887
+ id: toolCall2.id
888
+ });
746
889
  controller.enqueue({
747
890
  type: "tool-call",
748
- toolCallType: "function",
749
- toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils3.generateId)(),
891
+ toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils5.generateId)(),
750
892
  toolName: toolCall2.function.name,
751
- args: toolCall2.function.arguments
893
+ input: toolCall2.function.arguments
752
894
  });
753
895
  toolCall2.hasFinished = true;
754
896
  }
@@ -763,19 +905,20 @@ var OpenAIChatLanguageModel = class {
763
905
  toolCall.function.arguments += (_t = (_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null ? _t : "";
764
906
  }
765
907
  controller.enqueue({
766
- type: "tool-call-delta",
767
- toolCallType: "function",
768
- toolCallId: toolCall.id,
769
- toolName: toolCall.function.name,
770
- argsTextDelta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
908
+ type: "tool-input-delta",
909
+ id: toolCall.id,
910
+ delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
771
911
  });
772
- if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
912
+ if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
913
+ controller.enqueue({
914
+ type: "tool-input-end",
915
+ id: toolCall.id
916
+ });
773
917
  controller.enqueue({
774
918
  type: "tool-call",
775
- toolCallType: "function",
776
- toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils3.generateId)(),
919
+ toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils5.generateId)(),
777
920
  toolName: toolCall.function.name,
778
- args: toolCall.function.arguments
921
+ input: toolCall.function.arguments
779
922
  });
780
923
  toolCall.hasFinished = true;
781
924
  }
@@ -783,6 +926,9 @@ var OpenAIChatLanguageModel = class {
783
926
  }
784
927
  },
785
928
  flush(controller) {
929
+ if (isActiveText) {
930
+ controller.enqueue({ type: "text-end", id: "0" });
931
+ }
786
932
  controller.enqueue({
787
933
  type: "finish",
788
934
  finishReason,
@@ -797,97 +943,97 @@ var OpenAIChatLanguageModel = class {
797
943
  };
798
944
  }
799
945
  };
800
- var openaiTokenUsageSchema = import_zod3.z.object({
801
- prompt_tokens: import_zod3.z.number().nullish(),
802
- completion_tokens: import_zod3.z.number().nullish(),
803
- total_tokens: import_zod3.z.number().nullish(),
804
- prompt_tokens_details: import_zod3.z.object({
805
- cached_tokens: import_zod3.z.number().nullish()
946
+ var openaiTokenUsageSchema = import_v45.z.object({
947
+ prompt_tokens: import_v45.z.number().nullish(),
948
+ completion_tokens: import_v45.z.number().nullish(),
949
+ total_tokens: import_v45.z.number().nullish(),
950
+ prompt_tokens_details: import_v45.z.object({
951
+ cached_tokens: import_v45.z.number().nullish()
806
952
  }).nullish(),
807
- completion_tokens_details: import_zod3.z.object({
808
- reasoning_tokens: import_zod3.z.number().nullish(),
809
- accepted_prediction_tokens: import_zod3.z.number().nullish(),
810
- rejected_prediction_tokens: import_zod3.z.number().nullish()
953
+ completion_tokens_details: import_v45.z.object({
954
+ reasoning_tokens: import_v45.z.number().nullish(),
955
+ accepted_prediction_tokens: import_v45.z.number().nullish(),
956
+ rejected_prediction_tokens: import_v45.z.number().nullish()
811
957
  }).nullish()
812
958
  }).nullish();
813
- var openaiChatResponseSchema = import_zod3.z.object({
814
- id: import_zod3.z.string().nullish(),
815
- created: import_zod3.z.number().nullish(),
816
- model: import_zod3.z.string().nullish(),
817
- choices: import_zod3.z.array(
818
- import_zod3.z.object({
819
- message: import_zod3.z.object({
820
- role: import_zod3.z.literal("assistant").nullish(),
821
- content: import_zod3.z.string().nullish(),
822
- tool_calls: import_zod3.z.array(
823
- import_zod3.z.object({
824
- id: import_zod3.z.string().nullish(),
825
- type: import_zod3.z.literal("function"),
826
- function: import_zod3.z.object({
827
- name: import_zod3.z.string(),
828
- arguments: import_zod3.z.string()
959
+ var openaiChatResponseSchema = import_v45.z.object({
960
+ id: import_v45.z.string().nullish(),
961
+ created: import_v45.z.number().nullish(),
962
+ model: import_v45.z.string().nullish(),
963
+ choices: import_v45.z.array(
964
+ import_v45.z.object({
965
+ message: import_v45.z.object({
966
+ role: import_v45.z.literal("assistant").nullish(),
967
+ content: import_v45.z.string().nullish(),
968
+ tool_calls: import_v45.z.array(
969
+ import_v45.z.object({
970
+ id: import_v45.z.string().nullish(),
971
+ type: import_v45.z.literal("function"),
972
+ function: import_v45.z.object({
973
+ name: import_v45.z.string(),
974
+ arguments: import_v45.z.string()
829
975
  })
830
976
  })
831
977
  ).nullish()
832
978
  }),
833
- index: import_zod3.z.number(),
834
- logprobs: import_zod3.z.object({
835
- content: import_zod3.z.array(
836
- import_zod3.z.object({
837
- token: import_zod3.z.string(),
838
- logprob: import_zod3.z.number(),
839
- top_logprobs: import_zod3.z.array(
840
- import_zod3.z.object({
841
- token: import_zod3.z.string(),
842
- logprob: import_zod3.z.number()
979
+ index: import_v45.z.number(),
980
+ logprobs: import_v45.z.object({
981
+ content: import_v45.z.array(
982
+ import_v45.z.object({
983
+ token: import_v45.z.string(),
984
+ logprob: import_v45.z.number(),
985
+ top_logprobs: import_v45.z.array(
986
+ import_v45.z.object({
987
+ token: import_v45.z.string(),
988
+ logprob: import_v45.z.number()
843
989
  })
844
990
  )
845
991
  })
846
992
  ).nullish()
847
993
  }).nullish(),
848
- finish_reason: import_zod3.z.string().nullish()
994
+ finish_reason: import_v45.z.string().nullish()
849
995
  })
850
996
  ),
851
997
  usage: openaiTokenUsageSchema
852
998
  });
853
- var openaiChatChunkSchema = import_zod3.z.union([
854
- import_zod3.z.object({
855
- id: import_zod3.z.string().nullish(),
856
- created: import_zod3.z.number().nullish(),
857
- model: import_zod3.z.string().nullish(),
858
- choices: import_zod3.z.array(
859
- import_zod3.z.object({
860
- delta: import_zod3.z.object({
861
- role: import_zod3.z.enum(["assistant"]).nullish(),
862
- content: import_zod3.z.string().nullish(),
863
- tool_calls: import_zod3.z.array(
864
- import_zod3.z.object({
865
- index: import_zod3.z.number(),
866
- id: import_zod3.z.string().nullish(),
867
- type: import_zod3.z.literal("function").nullish(),
868
- function: import_zod3.z.object({
869
- name: import_zod3.z.string().nullish(),
870
- arguments: import_zod3.z.string().nullish()
999
+ var openaiChatChunkSchema = import_v45.z.union([
1000
+ import_v45.z.object({
1001
+ id: import_v45.z.string().nullish(),
1002
+ created: import_v45.z.number().nullish(),
1003
+ model: import_v45.z.string().nullish(),
1004
+ choices: import_v45.z.array(
1005
+ import_v45.z.object({
1006
+ delta: import_v45.z.object({
1007
+ role: import_v45.z.enum(["assistant"]).nullish(),
1008
+ content: import_v45.z.string().nullish(),
1009
+ tool_calls: import_v45.z.array(
1010
+ import_v45.z.object({
1011
+ index: import_v45.z.number(),
1012
+ id: import_v45.z.string().nullish(),
1013
+ type: import_v45.z.literal("function").nullish(),
1014
+ function: import_v45.z.object({
1015
+ name: import_v45.z.string().nullish(),
1016
+ arguments: import_v45.z.string().nullish()
871
1017
  })
872
1018
  })
873
1019
  ).nullish()
874
1020
  }).nullish(),
875
- logprobs: import_zod3.z.object({
876
- content: import_zod3.z.array(
877
- import_zod3.z.object({
878
- token: import_zod3.z.string(),
879
- logprob: import_zod3.z.number(),
880
- top_logprobs: import_zod3.z.array(
881
- import_zod3.z.object({
882
- token: import_zod3.z.string(),
883
- logprob: import_zod3.z.number()
1021
+ logprobs: import_v45.z.object({
1022
+ content: import_v45.z.array(
1023
+ import_v45.z.object({
1024
+ token: import_v45.z.string(),
1025
+ logprob: import_v45.z.number(),
1026
+ top_logprobs: import_v45.z.array(
1027
+ import_v45.z.object({
1028
+ token: import_v45.z.string(),
1029
+ logprob: import_v45.z.number()
884
1030
  })
885
1031
  )
886
1032
  })
887
1033
  ).nullish()
888
1034
  }).nullish(),
889
- finish_reason: import_zod3.z.string().nullish(),
890
- index: import_zod3.z.number()
1035
+ finish_reason: import_v45.z.string().nullish(),
1036
+ index: import_v45.z.number()
891
1037
  })
892
1038
  ),
893
1039
  usage: openaiTokenUsageSchema
@@ -897,6 +1043,9 @@ var openaiChatChunkSchema = import_zod3.z.union([
897
1043
  function isReasoningModel(modelId) {
898
1044
  return modelId.startsWith("o");
899
1045
  }
1046
+ function supportsFlexProcessing(modelId) {
1047
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1048
+ }
900
1049
  function getSystemMessageMode(modelId) {
901
1050
  var _a, _b;
902
1051
  if (!isReasoningModel(modelId)) {
@@ -938,8 +1087,8 @@ var reasoningModels = {
938
1087
  };
939
1088
 
940
1089
  // src/openai-completion-language-model.ts
941
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
942
- var import_zod5 = require("zod");
1090
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1091
+ var import_v47 = require("zod/v4");
943
1092
 
944
1093
  // src/convert-to-openai-completion-prompt.ts
945
1094
  var import_provider4 = require("@ai-sdk/provider");
@@ -1017,12 +1166,12 @@ ${user}:`]
1017
1166
  }
1018
1167
 
1019
1168
  // src/openai-completion-options.ts
1020
- var import_zod4 = require("zod");
1021
- var openaiCompletionProviderOptions = import_zod4.z.object({
1169
+ var import_v46 = require("zod/v4");
1170
+ var openaiCompletionProviderOptions = import_v46.z.object({
1022
1171
  /**
1023
1172
  Echo back the prompt in addition to the completion.
1024
1173
  */
1025
- echo: import_zod4.z.boolean().optional(),
1174
+ echo: import_v46.z.boolean().optional(),
1026
1175
  /**
1027
1176
  Modify the likelihood of specified tokens appearing in the completion.
1028
1177
 
@@ -1037,16 +1186,16 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
1037
1186
  As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
1038
1187
  token from being generated.
1039
1188
  */
1040
- logitBias: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number()).optional(),
1189
+ logitBias: import_v46.z.record(import_v46.z.string(), import_v46.z.number()).optional(),
1041
1190
  /**
1042
1191
  The suffix that comes after a completion of inserted text.
1043
1192
  */
1044
- suffix: import_zod4.z.string().optional(),
1193
+ suffix: import_v46.z.string().optional(),
1045
1194
  /**
1046
1195
  A unique identifier representing your end-user, which can help OpenAI to
1047
1196
  monitor and detect abuse. Learn more.
1048
1197
  */
1049
- user: import_zod4.z.string().optional(),
1198
+ user: import_v46.z.string().optional(),
1050
1199
  /**
1051
1200
  Return the log probabilities of the tokens. Including logprobs will increase
1052
1201
  the response size and can slow down response times. However, it can
@@ -1056,7 +1205,7 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
1056
1205
  Setting to a number will return the log probabilities of the top n
1057
1206
  tokens that were generated.
1058
1207
  */
1059
- logprobs: import_zod4.z.union([import_zod4.z.boolean(), import_zod4.z.number()]).optional()
1208
+ logprobs: import_v46.z.union([import_v46.z.boolean(), import_v46.z.number()]).optional()
1060
1209
  });
1061
1210
 
1062
1211
  // src/openai-completion-language-model.ts
@@ -1092,12 +1241,12 @@ var OpenAICompletionLanguageModel = class {
1092
1241
  }) {
1093
1242
  const warnings = [];
1094
1243
  const openaiOptions = {
1095
- ...await (0, import_provider_utils4.parseProviderOptions)({
1244
+ ...await (0, import_provider_utils6.parseProviderOptions)({
1096
1245
  provider: "openai",
1097
1246
  providerOptions,
1098
1247
  schema: openaiCompletionProviderOptions
1099
1248
  }),
1100
- ...await (0, import_provider_utils4.parseProviderOptions)({
1249
+ ...await (0, import_provider_utils6.parseProviderOptions)({
1101
1250
  provider: this.providerOptionsName,
1102
1251
  providerOptions,
1103
1252
  schema: openaiCompletionProviderOptions
@@ -1153,15 +1302,15 @@ var OpenAICompletionLanguageModel = class {
1153
1302
  responseHeaders,
1154
1303
  value: response,
1155
1304
  rawValue: rawResponse
1156
- } = await (0, import_provider_utils4.postJsonToApi)({
1305
+ } = await (0, import_provider_utils6.postJsonToApi)({
1157
1306
  url: this.config.url({
1158
1307
  path: "/completions",
1159
1308
  modelId: this.modelId
1160
1309
  }),
1161
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
1310
+ headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
1162
1311
  body: args,
1163
1312
  failedResponseHandler: openaiFailedResponseHandler,
1164
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1313
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1165
1314
  openaiCompletionResponseSchema
1166
1315
  ),
1167
1316
  abortSignal: options.abortSignal,
@@ -1199,15 +1348,15 @@ var OpenAICompletionLanguageModel = class {
1199
1348
  include_usage: true
1200
1349
  }
1201
1350
  };
1202
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
1351
+ const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
1203
1352
  url: this.config.url({
1204
1353
  path: "/completions",
1205
1354
  modelId: this.modelId
1206
1355
  }),
1207
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
1356
+ headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
1208
1357
  body,
1209
1358
  failedResponseHandler: openaiFailedResponseHandler,
1210
- successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
1359
+ successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(
1211
1360
  openaiCompletionChunkSchema
1212
1361
  ),
1213
1362
  abortSignal: options.abortSignal,
@@ -1228,6 +1377,9 @@ var OpenAICompletionLanguageModel = class {
1228
1377
  controller.enqueue({ type: "stream-start", warnings });
1229
1378
  },
1230
1379
  transform(chunk, controller) {
1380
+ if (options.includeRawChunks) {
1381
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1382
+ }
1231
1383
  if (!chunk.success) {
1232
1384
  finishReason = "error";
1233
1385
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1245,6 +1397,7 @@ var OpenAICompletionLanguageModel = class {
1245
1397
  type: "response-metadata",
1246
1398
  ...getResponseMetadata(value)
1247
1399
  });
1400
+ controller.enqueue({ type: "text-start", id: "0" });
1248
1401
  }
1249
1402
  if (value.usage != null) {
1250
1403
  usage.inputTokens = value.usage.prompt_tokens;
@@ -1258,14 +1411,18 @@ var OpenAICompletionLanguageModel = class {
1258
1411
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1259
1412
  providerMetadata.openai.logprobs = choice.logprobs;
1260
1413
  }
1261
- if ((choice == null ? void 0 : choice.text) != null) {
1414
+ if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
1262
1415
  controller.enqueue({
1263
- type: "text",
1264
- text: choice.text
1416
+ type: "text-delta",
1417
+ id: "0",
1418
+ delta: choice.text
1265
1419
  });
1266
1420
  }
1267
1421
  },
1268
1422
  flush(controller) {
1423
+ if (!isFirstChunk) {
1424
+ controller.enqueue({ type: "text-end", id: "0" });
1425
+ }
1269
1426
  controller.enqueue({
1270
1427
  type: "finish",
1271
1428
  finishReason,
@@ -1280,42 +1437,42 @@ var OpenAICompletionLanguageModel = class {
1280
1437
  };
1281
1438
  }
1282
1439
  };
1283
- var usageSchema = import_zod5.z.object({
1284
- prompt_tokens: import_zod5.z.number(),
1285
- completion_tokens: import_zod5.z.number(),
1286
- total_tokens: import_zod5.z.number()
1440
+ var usageSchema = import_v47.z.object({
1441
+ prompt_tokens: import_v47.z.number(),
1442
+ completion_tokens: import_v47.z.number(),
1443
+ total_tokens: import_v47.z.number()
1287
1444
  });
1288
- var openaiCompletionResponseSchema = import_zod5.z.object({
1289
- id: import_zod5.z.string().nullish(),
1290
- created: import_zod5.z.number().nullish(),
1291
- model: import_zod5.z.string().nullish(),
1292
- choices: import_zod5.z.array(
1293
- import_zod5.z.object({
1294
- text: import_zod5.z.string(),
1295
- finish_reason: import_zod5.z.string(),
1296
- logprobs: import_zod5.z.object({
1297
- tokens: import_zod5.z.array(import_zod5.z.string()),
1298
- token_logprobs: import_zod5.z.array(import_zod5.z.number()),
1299
- top_logprobs: import_zod5.z.array(import_zod5.z.record(import_zod5.z.string(), import_zod5.z.number())).nullish()
1445
+ var openaiCompletionResponseSchema = import_v47.z.object({
1446
+ id: import_v47.z.string().nullish(),
1447
+ created: import_v47.z.number().nullish(),
1448
+ model: import_v47.z.string().nullish(),
1449
+ choices: import_v47.z.array(
1450
+ import_v47.z.object({
1451
+ text: import_v47.z.string(),
1452
+ finish_reason: import_v47.z.string(),
1453
+ logprobs: import_v47.z.object({
1454
+ tokens: import_v47.z.array(import_v47.z.string()),
1455
+ token_logprobs: import_v47.z.array(import_v47.z.number()),
1456
+ top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
1300
1457
  }).nullish()
1301
1458
  })
1302
1459
  ),
1303
1460
  usage: usageSchema.nullish()
1304
1461
  });
1305
- var openaiCompletionChunkSchema = import_zod5.z.union([
1306
- import_zod5.z.object({
1307
- id: import_zod5.z.string().nullish(),
1308
- created: import_zod5.z.number().nullish(),
1309
- model: import_zod5.z.string().nullish(),
1310
- choices: import_zod5.z.array(
1311
- import_zod5.z.object({
1312
- text: import_zod5.z.string(),
1313
- finish_reason: import_zod5.z.string().nullish(),
1314
- index: import_zod5.z.number(),
1315
- logprobs: import_zod5.z.object({
1316
- tokens: import_zod5.z.array(import_zod5.z.string()),
1317
- token_logprobs: import_zod5.z.array(import_zod5.z.number()),
1318
- top_logprobs: import_zod5.z.array(import_zod5.z.record(import_zod5.z.string(), import_zod5.z.number())).nullish()
1462
+ var openaiCompletionChunkSchema = import_v47.z.union([
1463
+ import_v47.z.object({
1464
+ id: import_v47.z.string().nullish(),
1465
+ created: import_v47.z.number().nullish(),
1466
+ model: import_v47.z.string().nullish(),
1467
+ choices: import_v47.z.array(
1468
+ import_v47.z.object({
1469
+ text: import_v47.z.string(),
1470
+ finish_reason: import_v47.z.string().nullish(),
1471
+ index: import_v47.z.number(),
1472
+ logprobs: import_v47.z.object({
1473
+ tokens: import_v47.z.array(import_v47.z.string()),
1474
+ token_logprobs: import_v47.z.array(import_v47.z.number()),
1475
+ top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
1319
1476
  }).nullish()
1320
1477
  })
1321
1478
  ),
@@ -1326,22 +1483,22 @@ var openaiCompletionChunkSchema = import_zod5.z.union([
1326
1483
 
1327
1484
  // src/openai-embedding-model.ts
1328
1485
  var import_provider5 = require("@ai-sdk/provider");
1329
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1330
- var import_zod7 = require("zod");
1486
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1487
+ var import_v49 = require("zod/v4");
1331
1488
 
1332
1489
  // src/openai-embedding-options.ts
1333
- var import_zod6 = require("zod");
1334
- var openaiEmbeddingProviderOptions = import_zod6.z.object({
1490
+ var import_v48 = require("zod/v4");
1491
+ var openaiEmbeddingProviderOptions = import_v48.z.object({
1335
1492
  /**
1336
1493
  The number of dimensions the resulting output embeddings should have.
1337
1494
  Only supported in text-embedding-3 and later models.
1338
1495
  */
1339
- dimensions: import_zod6.z.number().optional(),
1496
+ dimensions: import_v48.z.number().optional(),
1340
1497
  /**
1341
1498
  A unique identifier representing your end-user, which can help OpenAI to
1342
1499
  monitor and detect abuse. Learn more.
1343
1500
  */
1344
- user: import_zod6.z.string().optional()
1501
+ user: import_v48.z.string().optional()
1345
1502
  });
1346
1503
 
1347
1504
  // src/openai-embedding-model.ts
@@ -1371,7 +1528,7 @@ var OpenAIEmbeddingModel = class {
1371
1528
  values
1372
1529
  });
1373
1530
  }
1374
- const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
1531
+ const openaiOptions = (_a = await (0, import_provider_utils7.parseProviderOptions)({
1375
1532
  provider: "openai",
1376
1533
  providerOptions,
1377
1534
  schema: openaiEmbeddingProviderOptions
@@ -1380,12 +1537,12 @@ var OpenAIEmbeddingModel = class {
1380
1537
  responseHeaders,
1381
1538
  value: response,
1382
1539
  rawValue
1383
- } = await (0, import_provider_utils5.postJsonToApi)({
1540
+ } = await (0, import_provider_utils7.postJsonToApi)({
1384
1541
  url: this.config.url({
1385
1542
  path: "/embeddings",
1386
1543
  modelId: this.modelId
1387
1544
  }),
1388
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers),
1545
+ headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), headers),
1389
1546
  body: {
1390
1547
  model: this.modelId,
1391
1548
  input: values,
@@ -1394,7 +1551,7 @@ var OpenAIEmbeddingModel = class {
1394
1551
  user: openaiOptions.user
1395
1552
  },
1396
1553
  failedResponseHandler: openaiFailedResponseHandler,
1397
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1554
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1398
1555
  openaiTextEmbeddingResponseSchema
1399
1556
  ),
1400
1557
  abortSignal,
@@ -1407,14 +1564,14 @@ var OpenAIEmbeddingModel = class {
1407
1564
  };
1408
1565
  }
1409
1566
  };
1410
- var openaiTextEmbeddingResponseSchema = import_zod7.z.object({
1411
- data: import_zod7.z.array(import_zod7.z.object({ embedding: import_zod7.z.array(import_zod7.z.number()) })),
1412
- usage: import_zod7.z.object({ prompt_tokens: import_zod7.z.number() }).nullish()
1567
+ var openaiTextEmbeddingResponseSchema = import_v49.z.object({
1568
+ data: import_v49.z.array(import_v49.z.object({ embedding: import_v49.z.array(import_v49.z.number()) })),
1569
+ usage: import_v49.z.object({ prompt_tokens: import_v49.z.number() }).nullish()
1413
1570
  });
1414
1571
 
1415
1572
  // src/openai-image-model.ts
1416
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1417
- var import_zod8 = require("zod");
1573
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1574
+ var import_v410 = require("zod/v4");
1418
1575
 
1419
1576
  // src/openai-image-settings.ts
1420
1577
  var modelMaxImagesPerCall = {
@@ -1461,12 +1618,12 @@ var OpenAIImageModel = class {
1461
1618
  warnings.push({ type: "unsupported-setting", setting: "seed" });
1462
1619
  }
1463
1620
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1464
- const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
1621
+ const { value: response, responseHeaders } = await (0, import_provider_utils8.postJsonToApi)({
1465
1622
  url: this.config.url({
1466
1623
  path: "/images/generations",
1467
1624
  modelId: this.modelId
1468
1625
  }),
1469
- headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
1626
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), headers),
1470
1627
  body: {
1471
1628
  model: this.modelId,
1472
1629
  prompt,
@@ -1476,7 +1633,7 @@ var OpenAIImageModel = class {
1476
1633
  ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1477
1634
  },
1478
1635
  failedResponseHandler: openaiFailedResponseHandler,
1479
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1636
+ successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
1480
1637
  openaiImageResponseSchema
1481
1638
  ),
1482
1639
  abortSignal,
@@ -1502,62 +1659,47 @@ var OpenAIImageModel = class {
1502
1659
  };
1503
1660
  }
1504
1661
  };
1505
- var openaiImageResponseSchema = import_zod8.z.object({
1506
- data: import_zod8.z.array(
1507
- import_zod8.z.object({ b64_json: import_zod8.z.string(), revised_prompt: import_zod8.z.string().optional() })
1662
+ var openaiImageResponseSchema = import_v410.z.object({
1663
+ data: import_v410.z.array(
1664
+ import_v410.z.object({ b64_json: import_v410.z.string(), revised_prompt: import_v410.z.string().optional() })
1508
1665
  )
1509
1666
  });
1510
1667
 
1511
1668
  // src/openai-tools.ts
1512
- var import_zod9 = require("zod");
1513
- var WebSearchPreviewParameters = import_zod9.z.object({});
1514
- function webSearchPreviewTool({
1515
- searchContextSize,
1516
- userLocation
1517
- } = {}) {
1518
- return {
1519
- type: "provider-defined",
1520
- id: "openai.web_search_preview",
1521
- args: {
1522
- searchContextSize,
1523
- userLocation
1524
- },
1525
- parameters: WebSearchPreviewParameters
1526
- };
1527
- }
1528
1669
  var openaiTools = {
1529
- webSearchPreview: webSearchPreviewTool
1670
+ fileSearch,
1671
+ webSearchPreview
1530
1672
  };
1531
1673
 
1532
1674
  // src/openai-transcription-model.ts
1533
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1534
- var import_zod11 = require("zod");
1675
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1676
+ var import_v412 = require("zod/v4");
1535
1677
 
1536
1678
  // src/openai-transcription-options.ts
1537
- var import_zod10 = require("zod");
1538
- var openAITranscriptionProviderOptions = import_zod10.z.object({
1679
+ var import_v411 = require("zod/v4");
1680
+ var openAITranscriptionProviderOptions = import_v411.z.object({
1539
1681
  /**
1540
1682
  * Additional information to include in the transcription response.
1541
1683
  */
1542
- include: import_zod10.z.array(import_zod10.z.string()).optional(),
1684
+ include: import_v411.z.array(import_v411.z.string()).optional(),
1543
1685
  /**
1544
1686
  * The language of the input audio in ISO-639-1 format.
1545
1687
  */
1546
- language: import_zod10.z.string().optional(),
1688
+ language: import_v411.z.string().optional(),
1547
1689
  /**
1548
1690
  * An optional text to guide the model's style or continue a previous audio segment.
1549
1691
  */
1550
- prompt: import_zod10.z.string().optional(),
1692
+ prompt: import_v411.z.string().optional(),
1551
1693
  /**
1552
1694
  * The sampling temperature, between 0 and 1.
1553
1695
  * @default 0
1554
1696
  */
1555
- temperature: import_zod10.z.number().min(0).max(1).default(0).optional(),
1697
+ temperature: import_v411.z.number().min(0).max(1).default(0).optional(),
1556
1698
  /**
1557
1699
  * The timestamp granularities to populate for this transcription.
1558
1700
  * @default ['segment']
1559
1701
  */
1560
- timestampGranularities: import_zod10.z.array(import_zod10.z.enum(["word", "segment"])).default(["segment"]).optional()
1702
+ timestampGranularities: import_v411.z.array(import_v411.z.enum(["word", "segment"])).default(["segment"]).optional()
1561
1703
  });
1562
1704
 
1563
1705
  // src/openai-transcription-model.ts
@@ -1624,7 +1766,7 @@ var OpenAITranscriptionModel = class {
1624
1766
  constructor(modelId, config) {
1625
1767
  this.modelId = modelId;
1626
1768
  this.config = config;
1627
- this.specificationVersion = "v1";
1769
+ this.specificationVersion = "v2";
1628
1770
  }
1629
1771
  get provider() {
1630
1772
  return this.config.provider;
@@ -1635,13 +1777,13 @@ var OpenAITranscriptionModel = class {
1635
1777
  providerOptions
1636
1778
  }) {
1637
1779
  const warnings = [];
1638
- const openAIOptions = await (0, import_provider_utils7.parseProviderOptions)({
1780
+ const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
1639
1781
  provider: "openai",
1640
1782
  providerOptions,
1641
1783
  schema: openAITranscriptionProviderOptions
1642
1784
  });
1643
1785
  const formData = new FormData();
1644
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
1786
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils9.convertBase64ToUint8Array)(audio)]);
1645
1787
  formData.append("model", this.modelId);
1646
1788
  formData.append("file", new File([blob], "audio", { type: mediaType }));
1647
1789
  if (openAIOptions) {
@@ -1671,15 +1813,15 @@ var OpenAITranscriptionModel = class {
1671
1813
  value: response,
1672
1814
  responseHeaders,
1673
1815
  rawValue: rawResponse
1674
- } = await (0, import_provider_utils7.postFormDataToApi)({
1816
+ } = await (0, import_provider_utils9.postFormDataToApi)({
1675
1817
  url: this.config.url({
1676
1818
  path: "/audio/transcriptions",
1677
1819
  modelId: this.modelId
1678
1820
  }),
1679
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1821
+ headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
1680
1822
  formData,
1681
1823
  failedResponseHandler: openaiFailedResponseHandler,
1682
- successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1824
+ successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
1683
1825
  openaiTranscriptionResponseSchema
1684
1826
  ),
1685
1827
  abortSignal: options.abortSignal,
@@ -1705,22 +1847,22 @@ var OpenAITranscriptionModel = class {
1705
1847
  };
1706
1848
  }
1707
1849
  };
1708
- var openaiTranscriptionResponseSchema = import_zod11.z.object({
1709
- text: import_zod11.z.string(),
1710
- language: import_zod11.z.string().nullish(),
1711
- duration: import_zod11.z.number().nullish(),
1712
- words: import_zod11.z.array(
1713
- import_zod11.z.object({
1714
- word: import_zod11.z.string(),
1715
- start: import_zod11.z.number(),
1716
- end: import_zod11.z.number()
1850
+ var openaiTranscriptionResponseSchema = import_v412.z.object({
1851
+ text: import_v412.z.string(),
1852
+ language: import_v412.z.string().nullish(),
1853
+ duration: import_v412.z.number().nullish(),
1854
+ words: import_v412.z.array(
1855
+ import_v412.z.object({
1856
+ word: import_v412.z.string(),
1857
+ start: import_v412.z.number(),
1858
+ end: import_v412.z.number()
1717
1859
  })
1718
1860
  ).nullish()
1719
1861
  });
1720
1862
 
1721
1863
  // src/responses/openai-responses-language-model.ts
1722
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1723
- var import_zod12 = require("zod");
1864
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1865
+ var import_v413 = require("zod/v4");
1724
1866
 
1725
1867
  // src/responses/convert-to-openai-responses-messages.ts
1726
1868
  var import_provider6 = require("@ai-sdk/provider");
@@ -1809,11 +1951,21 @@ function convertToOpenAIResponsesMessages({
1809
1951
  break;
1810
1952
  }
1811
1953
  case "tool-call": {
1954
+ if (part.providerExecuted) {
1955
+ break;
1956
+ }
1812
1957
  messages.push({
1813
1958
  type: "function_call",
1814
1959
  call_id: part.toolCallId,
1815
1960
  name: part.toolName,
1816
- arguments: JSON.stringify(part.args)
1961
+ arguments: JSON.stringify(part.input)
1962
+ });
1963
+ break;
1964
+ }
1965
+ case "tool-result": {
1966
+ warnings.push({
1967
+ type: "other",
1968
+ message: `tool result parts in assistant messages are not supported for OpenAI responses`
1817
1969
  });
1818
1970
  break;
1819
1971
  }
@@ -1823,10 +1975,23 @@ function convertToOpenAIResponsesMessages({
1823
1975
  }
1824
1976
  case "tool": {
1825
1977
  for (const part of content) {
1978
+ const output = part.output;
1979
+ let contentValue;
1980
+ switch (output.type) {
1981
+ case "text":
1982
+ case "error-text":
1983
+ contentValue = output.value;
1984
+ break;
1985
+ case "content":
1986
+ case "json":
1987
+ case "error-json":
1988
+ contentValue = JSON.stringify(output.value);
1989
+ break;
1990
+ }
1826
1991
  messages.push({
1827
1992
  type: "function_call_output",
1828
1993
  call_id: part.toolCallId,
1829
- output: JSON.stringify(part.result)
1994
+ output: contentValue
1830
1995
  });
1831
1996
  }
1832
1997
  break;
@@ -1878,7 +2043,7 @@ function prepareResponsesTools({
1878
2043
  type: "function",
1879
2044
  name: tool.name,
1880
2045
  description: tool.description,
1881
- parameters: tool.parameters,
2046
+ parameters: tool.inputSchema,
1882
2047
  strict: strict ? true : void 0
1883
2048
  });
1884
2049
  break;
@@ -1982,7 +2147,7 @@ var OpenAIResponsesLanguageModel = class {
1982
2147
  systemMessageMode: modelConfig.systemMessageMode
1983
2148
  });
1984
2149
  warnings.push(...messageWarnings);
1985
- const openaiOptions = await (0, import_provider_utils8.parseProviderOptions)({
2150
+ const openaiOptions = await (0, import_provider_utils10.parseProviderOptions)({
1986
2151
  provider: "openai",
1987
2152
  providerOptions,
1988
2153
  schema: openaiResponsesProviderOptionsSchema
@@ -2012,6 +2177,7 @@ var OpenAIResponsesLanguageModel = class {
2012
2177
  store: openaiOptions == null ? void 0 : openaiOptions.store,
2013
2178
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2014
2179
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2180
+ service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2015
2181
  // model-specific settings:
2016
2182
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2017
2183
  reasoning: {
@@ -2045,6 +2211,14 @@ var OpenAIResponsesLanguageModel = class {
2045
2211
  });
2046
2212
  }
2047
2213
  }
2214
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2215
+ warnings.push({
2216
+ type: "unsupported-setting",
2217
+ setting: "serviceTier",
2218
+ details: "flex processing is only available for o3 and o4-mini models"
2219
+ });
2220
+ delete baseArgs.service_tier;
2221
+ }
2048
2222
  const {
2049
2223
  tools: openaiTools2,
2050
2224
  toolChoice: openaiToolChoice,
@@ -2070,64 +2244,68 @@ var OpenAIResponsesLanguageModel = class {
2070
2244
  responseHeaders,
2071
2245
  value: response,
2072
2246
  rawValue: rawResponse
2073
- } = await (0, import_provider_utils8.postJsonToApi)({
2247
+ } = await (0, import_provider_utils10.postJsonToApi)({
2074
2248
  url: this.config.url({
2075
2249
  path: "/responses",
2076
2250
  modelId: this.modelId
2077
2251
  }),
2078
- headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
2252
+ headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
2079
2253
  body,
2080
2254
  failedResponseHandler: openaiFailedResponseHandler,
2081
- successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
2082
- import_zod12.z.object({
2083
- id: import_zod12.z.string(),
2084
- created_at: import_zod12.z.number(),
2085
- model: import_zod12.z.string(),
2086
- output: import_zod12.z.array(
2087
- import_zod12.z.discriminatedUnion("type", [
2088
- import_zod12.z.object({
2089
- type: import_zod12.z.literal("message"),
2090
- role: import_zod12.z.literal("assistant"),
2091
- content: import_zod12.z.array(
2092
- import_zod12.z.object({
2093
- type: import_zod12.z.literal("output_text"),
2094
- text: import_zod12.z.string(),
2095
- annotations: import_zod12.z.array(
2096
- import_zod12.z.object({
2097
- type: import_zod12.z.literal("url_citation"),
2098
- start_index: import_zod12.z.number(),
2099
- end_index: import_zod12.z.number(),
2100
- url: import_zod12.z.string(),
2101
- title: import_zod12.z.string()
2255
+ successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
2256
+ import_v413.z.object({
2257
+ id: import_v413.z.string(),
2258
+ created_at: import_v413.z.number(),
2259
+ model: import_v413.z.string(),
2260
+ output: import_v413.z.array(
2261
+ import_v413.z.discriminatedUnion("type", [
2262
+ import_v413.z.object({
2263
+ type: import_v413.z.literal("message"),
2264
+ role: import_v413.z.literal("assistant"),
2265
+ content: import_v413.z.array(
2266
+ import_v413.z.object({
2267
+ type: import_v413.z.literal("output_text"),
2268
+ text: import_v413.z.string(),
2269
+ annotations: import_v413.z.array(
2270
+ import_v413.z.object({
2271
+ type: import_v413.z.literal("url_citation"),
2272
+ start_index: import_v413.z.number(),
2273
+ end_index: import_v413.z.number(),
2274
+ url: import_v413.z.string(),
2275
+ title: import_v413.z.string()
2102
2276
  })
2103
2277
  )
2104
2278
  })
2105
2279
  )
2106
2280
  }),
2107
- import_zod12.z.object({
2108
- type: import_zod12.z.literal("function_call"),
2109
- call_id: import_zod12.z.string(),
2110
- name: import_zod12.z.string(),
2111
- arguments: import_zod12.z.string()
2281
+ import_v413.z.object({
2282
+ type: import_v413.z.literal("function_call"),
2283
+ call_id: import_v413.z.string(),
2284
+ name: import_v413.z.string(),
2285
+ arguments: import_v413.z.string()
2112
2286
  }),
2113
- import_zod12.z.object({
2114
- type: import_zod12.z.literal("web_search_call")
2287
+ import_v413.z.object({
2288
+ type: import_v413.z.literal("web_search_call"),
2289
+ id: import_v413.z.string(),
2290
+ status: import_v413.z.string().optional()
2115
2291
  }),
2116
- import_zod12.z.object({
2117
- type: import_zod12.z.literal("computer_call")
2292
+ import_v413.z.object({
2293
+ type: import_v413.z.literal("computer_call"),
2294
+ id: import_v413.z.string(),
2295
+ status: import_v413.z.string().optional()
2118
2296
  }),
2119
- import_zod12.z.object({
2120
- type: import_zod12.z.literal("reasoning"),
2121
- summary: import_zod12.z.array(
2122
- import_zod12.z.object({
2123
- type: import_zod12.z.literal("summary_text"),
2124
- text: import_zod12.z.string()
2297
+ import_v413.z.object({
2298
+ type: import_v413.z.literal("reasoning"),
2299
+ summary: import_v413.z.array(
2300
+ import_v413.z.object({
2301
+ type: import_v413.z.literal("summary_text"),
2302
+ text: import_v413.z.string()
2125
2303
  })
2126
2304
  )
2127
2305
  })
2128
2306
  ])
2129
2307
  ),
2130
- incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullable(),
2308
+ incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullable(),
2131
2309
  usage: usageSchema2
2132
2310
  })
2133
2311
  ),
@@ -2154,7 +2332,7 @@ var OpenAIResponsesLanguageModel = class {
2154
2332
  content.push({
2155
2333
  type: "source",
2156
2334
  sourceType: "url",
2157
- id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils8.generateId)(),
2335
+ id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils10.generateId)(),
2158
2336
  url: annotation.url,
2159
2337
  title: annotation.title
2160
2338
  });
@@ -2165,10 +2343,46 @@ var OpenAIResponsesLanguageModel = class {
2165
2343
  case "function_call": {
2166
2344
  content.push({
2167
2345
  type: "tool-call",
2168
- toolCallType: "function",
2169
2346
  toolCallId: part.call_id,
2170
2347
  toolName: part.name,
2171
- args: part.arguments
2348
+ input: part.arguments
2349
+ });
2350
+ break;
2351
+ }
2352
+ case "web_search_call": {
2353
+ content.push({
2354
+ type: "tool-call",
2355
+ toolCallId: part.id,
2356
+ toolName: "web_search_preview",
2357
+ input: "",
2358
+ providerExecuted: true
2359
+ });
2360
+ content.push({
2361
+ type: "tool-result",
2362
+ toolCallId: part.id,
2363
+ toolName: "web_search_preview",
2364
+ result: { status: part.status || "completed" },
2365
+ providerExecuted: true
2366
+ });
2367
+ break;
2368
+ }
2369
+ case "computer_call": {
2370
+ content.push({
2371
+ type: "tool-call",
2372
+ toolCallId: part.id,
2373
+ toolName: "computer_use",
2374
+ input: "",
2375
+ providerExecuted: true
2376
+ });
2377
+ content.push({
2378
+ type: "tool-result",
2379
+ toolCallId: part.id,
2380
+ toolName: "computer_use",
2381
+ result: {
2382
+ type: "computer_use_tool_result",
2383
+ status: part.status || "completed"
2384
+ },
2385
+ providerExecuted: true
2172
2386
  });
2173
2387
  break;
2174
2388
  }
@@ -2205,18 +2419,18 @@ var OpenAIResponsesLanguageModel = class {
2205
2419
  }
2206
2420
  async doStream(options) {
2207
2421
  const { args: body, warnings } = await this.getArgs(options);
2208
- const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
2422
+ const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
2209
2423
  url: this.config.url({
2210
2424
  path: "/responses",
2211
2425
  modelId: this.modelId
2212
2426
  }),
2213
- headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
2427
+ headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
2214
2428
  body: {
2215
2429
  ...body,
2216
2430
  stream: true
2217
2431
  },
2218
2432
  failedResponseHandler: openaiFailedResponseHandler,
2219
- successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(
2433
+ successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
2220
2434
  openaiResponsesChunkSchema
2221
2435
  ),
2222
2436
  abortSignal: options.abortSignal,
@@ -2240,6 +2454,9 @@ var OpenAIResponsesLanguageModel = class {
2240
2454
  },
2241
2455
  transform(chunk, controller) {
2242
2456
  var _a, _b, _c, _d, _e, _f, _g, _h;
2457
+ if (options.includeRawChunks) {
2458
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2459
+ }
2243
2460
  if (!chunk.success) {
2244
2461
  finishReason = "error";
2245
2462
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2253,22 +2470,121 @@ var OpenAIResponsesLanguageModel = class {
2253
2470
  toolCallId: value.item.call_id
2254
2471
  };
2255
2472
  controller.enqueue({
2256
- type: "tool-call-delta",
2257
- toolCallType: "function",
2473
+ type: "tool-input-start",
2474
+ id: value.item.call_id,
2475
+ toolName: value.item.name
2476
+ });
2477
+ } else if (value.item.type === "web_search_call") {
2478
+ ongoingToolCalls[value.output_index] = {
2479
+ toolName: "web_search_preview",
2480
+ toolCallId: value.item.id
2481
+ };
2482
+ controller.enqueue({
2483
+ type: "tool-input-start",
2484
+ id: value.item.id,
2485
+ toolName: "web_search_preview"
2486
+ });
2487
+ } else if (value.item.type === "computer_call") {
2488
+ ongoingToolCalls[value.output_index] = {
2489
+ toolName: "computer_use",
2490
+ toolCallId: value.item.id
2491
+ };
2492
+ controller.enqueue({
2493
+ type: "tool-input-start",
2494
+ id: value.item.id,
2495
+ toolName: "computer_use"
2496
+ });
2497
+ } else if (value.item.type === "message") {
2498
+ controller.enqueue({
2499
+ type: "text-start",
2500
+ id: value.item.id
2501
+ });
2502
+ } else if (value.item.type === "reasoning") {
2503
+ controller.enqueue({
2504
+ type: "reasoning-start",
2505
+ id: value.item.id
2506
+ });
2507
+ }
2508
+ } else if (isResponseOutputItemDoneChunk(value)) {
2509
+ if (value.item.type === "function_call") {
2510
+ ongoingToolCalls[value.output_index] = void 0;
2511
+ hasToolCalls = true;
2512
+ controller.enqueue({
2513
+ type: "tool-input-end",
2514
+ id: value.item.call_id
2515
+ });
2516
+ controller.enqueue({
2517
+ type: "tool-call",
2258
2518
  toolCallId: value.item.call_id,
2259
2519
  toolName: value.item.name,
2260
- argsTextDelta: value.item.arguments
2520
+ input: value.item.arguments
2521
+ });
2522
+ } else if (value.item.type === "web_search_call") {
2523
+ ongoingToolCalls[value.output_index] = void 0;
2524
+ hasToolCalls = true;
2525
+ controller.enqueue({
2526
+ type: "tool-input-end",
2527
+ id: value.item.id
2528
+ });
2529
+ controller.enqueue({
2530
+ type: "tool-call",
2531
+ toolCallId: value.item.id,
2532
+ toolName: "web_search_preview",
2533
+ input: "",
2534
+ providerExecuted: true
2535
+ });
2536
+ controller.enqueue({
2537
+ type: "tool-result",
2538
+ toolCallId: value.item.id,
2539
+ toolName: "web_search_preview",
2540
+ result: {
2541
+ type: "web_search_tool_result",
2542
+ status: value.item.status || "completed"
2543
+ },
2544
+ providerExecuted: true
2545
+ });
2546
+ } else if (value.item.type === "computer_call") {
2547
+ ongoingToolCalls[value.output_index] = void 0;
2548
+ hasToolCalls = true;
2549
+ controller.enqueue({
2550
+ type: "tool-input-end",
2551
+ id: value.item.id
2552
+ });
2553
+ controller.enqueue({
2554
+ type: "tool-call",
2555
+ toolCallId: value.item.id,
2556
+ toolName: "computer_use",
2557
+ input: "",
2558
+ providerExecuted: true
2559
+ });
2560
+ controller.enqueue({
2561
+ type: "tool-result",
2562
+ toolCallId: value.item.id,
2563
+ toolName: "computer_use",
2564
+ result: {
2565
+ type: "computer_use_tool_result",
2566
+ status: value.item.status || "completed"
2567
+ },
2568
+ providerExecuted: true
2569
+ });
2570
+ } else if (value.item.type === "message") {
2571
+ controller.enqueue({
2572
+ type: "text-end",
2573
+ id: value.item.id
2574
+ });
2575
+ } else if (value.item.type === "reasoning") {
2576
+ controller.enqueue({
2577
+ type: "reasoning-end",
2578
+ id: value.item.id
2261
2579
  });
2262
2580
  }
2263
2581
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
2264
2582
  const toolCall = ongoingToolCalls[value.output_index];
2265
2583
  if (toolCall != null) {
2266
2584
  controller.enqueue({
2267
- type: "tool-call-delta",
2268
- toolCallType: "function",
2269
- toolCallId: toolCall.toolCallId,
2270
- toolName: toolCall.toolName,
2271
- argsTextDelta: value.delta
2585
+ type: "tool-input-delta",
2586
+ id: toolCall.toolCallId,
2587
+ delta: value.delta
2272
2588
  });
2273
2589
  }
2274
2590
  } else if (isResponseCreatedChunk(value)) {
@@ -2281,23 +2597,15 @@ var OpenAIResponsesLanguageModel = class {
2281
2597
  });
2282
2598
  } else if (isTextDeltaChunk(value)) {
2283
2599
  controller.enqueue({
2284
- type: "text",
2285
- text: value.delta
2600
+ type: "text-delta",
2601
+ id: value.item_id,
2602
+ delta: value.delta
2286
2603
  });
2287
2604
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2288
2605
  controller.enqueue({
2289
- type: "reasoning",
2290
- text: value.delta
2291
- });
2292
- } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2293
- ongoingToolCalls[value.output_index] = void 0;
2294
- hasToolCalls = true;
2295
- controller.enqueue({
2296
- type: "tool-call",
2297
- toolCallType: "function",
2298
- toolCallId: value.item.call_id,
2299
- toolName: value.item.name,
2300
- args: value.item.arguments
2606
+ type: "reasoning-delta",
2607
+ delta: value.delta,
2608
+ id: value.item_id
2301
2609
  });
2302
2610
  } else if (isResponseFinishedChunk(value)) {
2303
2611
  finishReason = mapOpenAIResponseFinishReason({
@@ -2313,7 +2621,7 @@ var OpenAIResponsesLanguageModel = class {
2313
2621
  controller.enqueue({
2314
2622
  type: "source",
2315
2623
  sourceType: "url",
2316
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils8.generateId)(),
2624
+ id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
2317
2625
  url: value.annotation.url,
2318
2626
  title: value.annotation.title
2319
2627
  });
@@ -2338,95 +2646,134 @@ var OpenAIResponsesLanguageModel = class {
2338
2646
  };
2339
2647
  }
2340
2648
  };
2341
- var usageSchema2 = import_zod12.z.object({
2342
- input_tokens: import_zod12.z.number(),
2343
- input_tokens_details: import_zod12.z.object({ cached_tokens: import_zod12.z.number().nullish() }).nullish(),
2344
- output_tokens: import_zod12.z.number(),
2345
- output_tokens_details: import_zod12.z.object({ reasoning_tokens: import_zod12.z.number().nullish() }).nullish()
2649
+ var usageSchema2 = import_v413.z.object({
2650
+ input_tokens: import_v413.z.number(),
2651
+ input_tokens_details: import_v413.z.object({ cached_tokens: import_v413.z.number().nullish() }).nullish(),
2652
+ output_tokens: import_v413.z.number(),
2653
+ output_tokens_details: import_v413.z.object({ reasoning_tokens: import_v413.z.number().nullish() }).nullish()
2346
2654
  });
2347
- var textDeltaChunkSchema = import_zod12.z.object({
2348
- type: import_zod12.z.literal("response.output_text.delta"),
2349
- delta: import_zod12.z.string()
2655
+ var textDeltaChunkSchema = import_v413.z.object({
2656
+ type: import_v413.z.literal("response.output_text.delta"),
2657
+ item_id: import_v413.z.string(),
2658
+ delta: import_v413.z.string()
2350
2659
  });
2351
- var responseFinishedChunkSchema = import_zod12.z.object({
2352
- type: import_zod12.z.enum(["response.completed", "response.incomplete"]),
2353
- response: import_zod12.z.object({
2354
- incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullish(),
2660
+ var responseFinishedChunkSchema = import_v413.z.object({
2661
+ type: import_v413.z.enum(["response.completed", "response.incomplete"]),
2662
+ response: import_v413.z.object({
2663
+ incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullish(),
2355
2664
  usage: usageSchema2
2356
2665
  })
2357
2666
  });
2358
- var responseCreatedChunkSchema = import_zod12.z.object({
2359
- type: import_zod12.z.literal("response.created"),
2360
- response: import_zod12.z.object({
2361
- id: import_zod12.z.string(),
2362
- created_at: import_zod12.z.number(),
2363
- model: import_zod12.z.string()
2667
+ var responseCreatedChunkSchema = import_v413.z.object({
2668
+ type: import_v413.z.literal("response.created"),
2669
+ response: import_v413.z.object({
2670
+ id: import_v413.z.string(),
2671
+ created_at: import_v413.z.number(),
2672
+ model: import_v413.z.string()
2364
2673
  })
2365
2674
  });
2366
- var responseOutputItemDoneSchema = import_zod12.z.object({
2367
- type: import_zod12.z.literal("response.output_item.done"),
2368
- output_index: import_zod12.z.number(),
2369
- item: import_zod12.z.discriminatedUnion("type", [
2370
- import_zod12.z.object({
2371
- type: import_zod12.z.literal("message")
2675
+ var responseOutputItemAddedSchema = import_v413.z.object({
2676
+ type: import_v413.z.literal("response.output_item.added"),
2677
+ output_index: import_v413.z.number(),
2678
+ item: import_v413.z.discriminatedUnion("type", [
2679
+ import_v413.z.object({
2680
+ type: import_v413.z.literal("message"),
2681
+ id: import_v413.z.string()
2682
+ }),
2683
+ import_v413.z.object({
2684
+ type: import_v413.z.literal("reasoning"),
2685
+ id: import_v413.z.string()
2686
+ }),
2687
+ import_v413.z.object({
2688
+ type: import_v413.z.literal("function_call"),
2689
+ id: import_v413.z.string(),
2690
+ call_id: import_v413.z.string(),
2691
+ name: import_v413.z.string(),
2692
+ arguments: import_v413.z.string()
2693
+ }),
2694
+ import_v413.z.object({
2695
+ type: import_v413.z.literal("web_search_call"),
2696
+ id: import_v413.z.string(),
2697
+ status: import_v413.z.string()
2372
2698
  }),
2373
- import_zod12.z.object({
2374
- type: import_zod12.z.literal("function_call"),
2375
- id: import_zod12.z.string(),
2376
- call_id: import_zod12.z.string(),
2377
- name: import_zod12.z.string(),
2378
- arguments: import_zod12.z.string(),
2379
- status: import_zod12.z.literal("completed")
2699
+ import_v413.z.object({
2700
+ type: import_v413.z.literal("computer_call"),
2701
+ id: import_v413.z.string(),
2702
+ status: import_v413.z.string()
2380
2703
  })
2381
2704
  ])
2382
2705
  });
2383
- var responseFunctionCallArgumentsDeltaSchema = import_zod12.z.object({
2384
- type: import_zod12.z.literal("response.function_call_arguments.delta"),
2385
- item_id: import_zod12.z.string(),
2386
- output_index: import_zod12.z.number(),
2387
- delta: import_zod12.z.string()
2388
- });
2389
- var responseOutputItemAddedSchema = import_zod12.z.object({
2390
- type: import_zod12.z.literal("response.output_item.added"),
2391
- output_index: import_zod12.z.number(),
2392
- item: import_zod12.z.discriminatedUnion("type", [
2393
- import_zod12.z.object({
2394
- type: import_zod12.z.literal("message")
2706
+ var responseOutputItemDoneSchema = import_v413.z.object({
2707
+ type: import_v413.z.literal("response.output_item.done"),
2708
+ output_index: import_v413.z.number(),
2709
+ item: import_v413.z.discriminatedUnion("type", [
2710
+ import_v413.z.object({
2711
+ type: import_v413.z.literal("message"),
2712
+ id: import_v413.z.string()
2713
+ }),
2714
+ import_v413.z.object({
2715
+ type: import_v413.z.literal("reasoning"),
2716
+ id: import_v413.z.string()
2717
+ }),
2718
+ import_v413.z.object({
2719
+ type: import_v413.z.literal("function_call"),
2720
+ id: import_v413.z.string(),
2721
+ call_id: import_v413.z.string(),
2722
+ name: import_v413.z.string(),
2723
+ arguments: import_v413.z.string(),
2724
+ status: import_v413.z.literal("completed")
2395
2725
  }),
2396
- import_zod12.z.object({
2397
- type: import_zod12.z.literal("function_call"),
2398
- id: import_zod12.z.string(),
2399
- call_id: import_zod12.z.string(),
2400
- name: import_zod12.z.string(),
2401
- arguments: import_zod12.z.string()
2726
+ import_v413.z.object({
2727
+ type: import_v413.z.literal("web_search_call"),
2728
+ id: import_v413.z.string(),
2729
+ status: import_v413.z.literal("completed")
2730
+ }),
2731
+ import_v413.z.object({
2732
+ type: import_v413.z.literal("computer_call"),
2733
+ id: import_v413.z.string(),
2734
+ status: import_v413.z.literal("completed")
2402
2735
  })
2403
2736
  ])
2404
2737
  });
2405
- var responseAnnotationAddedSchema = import_zod12.z.object({
2406
- type: import_zod12.z.literal("response.output_text.annotation.added"),
2407
- annotation: import_zod12.z.object({
2408
- type: import_zod12.z.literal("url_citation"),
2409
- url: import_zod12.z.string(),
2410
- title: import_zod12.z.string()
2738
+ var responseFunctionCallArgumentsDeltaSchema = import_v413.z.object({
2739
+ type: import_v413.z.literal("response.function_call_arguments.delta"),
2740
+ item_id: import_v413.z.string(),
2741
+ output_index: import_v413.z.number(),
2742
+ delta: import_v413.z.string()
2743
+ });
2744
+ var responseAnnotationAddedSchema = import_v413.z.object({
2745
+ type: import_v413.z.literal("response.output_text.annotation.added"),
2746
+ annotation: import_v413.z.object({
2747
+ type: import_v413.z.literal("url_citation"),
2748
+ url: import_v413.z.string(),
2749
+ title: import_v413.z.string()
2411
2750
  })
2412
2751
  });
2413
- var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
2414
- type: import_zod12.z.literal("response.reasoning_summary_text.delta"),
2415
- item_id: import_zod12.z.string(),
2416
- output_index: import_zod12.z.number(),
2417
- summary_index: import_zod12.z.number(),
2418
- delta: import_zod12.z.string()
2752
+ var responseReasoningSummaryTextDeltaSchema = import_v413.z.object({
2753
+ type: import_v413.z.literal("response.reasoning_summary_text.delta"),
2754
+ item_id: import_v413.z.string(),
2755
+ output_index: import_v413.z.number(),
2756
+ summary_index: import_v413.z.number(),
2757
+ delta: import_v413.z.string()
2758
+ });
2759
+ var responseReasoningSummaryPartDoneSchema = import_v413.z.object({
2760
+ type: import_v413.z.literal("response.reasoning_summary_part.done"),
2761
+ item_id: import_v413.z.string(),
2762
+ output_index: import_v413.z.number(),
2763
+ summary_index: import_v413.z.number(),
2764
+ part: import_v413.z.unknown().nullish()
2419
2765
  });
2420
- var openaiResponsesChunkSchema = import_zod12.z.union([
2766
+ var openaiResponsesChunkSchema = import_v413.z.union([
2421
2767
  textDeltaChunkSchema,
2422
2768
  responseFinishedChunkSchema,
2423
2769
  responseCreatedChunkSchema,
2770
+ responseOutputItemAddedSchema,
2424
2771
  responseOutputItemDoneSchema,
2425
2772
  responseFunctionCallArgumentsDeltaSchema,
2426
- responseOutputItemAddedSchema,
2427
2773
  responseAnnotationAddedSchema,
2428
2774
  responseReasoningSummaryTextDeltaSchema,
2429
- import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
2775
+ responseReasoningSummaryPartDoneSchema,
2776
+ import_v413.z.object({ type: import_v413.z.string() }).passthrough()
2430
2777
  // fallback for unknown chunks
2431
2778
  ]);
2432
2779
  function isTextDeltaChunk(chunk) {
@@ -2474,30 +2821,34 @@ function getResponsesModelConfig(modelId) {
2474
2821
  requiredAutoTruncation: false
2475
2822
  };
2476
2823
  }
2477
- var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
2478
- metadata: import_zod12.z.any().nullish(),
2479
- parallelToolCalls: import_zod12.z.boolean().nullish(),
2480
- previousResponseId: import_zod12.z.string().nullish(),
2481
- store: import_zod12.z.boolean().nullish(),
2482
- user: import_zod12.z.string().nullish(),
2483
- reasoningEffort: import_zod12.z.string().nullish(),
2484
- strictSchemas: import_zod12.z.boolean().nullish(),
2485
- instructions: import_zod12.z.string().nullish(),
2486
- reasoningSummary: import_zod12.z.string().nullish()
2824
+ function supportsFlexProcessing2(modelId) {
2825
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
2826
+ }
2827
+ var openaiResponsesProviderOptionsSchema = import_v413.z.object({
2828
+ metadata: import_v413.z.any().nullish(),
2829
+ parallelToolCalls: import_v413.z.boolean().nullish(),
2830
+ previousResponseId: import_v413.z.string().nullish(),
2831
+ store: import_v413.z.boolean().nullish(),
2832
+ user: import_v413.z.string().nullish(),
2833
+ reasoningEffort: import_v413.z.string().nullish(),
2834
+ strictSchemas: import_v413.z.boolean().nullish(),
2835
+ instructions: import_v413.z.string().nullish(),
2836
+ reasoningSummary: import_v413.z.string().nullish(),
2837
+ serviceTier: import_v413.z.enum(["auto", "flex"]).nullish()
2487
2838
  });
2488
2839
 
2489
2840
  // src/openai-speech-model.ts
2490
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2491
- var import_zod13 = require("zod");
2492
- var OpenAIProviderOptionsSchema = import_zod13.z.object({
2493
- instructions: import_zod13.z.string().nullish(),
2494
- speed: import_zod13.z.number().min(0.25).max(4).default(1).nullish()
2841
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2842
+ var import_v414 = require("zod/v4");
2843
+ var OpenAIProviderOptionsSchema = import_v414.z.object({
2844
+ instructions: import_v414.z.string().nullish(),
2845
+ speed: import_v414.z.number().min(0.25).max(4).default(1).nullish()
2495
2846
  });
2496
2847
  var OpenAISpeechModel = class {
2497
2848
  constructor(modelId, config) {
2498
2849
  this.modelId = modelId;
2499
2850
  this.config = config;
2500
- this.specificationVersion = "v1";
2851
+ this.specificationVersion = "v2";
2501
2852
  }
2502
2853
  get provider() {
2503
2854
  return this.config.provider;
@@ -2508,10 +2859,11 @@ var OpenAISpeechModel = class {
2508
2859
  outputFormat = "mp3",
2509
2860
  speed,
2510
2861
  instructions,
2862
+ language,
2511
2863
  providerOptions
2512
2864
  }) {
2513
2865
  const warnings = [];
2514
- const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
2866
+ const openAIOptions = await (0, import_provider_utils11.parseProviderOptions)({
2515
2867
  provider: "openai",
2516
2868
  providerOptions,
2517
2869
  schema: OpenAIProviderOptionsSchema
@@ -2544,6 +2896,13 @@ var OpenAISpeechModel = class {
2544
2896
  }
2545
2897
  }
2546
2898
  }
2899
+ if (language) {
2900
+ warnings.push({
2901
+ type: "unsupported-setting",
2902
+ setting: "language",
2903
+ details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
2904
+ });
2905
+ }
2547
2906
  return {
2548
2907
  requestBody,
2549
2908
  warnings
@@ -2557,15 +2916,15 @@ var OpenAISpeechModel = class {
2557
2916
  value: audio,
2558
2917
  responseHeaders,
2559
2918
  rawValue: rawResponse
2560
- } = await (0, import_provider_utils9.postJsonToApi)({
2919
+ } = await (0, import_provider_utils11.postJsonToApi)({
2561
2920
  url: this.config.url({
2562
2921
  path: "/audio/speech",
2563
2922
  modelId: this.modelId
2564
2923
  }),
2565
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2924
+ headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
2566
2925
  body: requestBody,
2567
2926
  failedResponseHandler: openaiFailedResponseHandler,
2568
- successfulResponseHandler: (0, import_provider_utils9.createBinaryResponseHandler)(),
2927
+ successfulResponseHandler: (0, import_provider_utils11.createBinaryResponseHandler)(),
2569
2928
  abortSignal: options.abortSignal,
2570
2929
  fetch: this.config.fetch
2571
2930
  });
@@ -2588,10 +2947,10 @@ var OpenAISpeechModel = class {
2588
2947
  // src/openai-provider.ts
2589
2948
  function createOpenAI(options = {}) {
2590
2949
  var _a, _b;
2591
- const baseURL = (_a = (0, import_provider_utils10.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
2950
+ const baseURL = (_a = (0, import_provider_utils12.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
2592
2951
  const providerName = (_b = options.name) != null ? _b : "openai";
2593
2952
  const getHeaders = () => ({
2594
- Authorization: `Bearer ${(0, import_provider_utils10.loadApiKey)({
2953
+ Authorization: `Bearer ${(0, import_provider_utils12.loadApiKey)({
2595
2954
  apiKey: options.apiKey,
2596
2955
  environmentVariableName: "OPENAI_API_KEY",
2597
2956
  description: "OpenAI"
@@ -2642,10 +3001,7 @@ function createOpenAI(options = {}) {
2642
3001
  "The OpenAI model function cannot be called with the new keyword."
2643
3002
  );
2644
3003
  }
2645
- if (modelId === "gpt-3.5-turbo-instruct") {
2646
- return createCompletionModel(modelId);
2647
- }
2648
- return createChatModel(modelId);
3004
+ return createResponsesModel(modelId);
2649
3005
  };
2650
3006
  const createResponsesModel = (modelId) => {
2651
3007
  return new OpenAIResponsesLanguageModel(modelId, {