@ai-sdk/openai 2.0.0-canary.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -14,10 +14,10 @@ import {
14
14
  createJsonResponseHandler,
15
15
  generateId,
16
16
  isParsableJson,
17
- postJsonToApi,
18
- parseProviderOptions
17
+ parseProviderOptions,
18
+ postJsonToApi
19
19
  } from "@ai-sdk/provider-utils";
20
- import { z as z3 } from "zod";
20
+ import { z as z5 } from "zod/v4";
21
21
 
22
22
  // src/convert-to-openai-chat-messages.ts
23
23
  import {
@@ -124,7 +124,7 @@ function convertToOpenAIChatMessages({
124
124
  type: "file",
125
125
  file: {
126
126
  filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
127
- file_data: `data:application/pdf;base64,${part.data}`
127
+ file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
128
128
  }
129
129
  };
130
130
  } else {
@@ -153,7 +153,7 @@ function convertToOpenAIChatMessages({
153
153
  type: "function",
154
154
  function: {
155
155
  name: part.toolName,
156
- arguments: JSON.stringify(part.args)
156
+ arguments: JSON.stringify(part.input)
157
157
  }
158
158
  });
159
159
  break;
@@ -169,10 +169,23 @@ function convertToOpenAIChatMessages({
169
169
  }
170
170
  case "tool": {
171
171
  for (const toolResponse of content) {
172
+ const output = toolResponse.output;
173
+ let contentValue;
174
+ switch (output.type) {
175
+ case "text":
176
+ case "error-text":
177
+ contentValue = output.value;
178
+ break;
179
+ case "content":
180
+ case "json":
181
+ case "error-json":
182
+ contentValue = JSON.stringify(output.value);
183
+ break;
184
+ }
172
185
  messages.push({
173
186
  role: "tool",
174
187
  tool_call_id: toolResponse.toolCallId,
175
- content: JSON.stringify(toolResponse.result)
188
+ content: contentValue
176
189
  });
177
190
  }
178
191
  break;
@@ -186,17 +199,17 @@ function convertToOpenAIChatMessages({
186
199
  return { messages, warnings };
187
200
  }
188
201
 
189
- // src/map-openai-chat-logprobs.ts
190
- function mapOpenAIChatLogProbsOutput(logprobs) {
191
- var _a, _b;
192
- return (_b = (_a = logprobs == null ? void 0 : logprobs.content) == null ? void 0 : _a.map(({ token, logprob, top_logprobs }) => ({
193
- token,
194
- logprob,
195
- topLogprobs: top_logprobs ? top_logprobs.map(({ token: token2, logprob: logprob2 }) => ({
196
- token: token2,
197
- logprob: logprob2
198
- })) : []
199
- }))) != null ? _b : void 0;
202
+ // src/get-response-metadata.ts
203
+ function getResponseMetadata({
204
+ id,
205
+ model,
206
+ created
207
+ }) {
208
+ return {
209
+ id: id != null ? id : void 0,
210
+ modelId: model != null ? model : void 0,
211
+ timestamp: created != null ? new Date(created * 1e3) : void 0
212
+ };
200
213
  }
201
214
 
202
215
  // src/map-openai-finish-reason.ts
@@ -217,7 +230,7 @@ function mapOpenAIFinishReason(finishReason) {
217
230
  }
218
231
 
219
232
  // src/openai-chat-options.ts
220
- import { z } from "zod";
233
+ import { z } from "zod/v4";
221
234
  var openaiProviderOptions = z.object({
222
235
  /**
223
236
  * Modify the likelihood of specified tokens appearing in the completion.
@@ -260,15 +273,36 @@ var openaiProviderOptions = z.object({
260
273
  /**
261
274
  * Metadata to associate with the request.
262
275
  */
263
- metadata: z.record(z.string()).optional(),
276
+ metadata: z.record(z.string().max(64), z.string().max(512)).optional(),
264
277
  /**
265
278
  * Parameters for prediction mode.
266
279
  */
267
- prediction: z.record(z.any()).optional()
280
+ prediction: z.record(z.string(), z.any()).optional(),
281
+ /**
282
+ * Whether to use structured outputs.
283
+ *
284
+ * @default true
285
+ */
286
+ structuredOutputs: z.boolean().optional(),
287
+ /**
288
+ * Service tier for the request.
289
+ * - 'auto': Default service tier
290
+ * - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
291
+ * - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
292
+ *
293
+ * @default 'auto'
294
+ */
295
+ serviceTier: z.enum(["auto", "flex", "priority"]).optional(),
296
+ /**
297
+ * Whether to use strict JSON schema validation.
298
+ *
299
+ * @default false
300
+ */
301
+ strictJsonSchema: z.boolean().optional()
268
302
  });
269
303
 
270
304
  // src/openai-error.ts
271
- import { z as z2 } from "zod";
305
+ import { z as z2 } from "zod/v4";
272
306
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
273
307
  var openaiErrorDataSchema = z2.object({
274
308
  error: z2.object({
@@ -286,27 +320,103 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
286
320
  errorToMessage: (data) => data.error.message
287
321
  });
288
322
 
289
- // src/get-response-metadata.ts
290
- function getResponseMetadata({
291
- id,
292
- model,
293
- created
294
- }) {
295
- return {
296
- id: id != null ? id : void 0,
297
- modelId: model != null ? model : void 0,
298
- timestamp: created != null ? new Date(created * 1e3) : void 0
299
- };
300
- }
301
-
302
323
  // src/openai-prepare-tools.ts
303
324
  import {
304
325
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
305
326
  } from "@ai-sdk/provider";
327
+
328
+ // src/tool/file-search.ts
329
+ import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
330
+ import { z as z3 } from "zod/v4";
331
+ var comparisonFilterSchema = z3.object({
332
+ key: z3.string(),
333
+ type: z3.enum(["eq", "ne", "gt", "gte", "lt", "lte"]),
334
+ value: z3.union([z3.string(), z3.number(), z3.boolean()])
335
+ });
336
+ var compoundFilterSchema = z3.object({
337
+ type: z3.enum(["and", "or"]),
338
+ filters: z3.array(
339
+ z3.union([comparisonFilterSchema, z3.lazy(() => compoundFilterSchema)])
340
+ )
341
+ });
342
+ var filtersSchema = z3.union([comparisonFilterSchema, compoundFilterSchema]);
343
+ var fileSearchArgsSchema = z3.object({
344
+ /**
345
+ * List of vector store IDs to search through. If not provided, searches all available vector stores.
346
+ */
347
+ vectorStoreIds: z3.array(z3.string()).optional(),
348
+ /**
349
+ * Maximum number of search results to return. Defaults to 10.
350
+ */
351
+ maxNumResults: z3.number().optional(),
352
+ /**
353
+ * Ranking options for the search.
354
+ */
355
+ ranking: z3.object({
356
+ ranker: z3.enum(["auto", "default-2024-08-21"]).optional()
357
+ }).optional(),
358
+ /**
359
+ * A filter to apply based on file attributes.
360
+ */
361
+ filters: filtersSchema.optional()
362
+ });
363
+ var fileSearch = createProviderDefinedToolFactory({
364
+ id: "openai.file_search",
365
+ name: "file_search",
366
+ inputSchema: z3.object({
367
+ query: z3.string()
368
+ })
369
+ });
370
+
371
+ // src/tool/web-search-preview.ts
372
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
373
+ import { z as z4 } from "zod/v4";
374
+ var webSearchPreviewArgsSchema = z4.object({
375
+ /**
376
+ * Search context size to use for the web search.
377
+ * - high: Most comprehensive context, highest cost, slower response
378
+ * - medium: Balanced context, cost, and latency (default)
379
+ * - low: Least context, lowest cost, fastest response
380
+ */
381
+ searchContextSize: z4.enum(["low", "medium", "high"]).optional(),
382
+ /**
383
+ * User location information to provide geographically relevant search results.
384
+ */
385
+ userLocation: z4.object({
386
+ /**
387
+ * Type of location (always 'approximate')
388
+ */
389
+ type: z4.literal("approximate"),
390
+ /**
391
+ * Two-letter ISO country code (e.g., 'US', 'GB')
392
+ */
393
+ country: z4.string().optional(),
394
+ /**
395
+ * City name (free text, e.g., 'Minneapolis')
396
+ */
397
+ city: z4.string().optional(),
398
+ /**
399
+ * Region name (free text, e.g., 'Minnesota')
400
+ */
401
+ region: z4.string().optional(),
402
+ /**
403
+ * IANA timezone (e.g., 'America/Chicago')
404
+ */
405
+ timezone: z4.string().optional()
406
+ }).optional()
407
+ });
408
+ var webSearchPreview = createProviderDefinedToolFactory2({
409
+ id: "openai.web_search_preview",
410
+ name: "web_search_preview",
411
+ inputSchema: z4.object({})
412
+ });
413
+
414
+ // src/openai-prepare-tools.ts
306
415
  function prepareTools({
307
416
  tools,
308
417
  toolChoice,
309
- structuredOutputs
418
+ structuredOutputs,
419
+ strictJsonSchema
310
420
  }) {
311
421
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
312
422
  const toolWarnings = [];
@@ -315,18 +425,48 @@ function prepareTools({
315
425
  }
316
426
  const openaiTools2 = [];
317
427
  for (const tool of tools) {
318
- if (tool.type === "provider-defined") {
319
- toolWarnings.push({ type: "unsupported-tool", tool });
320
- } else {
321
- openaiTools2.push({
322
- type: "function",
323
- function: {
324
- name: tool.name,
325
- description: tool.description,
326
- parameters: tool.parameters,
327
- strict: structuredOutputs ? true : void 0
428
+ switch (tool.type) {
429
+ case "function":
430
+ openaiTools2.push({
431
+ type: "function",
432
+ function: {
433
+ name: tool.name,
434
+ description: tool.description,
435
+ parameters: tool.inputSchema,
436
+ strict: structuredOutputs ? strictJsonSchema : void 0
437
+ }
438
+ });
439
+ break;
440
+ case "provider-defined":
441
+ switch (tool.id) {
442
+ case "openai.file_search": {
443
+ const args = fileSearchArgsSchema.parse(tool.args);
444
+ openaiTools2.push({
445
+ type: "file_search",
446
+ vector_store_ids: args.vectorStoreIds,
447
+ max_num_results: args.maxNumResults,
448
+ ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
449
+ filters: args.filters
450
+ });
451
+ break;
452
+ }
453
+ case "openai.web_search_preview": {
454
+ const args = webSearchPreviewArgsSchema.parse(tool.args);
455
+ openaiTools2.push({
456
+ type: "web_search_preview",
457
+ search_context_size: args.searchContextSize,
458
+ user_location: args.userLocation
459
+ });
460
+ break;
461
+ }
462
+ default:
463
+ toolWarnings.push({ type: "unsupported-tool", tool });
464
+ break;
328
465
  }
329
- });
466
+ break;
467
+ default:
468
+ toolWarnings.push({ type: "unsupported-tool", tool });
469
+ break;
330
470
  }
331
471
  }
332
472
  if (toolChoice == null) {
@@ -360,29 +500,18 @@ function prepareTools({
360
500
 
361
501
  // src/openai-chat-language-model.ts
362
502
  var OpenAIChatLanguageModel = class {
363
- constructor(modelId, settings, config) {
503
+ constructor(modelId, config) {
364
504
  this.specificationVersion = "v2";
505
+ this.supportedUrls = {
506
+ "image/*": [/^https?:\/\/.*$/]
507
+ };
365
508
  this.modelId = modelId;
366
- this.settings = settings;
367
509
  this.config = config;
368
510
  }
369
- get supportsStructuredOutputs() {
370
- var _a;
371
- return (_a = this.settings.structuredOutputs) != null ? _a : isReasoningModel(this.modelId);
372
- }
373
- get defaultObjectGenerationMode() {
374
- if (isAudioModel(this.modelId)) {
375
- return "tool";
376
- }
377
- return this.supportsStructuredOutputs ? "json" : "tool";
378
- }
379
511
  get provider() {
380
512
  return this.config.provider;
381
513
  }
382
- get supportsImageUrls() {
383
- return !this.settings.downloadImages;
384
- }
385
- getArgs({
514
+ async getArgs({
386
515
  prompt,
387
516
  maxOutputTokens,
388
517
  temperature,
@@ -397,20 +526,21 @@ var OpenAIChatLanguageModel = class {
397
526
  toolChoice,
398
527
  providerOptions
399
528
  }) {
400
- var _a, _b;
529
+ var _a, _b, _c, _d;
401
530
  const warnings = [];
402
- const openaiOptions = (_a = parseProviderOptions({
531
+ const openaiOptions = (_a = await parseProviderOptions({
403
532
  provider: "openai",
404
533
  providerOptions,
405
534
  schema: openaiProviderOptions
406
535
  })) != null ? _a : {};
536
+ const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
407
537
  if (topK != null) {
408
538
  warnings.push({
409
539
  type: "unsupported-setting",
410
540
  setting: "topK"
411
541
  });
412
542
  }
413
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
543
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
414
544
  warnings.push({
415
545
  type: "unsupported-setting",
416
546
  setting: "responseFormat",
@@ -424,6 +554,7 @@ var OpenAIChatLanguageModel = class {
424
554
  }
425
555
  );
426
556
  warnings.push(...messageWarnings);
557
+ const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
427
558
  const baseArgs = {
428
559
  // model id:
429
560
  model: this.modelId,
@@ -439,13 +570,12 @@ var OpenAIChatLanguageModel = class {
439
570
  top_p: topP,
440
571
  frequency_penalty: frequencyPenalty,
441
572
  presence_penalty: presencePenalty,
442
- // TODO improve below:
443
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
573
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
444
574
  type: "json_schema",
445
575
  json_schema: {
446
576
  schema: responseFormat.schema,
447
- strict: true,
448
- name: (_b = responseFormat.name) != null ? _b : "response",
577
+ strict: strictJsonSchema,
578
+ name: (_d = responseFormat.name) != null ? _d : "response",
449
579
  description: responseFormat.description
450
580
  }
451
581
  } : { type: "json_object" } : void 0,
@@ -458,6 +588,7 @@ var OpenAIChatLanguageModel = class {
458
588
  metadata: openaiOptions.metadata,
459
589
  prediction: openaiOptions.prediction,
460
590
  reasoning_effort: openaiOptions.reasoningEffort,
591
+ service_tier: openaiOptions.serviceTier,
461
592
  // messages:
462
593
  messages
463
594
  };
@@ -531,6 +662,22 @@ var OpenAIChatLanguageModel = class {
531
662
  });
532
663
  }
533
664
  }
665
+ if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
666
+ warnings.push({
667
+ type: "unsupported-setting",
668
+ setting: "serviceTier",
669
+ details: "flex processing is only available for o3 and o4-mini models"
670
+ });
671
+ baseArgs.service_tier = void 0;
672
+ }
673
+ if (openaiOptions.serviceTier === "priority" && !supportsPriorityProcessing(this.modelId)) {
674
+ warnings.push({
675
+ type: "unsupported-setting",
676
+ setting: "serviceTier",
677
+ details: "priority processing is only available for supported models (GPT-4, o3, o4-mini) and requires Enterprise access"
678
+ });
679
+ baseArgs.service_tier = void 0;
680
+ }
534
681
  const {
535
682
  tools: openaiTools2,
536
683
  toolChoice: openaiToolChoice,
@@ -538,7 +685,8 @@ var OpenAIChatLanguageModel = class {
538
685
  } = prepareTools({
539
686
  tools,
540
687
  toolChoice,
541
- structuredOutputs: this.supportsStructuredOutputs
688
+ structuredOutputs,
689
+ strictJsonSchema
542
690
  });
543
691
  return {
544
692
  args: {
@@ -550,8 +698,8 @@ var OpenAIChatLanguageModel = class {
550
698
  };
551
699
  }
552
700
  async doGenerate(options) {
553
- var _a, _b, _c, _d, _e, _f, _g, _h;
554
- const { args: body, warnings } = this.getArgs(options);
701
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
702
+ const { args: body, warnings } = await this.getArgs(options);
555
703
  const {
556
704
  responseHeaders,
557
705
  value: response,
@@ -579,33 +727,32 @@ var OpenAIChatLanguageModel = class {
579
727
  for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
580
728
  content.push({
581
729
  type: "tool-call",
582
- toolCallType: "function",
583
730
  toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
584
731
  toolName: toolCall.function.name,
585
- args: toolCall.function.arguments
732
+ input: toolCall.function.arguments
586
733
  });
587
734
  }
588
735
  const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
589
736
  const promptTokenDetails = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details;
590
737
  const providerMetadata = { openai: {} };
591
- if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
592
- providerMetadata.openai.reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
593
- }
594
738
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
595
739
  providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
596
740
  }
597
741
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
598
742
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
599
743
  }
600
- if ((promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null) {
601
- providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
744
+ if (((_e = choice.logprobs) == null ? void 0 : _e.content) != null) {
745
+ providerMetadata.openai.logprobs = choice.logprobs.content;
602
746
  }
603
747
  return {
604
748
  content,
605
749
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
606
750
  usage: {
607
- inputTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : void 0,
608
- outputTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0
751
+ inputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : void 0,
752
+ outputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : void 0,
753
+ totalTokens: (_k = (_j = response.usage) == null ? void 0 : _j.total_tokens) != null ? _k : void 0,
754
+ reasoningTokens: (_l = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _l : void 0,
755
+ cachedInputTokens: (_m = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _m : void 0
609
756
  },
610
757
  request: { body },
611
758
  response: {
@@ -614,17 +761,17 @@ var OpenAIChatLanguageModel = class {
614
761
  body: rawResponse
615
762
  },
616
763
  warnings,
617
- logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
618
764
  providerMetadata
619
765
  };
620
766
  }
621
767
  async doStream(options) {
622
- const { args, warnings } = this.getArgs(options);
768
+ const { args, warnings } = await this.getArgs(options);
623
769
  const body = {
624
770
  ...args,
625
771
  stream: true,
626
- // only include stream_options when in strict compatibility mode:
627
- stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
772
+ stream_options: {
773
+ include_usage: true
774
+ }
628
775
  };
629
776
  const { responseHeaders, value: response } = await postJsonToApi({
630
777
  url: this.config.url({
@@ -640,15 +787,15 @@ var OpenAIChatLanguageModel = class {
640
787
  abortSignal: options.abortSignal,
641
788
  fetch: this.config.fetch
642
789
  });
643
- const { messages: rawPrompt, ...rawSettings } = args;
644
790
  const toolCalls = [];
645
791
  let finishReason = "unknown";
646
792
  const usage = {
647
793
  inputTokens: void 0,
648
- outputTokens: void 0
794
+ outputTokens: void 0,
795
+ totalTokens: void 0
649
796
  };
650
- let logprobs;
651
797
  let isFirstChunk = true;
798
+ let isActiveText = false;
652
799
  const providerMetadata = { openai: {} };
653
800
  return {
654
801
  stream: response.pipeThrough(
@@ -657,7 +804,10 @@ var OpenAIChatLanguageModel = class {
657
804
  controller.enqueue({ type: "stream-start", warnings });
658
805
  },
659
806
  transform(chunk, controller) {
660
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
807
+ 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;
808
+ if (options.includeRawChunks) {
809
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
810
+ }
661
811
  if (!chunk.success) {
662
812
  finishReason = "error";
663
813
  controller.enqueue({ type: "error", error: chunk.error });
@@ -677,48 +827,40 @@ var OpenAIChatLanguageModel = class {
677
827
  });
678
828
  }
679
829
  if (value.usage != null) {
680
- const {
681
- prompt_tokens,
682
- completion_tokens,
683
- prompt_tokens_details,
684
- completion_tokens_details
685
- } = value.usage;
686
- usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
687
- usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
688
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
689
- providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
690
- }
691
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens) != null) {
692
- providerMetadata.openai.acceptedPredictionTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens;
830
+ usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
831
+ usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
832
+ usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
833
+ usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
834
+ usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
835
+ if (((_h = value.usage.completion_tokens_details) == null ? void 0 : _h.accepted_prediction_tokens) != null) {
836
+ providerMetadata.openai.acceptedPredictionTokens = (_i = value.usage.completion_tokens_details) == null ? void 0 : _i.accepted_prediction_tokens;
693
837
  }
694
- if ((completion_tokens_details == null ? void 0 : completion_tokens_details.rejected_prediction_tokens) != null) {
695
- providerMetadata.openai.rejectedPredictionTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.rejected_prediction_tokens;
696
- }
697
- if ((prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens) != null) {
698
- providerMetadata.openai.cachedPromptTokens = prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens;
838
+ if (((_j = value.usage.completion_tokens_details) == null ? void 0 : _j.rejected_prediction_tokens) != null) {
839
+ providerMetadata.openai.rejectedPredictionTokens = (_k = value.usage.completion_tokens_details) == null ? void 0 : _k.rejected_prediction_tokens;
699
840
  }
700
841
  }
701
842
  const choice = value.choices[0];
702
843
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
703
844
  finishReason = mapOpenAIFinishReason(choice.finish_reason);
704
845
  }
846
+ if (((_l = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _l.content) != null) {
847
+ providerMetadata.openai.logprobs = choice.logprobs.content;
848
+ }
705
849
  if ((choice == null ? void 0 : choice.delta) == null) {
706
850
  return;
707
851
  }
708
852
  const delta = choice.delta;
709
853
  if (delta.content != null) {
854
+ if (!isActiveText) {
855
+ controller.enqueue({ type: "text-start", id: "0" });
856
+ isActiveText = true;
857
+ }
710
858
  controller.enqueue({
711
- type: "text",
712
- text: delta.content
859
+ type: "text-delta",
860
+ id: "0",
861
+ delta: delta.content
713
862
  });
714
863
  }
715
- const mappedLogprobs = mapOpenAIChatLogProbsOutput(
716
- choice == null ? void 0 : choice.logprobs
717
- );
718
- if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
719
- if (logprobs === void 0) logprobs = [];
720
- logprobs.push(...mappedLogprobs);
721
- }
722
864
  if (delta.tool_calls != null) {
723
865
  for (const toolCallDelta of delta.tool_calls) {
724
866
  const index = toolCallDelta.index;
@@ -735,39 +877,45 @@ var OpenAIChatLanguageModel = class {
735
877
  message: `Expected 'id' to be a string.`
736
878
  });
737
879
  }
738
- if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
880
+ if (((_m = toolCallDelta.function) == null ? void 0 : _m.name) == null) {
739
881
  throw new InvalidResponseDataError({
740
882
  data: toolCallDelta,
741
883
  message: `Expected 'function.name' to be a string.`
742
884
  });
743
885
  }
886
+ controller.enqueue({
887
+ type: "tool-input-start",
888
+ id: toolCallDelta.id,
889
+ toolName: toolCallDelta.function.name
890
+ });
744
891
  toolCalls[index] = {
745
892
  id: toolCallDelta.id,
746
893
  type: "function",
747
894
  function: {
748
895
  name: toolCallDelta.function.name,
749
- arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
896
+ arguments: (_n = toolCallDelta.function.arguments) != null ? _n : ""
750
897
  },
751
898
  hasFinished: false
752
899
  };
753
900
  const toolCall2 = toolCalls[index];
754
- if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
901
+ if (((_o = toolCall2.function) == null ? void 0 : _o.name) != null && ((_p = toolCall2.function) == null ? void 0 : _p.arguments) != null) {
755
902
  if (toolCall2.function.arguments.length > 0) {
756
903
  controller.enqueue({
757
- type: "tool-call-delta",
758
- toolCallType: "function",
759
- toolCallId: toolCall2.id,
760
- toolName: toolCall2.function.name,
761
- argsTextDelta: toolCall2.function.arguments
904
+ type: "tool-input-delta",
905
+ id: toolCall2.id,
906
+ delta: toolCall2.function.arguments
762
907
  });
763
908
  }
764
909
  if (isParsableJson(toolCall2.function.arguments)) {
910
+ controller.enqueue({
911
+ type: "tool-input-end",
912
+ id: toolCall2.id
913
+ });
765
914
  controller.enqueue({
766
915
  type: "tool-call",
767
- toolCallType: "function",
768
- toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
916
+ toolCallId: (_q = toolCall2.id) != null ? _q : generateId(),
769
917
  toolName: toolCall2.function.name,
770
- args: toolCall2.function.arguments
918
+ input: toolCall2.function.arguments
771
919
  });
772
920
  toolCall2.hasFinished = true;
773
921
  }
@@ -778,23 +926,24 @@ var OpenAIChatLanguageModel = class {
778
926
  if (toolCall.hasFinished) {
779
927
  continue;
780
928
  }
781
- if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
782
- toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
929
+ if (((_r = toolCallDelta.function) == null ? void 0 : _r.arguments) != null) {
930
+ toolCall.function.arguments += (_t = (_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null ? _t : "";
783
931
  }
784
932
  controller.enqueue({
785
- type: "tool-call-delta",
786
- toolCallType: "function",
787
- toolCallId: toolCall.id,
788
- toolName: toolCall.function.name,
789
- argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
933
+ type: "tool-input-delta",
934
+ id: toolCall.id,
935
+ delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
790
936
  });
791
- if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
937
+ if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && isParsableJson(toolCall.function.arguments)) {
938
+ controller.enqueue({
939
+ type: "tool-input-end",
940
+ id: toolCall.id
941
+ });
792
942
  controller.enqueue({
793
943
  type: "tool-call",
794
- toolCallType: "function",
795
- toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
944
+ toolCallId: (_x = toolCall.id) != null ? _x : generateId(),
796
945
  toolName: toolCall.function.name,
797
- args: toolCall.function.arguments
946
+ input: toolCall.function.arguments
798
947
  });
799
948
  toolCall.hasFinished = true;
800
949
  }
@@ -802,10 +951,12 @@ var OpenAIChatLanguageModel = class {
802
951
  }
803
952
  },
804
953
  flush(controller) {
954
+ if (isActiveText) {
955
+ controller.enqueue({ type: "text-end", id: "0" });
956
+ }
805
957
  controller.enqueue({
806
958
  type: "finish",
807
959
  finishReason,
808
- logprobs,
809
960
  usage,
810
961
  ...providerMetadata != null ? { providerMetadata } : {}
811
962
  });
@@ -817,96 +968,97 @@ var OpenAIChatLanguageModel = class {
817
968
  };
818
969
  }
819
970
  };
820
- var openaiTokenUsageSchema = z3.object({
821
- prompt_tokens: z3.number().nullish(),
822
- completion_tokens: z3.number().nullish(),
823
- prompt_tokens_details: z3.object({
824
- cached_tokens: z3.number().nullish()
971
+ var openaiTokenUsageSchema = z5.object({
972
+ prompt_tokens: z5.number().nullish(),
973
+ completion_tokens: z5.number().nullish(),
974
+ total_tokens: z5.number().nullish(),
975
+ prompt_tokens_details: z5.object({
976
+ cached_tokens: z5.number().nullish()
825
977
  }).nullish(),
826
- completion_tokens_details: z3.object({
827
- reasoning_tokens: z3.number().nullish(),
828
- accepted_prediction_tokens: z3.number().nullish(),
829
- rejected_prediction_tokens: z3.number().nullish()
978
+ completion_tokens_details: z5.object({
979
+ reasoning_tokens: z5.number().nullish(),
980
+ accepted_prediction_tokens: z5.number().nullish(),
981
+ rejected_prediction_tokens: z5.number().nullish()
830
982
  }).nullish()
831
983
  }).nullish();
832
- var openaiChatResponseSchema = z3.object({
833
- id: z3.string().nullish(),
834
- created: z3.number().nullish(),
835
- model: z3.string().nullish(),
836
- choices: z3.array(
837
- z3.object({
838
- message: z3.object({
839
- role: z3.literal("assistant").nullish(),
840
- content: z3.string().nullish(),
841
- tool_calls: z3.array(
842
- z3.object({
843
- id: z3.string().nullish(),
844
- type: z3.literal("function"),
845
- function: z3.object({
846
- name: z3.string(),
847
- arguments: z3.string()
984
+ var openaiChatResponseSchema = z5.object({
985
+ id: z5.string().nullish(),
986
+ created: z5.number().nullish(),
987
+ model: z5.string().nullish(),
988
+ choices: z5.array(
989
+ z5.object({
990
+ message: z5.object({
991
+ role: z5.literal("assistant").nullish(),
992
+ content: z5.string().nullish(),
993
+ tool_calls: z5.array(
994
+ z5.object({
995
+ id: z5.string().nullish(),
996
+ type: z5.literal("function"),
997
+ function: z5.object({
998
+ name: z5.string(),
999
+ arguments: z5.string()
848
1000
  })
849
1001
  })
850
1002
  ).nullish()
851
1003
  }),
852
- index: z3.number(),
853
- logprobs: z3.object({
854
- content: z3.array(
855
- z3.object({
856
- token: z3.string(),
857
- logprob: z3.number(),
858
- top_logprobs: z3.array(
859
- z3.object({
860
- token: z3.string(),
861
- logprob: z3.number()
1004
+ index: z5.number(),
1005
+ logprobs: z5.object({
1006
+ content: z5.array(
1007
+ z5.object({
1008
+ token: z5.string(),
1009
+ logprob: z5.number(),
1010
+ top_logprobs: z5.array(
1011
+ z5.object({
1012
+ token: z5.string(),
1013
+ logprob: z5.number()
862
1014
  })
863
1015
  )
864
1016
  })
865
- ).nullable()
1017
+ ).nullish()
866
1018
  }).nullish(),
867
- finish_reason: z3.string().nullish()
1019
+ finish_reason: z5.string().nullish()
868
1020
  })
869
1021
  ),
870
1022
  usage: openaiTokenUsageSchema
871
1023
  });
872
- var openaiChatChunkSchema = z3.union([
873
- z3.object({
874
- id: z3.string().nullish(),
875
- created: z3.number().nullish(),
876
- model: z3.string().nullish(),
877
- choices: z3.array(
878
- z3.object({
879
- delta: z3.object({
880
- role: z3.enum(["assistant"]).nullish(),
881
- content: z3.string().nullish(),
882
- tool_calls: z3.array(
883
- z3.object({
884
- index: z3.number(),
885
- id: z3.string().nullish(),
886
- type: z3.literal("function").optional(),
887
- function: z3.object({
888
- name: z3.string().nullish(),
889
- arguments: z3.string().nullish()
1024
+ var openaiChatChunkSchema = z5.union([
1025
+ z5.object({
1026
+ id: z5.string().nullish(),
1027
+ created: z5.number().nullish(),
1028
+ model: z5.string().nullish(),
1029
+ choices: z5.array(
1030
+ z5.object({
1031
+ delta: z5.object({
1032
+ role: z5.enum(["assistant"]).nullish(),
1033
+ content: z5.string().nullish(),
1034
+ tool_calls: z5.array(
1035
+ z5.object({
1036
+ index: z5.number(),
1037
+ id: z5.string().nullish(),
1038
+ type: z5.literal("function").nullish(),
1039
+ function: z5.object({
1040
+ name: z5.string().nullish(),
1041
+ arguments: z5.string().nullish()
890
1042
  })
891
1043
  })
892
1044
  ).nullish()
893
1045
  }).nullish(),
894
- logprobs: z3.object({
895
- content: z3.array(
896
- z3.object({
897
- token: z3.string(),
898
- logprob: z3.number(),
899
- top_logprobs: z3.array(
900
- z3.object({
901
- token: z3.string(),
902
- logprob: z3.number()
1046
+ logprobs: z5.object({
1047
+ content: z5.array(
1048
+ z5.object({
1049
+ token: z5.string(),
1050
+ logprob: z5.number(),
1051
+ top_logprobs: z5.array(
1052
+ z5.object({
1053
+ token: z5.string(),
1054
+ logprob: z5.number()
903
1055
  })
904
1056
  )
905
1057
  })
906
- ).nullable()
1058
+ ).nullish()
907
1059
  }).nullish(),
908
- finish_reason: z3.string().nullable().optional(),
909
- index: z3.number()
1060
+ finish_reason: z5.string().nullish(),
1061
+ index: z5.number()
910
1062
  })
911
1063
  ),
912
1064
  usage: openaiTokenUsageSchema
@@ -916,8 +1068,11 @@ var openaiChatChunkSchema = z3.union([
916
1068
  function isReasoningModel(modelId) {
917
1069
  return modelId.startsWith("o");
918
1070
  }
919
- function isAudioModel(modelId) {
920
- return modelId.startsWith("gpt-4o-audio-preview");
1071
+ function supportsFlexProcessing(modelId) {
1072
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1073
+ }
1074
+ function supportsPriorityProcessing(modelId) {
1075
+ return modelId.startsWith("gpt-4") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
921
1076
  }
922
1077
  function getSystemMessageMode(modelId) {
923
1078
  var _a, _b;
@@ -939,11 +1094,23 @@ var reasoningModels = {
939
1094
  "o1-preview-2024-09-12": {
940
1095
  systemMessageMode: "remove"
941
1096
  },
1097
+ o3: {
1098
+ systemMessageMode: "developer"
1099
+ },
1100
+ "o3-2025-04-16": {
1101
+ systemMessageMode: "developer"
1102
+ },
942
1103
  "o3-mini": {
943
1104
  systemMessageMode: "developer"
944
1105
  },
945
1106
  "o3-mini-2025-01-31": {
946
1107
  systemMessageMode: "developer"
1108
+ },
1109
+ "o4-mini": {
1110
+ systemMessageMode: "developer"
1111
+ },
1112
+ "o4-mini-2025-04-16": {
1113
+ systemMessageMode: "developer"
947
1114
  }
948
1115
  };
949
1116
 
@@ -952,9 +1119,10 @@ import {
952
1119
  combineHeaders as combineHeaders2,
953
1120
  createEventSourceResponseHandler as createEventSourceResponseHandler2,
954
1121
  createJsonResponseHandler as createJsonResponseHandler2,
1122
+ parseProviderOptions as parseProviderOptions2,
955
1123
  postJsonToApi as postJsonToApi2
956
1124
  } from "@ai-sdk/provider-utils";
957
- import { z as z4 } from "zod";
1125
+ import { z as z7 } from "zod/v4";
958
1126
 
959
1127
  // src/convert-to-openai-completion-prompt.ts
960
1128
  import {
@@ -963,13 +1131,9 @@ import {
963
1131
  } from "@ai-sdk/provider";
964
1132
  function convertToOpenAICompletionPrompt({
965
1133
  prompt,
966
- inputFormat,
967
1134
  user = "user",
968
1135
  assistant = "assistant"
969
1136
  }) {
970
- if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
971
- return { prompt: prompt[0].content[0].text };
972
- }
973
1137
  let text = "";
974
1138
  if (prompt[0].role === "system") {
975
1139
  text += `${prompt[0].content}
@@ -1038,34 +1202,66 @@ ${user}:`]
1038
1202
  };
1039
1203
  }
1040
1204
 
1041
- // src/map-openai-completion-logprobs.ts
1042
- function mapOpenAICompletionLogProbs(logprobs) {
1043
- return logprobs == null ? void 0 : logprobs.tokens.map((token, index) => ({
1044
- token,
1045
- logprob: logprobs.token_logprobs[index],
1046
- topLogprobs: logprobs.top_logprobs ? Object.entries(logprobs.top_logprobs[index]).map(
1047
- ([token2, logprob]) => ({
1048
- token: token2,
1049
- logprob
1050
- })
1051
- ) : []
1052
- }));
1053
- }
1205
+ // src/openai-completion-options.ts
1206
+ import { z as z6 } from "zod/v4";
1207
+ var openaiCompletionProviderOptions = z6.object({
1208
+ /**
1209
+ Echo back the prompt in addition to the completion.
1210
+ */
1211
+ echo: z6.boolean().optional(),
1212
+ /**
1213
+ Modify the likelihood of specified tokens appearing in the completion.
1214
+
1215
+ Accepts a JSON object that maps tokens (specified by their token ID in
1216
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
1217
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
1218
+ the bias is added to the logits generated by the model prior to sampling.
1219
+ The exact effect will vary per model, but values between -1 and 1 should
1220
+ decrease or increase likelihood of selection; values like -100 or 100
1221
+ should result in a ban or exclusive selection of the relevant token.
1222
+
1223
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
1224
+ token from being generated.
1225
+ */
1226
+ logitBias: z6.record(z6.string(), z6.number()).optional(),
1227
+ /**
1228
+ The suffix that comes after a completion of inserted text.
1229
+ */
1230
+ suffix: z6.string().optional(),
1231
+ /**
1232
+ A unique identifier representing your end-user, which can help OpenAI to
1233
+ monitor and detect abuse. Learn more.
1234
+ */
1235
+ user: z6.string().optional(),
1236
+ /**
1237
+ Return the log probabilities of the tokens. Including logprobs will increase
1238
+ the response size and can slow down response times. However, it can
1239
+ be useful to better understand how the model is behaving.
1240
+ Setting to true will return the log probabilities of the tokens that
1241
+ were generated.
1242
+ Setting to a number will return the log probabilities of the top n
1243
+ tokens that were generated.
1244
+ */
1245
+ logprobs: z6.union([z6.boolean(), z6.number()]).optional()
1246
+ });
1054
1247
 
1055
1248
  // src/openai-completion-language-model.ts
1056
1249
  var OpenAICompletionLanguageModel = class {
1057
- constructor(modelId, settings, config) {
1250
+ constructor(modelId, config) {
1058
1251
  this.specificationVersion = "v2";
1059
- this.defaultObjectGenerationMode = void 0;
1252
+ this.supportedUrls = {
1253
+ // No URLs are supported for completion models.
1254
+ };
1060
1255
  this.modelId = modelId;
1061
- this.settings = settings;
1062
1256
  this.config = config;
1063
1257
  }
1258
+ get providerOptionsName() {
1259
+ return this.config.provider.split(".")[0].trim();
1260
+ }
1064
1261
  get provider() {
1065
1262
  return this.config.provider;
1066
1263
  }
1067
- getArgs({
1068
- inputFormat,
1264
+ async getArgs({
1069
1265
  prompt,
1070
1266
  maxOutputTokens,
1071
1267
  temperature,
@@ -1077,9 +1273,22 @@ var OpenAICompletionLanguageModel = class {
1077
1273
  responseFormat,
1078
1274
  tools,
1079
1275
  toolChoice,
1080
- seed
1276
+ seed,
1277
+ providerOptions
1081
1278
  }) {
1082
1279
  const warnings = [];
1280
+ const openaiOptions = {
1281
+ ...await parseProviderOptions2({
1282
+ provider: "openai",
1283
+ providerOptions,
1284
+ schema: openaiCompletionProviderOptions
1285
+ }),
1286
+ ...await parseProviderOptions2({
1287
+ provider: this.providerOptionsName,
1288
+ providerOptions,
1289
+ schema: openaiCompletionProviderOptions
1290
+ })
1291
+ };
1083
1292
  if (topK != null) {
1084
1293
  warnings.push({ type: "unsupported-setting", setting: "topK" });
1085
1294
  }
@@ -1096,18 +1305,18 @@ var OpenAICompletionLanguageModel = class {
1096
1305
  details: "JSON response format is not supported."
1097
1306
  });
1098
1307
  }
1099
- const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
1308
+ const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
1100
1309
  const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
1101
1310
  return {
1102
1311
  args: {
1103
1312
  // model id:
1104
1313
  model: this.modelId,
1105
1314
  // model specific settings:
1106
- echo: this.settings.echo,
1107
- logit_bias: this.settings.logitBias,
1108
- logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
1109
- suffix: this.settings.suffix,
1110
- user: this.settings.user,
1315
+ echo: openaiOptions.echo,
1316
+ logit_bias: openaiOptions.logitBias,
1317
+ logprobs: (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? 0 : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === false ? void 0 : openaiOptions == null ? void 0 : openaiOptions.logprobs,
1318
+ suffix: openaiOptions.suffix,
1319
+ user: openaiOptions.user,
1111
1320
  // standardized settings:
1112
1321
  max_tokens: maxOutputTokens,
1113
1322
  temperature,
@@ -1124,7 +1333,8 @@ var OpenAICompletionLanguageModel = class {
1124
1333
  };
1125
1334
  }
1126
1335
  async doGenerate(options) {
1127
- const { args, warnings } = this.getArgs(options);
1336
+ var _a, _b, _c;
1337
+ const { args, warnings } = await this.getArgs(options);
1128
1338
  const {
1129
1339
  responseHeaders,
1130
1340
  value: response,
@@ -1144,30 +1354,36 @@ var OpenAICompletionLanguageModel = class {
1144
1354
  fetch: this.config.fetch
1145
1355
  });
1146
1356
  const choice = response.choices[0];
1357
+ const providerMetadata = { openai: {} };
1358
+ if (choice.logprobs != null) {
1359
+ providerMetadata.openai.logprobs = choice.logprobs;
1360
+ }
1147
1361
  return {
1148
1362
  content: [{ type: "text", text: choice.text }],
1149
1363
  usage: {
1150
- inputTokens: response.usage.prompt_tokens,
1151
- outputTokens: response.usage.completion_tokens
1364
+ inputTokens: (_a = response.usage) == null ? void 0 : _a.prompt_tokens,
1365
+ outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
1366
+ totalTokens: (_c = response.usage) == null ? void 0 : _c.total_tokens
1152
1367
  },
1153
1368
  finishReason: mapOpenAIFinishReason(choice.finish_reason),
1154
- logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
1155
1369
  request: { body: args },
1156
1370
  response: {
1157
1371
  ...getResponseMetadata(response),
1158
1372
  headers: responseHeaders,
1159
1373
  body: rawResponse
1160
1374
  },
1375
+ providerMetadata,
1161
1376
  warnings
1162
1377
  };
1163
1378
  }
1164
1379
  async doStream(options) {
1165
- const { args, warnings } = this.getArgs(options);
1380
+ const { args, warnings } = await this.getArgs(options);
1166
1381
  const body = {
1167
1382
  ...args,
1168
1383
  stream: true,
1169
- // only include stream_options when in strict compatibility mode:
1170
- stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
1384
+ stream_options: {
1385
+ include_usage: true
1386
+ }
1171
1387
  };
1172
1388
  const { responseHeaders, value: response } = await postJsonToApi2({
1173
1389
  url: this.config.url({
@@ -1184,11 +1400,12 @@ var OpenAICompletionLanguageModel = class {
1184
1400
  fetch: this.config.fetch
1185
1401
  });
1186
1402
  let finishReason = "unknown";
1403
+ const providerMetadata = { openai: {} };
1187
1404
  const usage = {
1188
1405
  inputTokens: void 0,
1189
- outputTokens: void 0
1406
+ outputTokens: void 0,
1407
+ totalTokens: void 0
1190
1408
  };
1191
- let logprobs;
1192
1409
  let isFirstChunk = true;
1193
1410
  return {
1194
1411
  stream: response.pipeThrough(
@@ -1197,6 +1414,9 @@ var OpenAICompletionLanguageModel = class {
1197
1414
  controller.enqueue({ type: "stream-start", warnings });
1198
1415
  },
1199
1416
  transform(chunk, controller) {
1417
+ if (options.includeRawChunks) {
1418
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1419
+ }
1200
1420
  if (!chunk.success) {
1201
1421
  finishReason = "error";
1202
1422
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1214,34 +1434,36 @@ var OpenAICompletionLanguageModel = class {
1214
1434
  type: "response-metadata",
1215
1435
  ...getResponseMetadata(value)
1216
1436
  });
1437
+ controller.enqueue({ type: "text-start", id: "0" });
1217
1438
  }
1218
1439
  if (value.usage != null) {
1219
1440
  usage.inputTokens = value.usage.prompt_tokens;
1220
1441
  usage.outputTokens = value.usage.completion_tokens;
1442
+ usage.totalTokens = value.usage.total_tokens;
1221
1443
  }
1222
1444
  const choice = value.choices[0];
1223
1445
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1224
1446
  finishReason = mapOpenAIFinishReason(choice.finish_reason);
1225
1447
  }
1226
- if ((choice == null ? void 0 : choice.text) != null) {
1448
+ if ((choice == null ? void 0 : choice.logprobs) != null) {
1449
+ providerMetadata.openai.logprobs = choice.logprobs;
1450
+ }
1451
+ if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
1227
1452
  controller.enqueue({
1228
- type: "text",
1229
- text: choice.text
1453
+ type: "text-delta",
1454
+ id: "0",
1455
+ delta: choice.text
1230
1456
  });
1231
1457
  }
1232
- const mappedLogprobs = mapOpenAICompletionLogProbs(
1233
- choice == null ? void 0 : choice.logprobs
1234
- );
1235
- if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
1236
- if (logprobs === void 0) logprobs = [];
1237
- logprobs.push(...mappedLogprobs);
1238
- }
1239
1458
  },
1240
1459
  flush(controller) {
1460
+ if (!isFirstChunk) {
1461
+ controller.enqueue({ type: "text-end", id: "0" });
1462
+ }
1241
1463
  controller.enqueue({
1242
1464
  type: "finish",
1243
1465
  finishReason,
1244
- logprobs,
1466
+ providerMetadata,
1245
1467
  usage
1246
1468
  });
1247
1469
  }
@@ -1252,47 +1474,46 @@ var OpenAICompletionLanguageModel = class {
1252
1474
  };
1253
1475
  }
1254
1476
  };
1255
- var openaiCompletionResponseSchema = z4.object({
1256
- id: z4.string().nullish(),
1257
- created: z4.number().nullish(),
1258
- model: z4.string().nullish(),
1259
- choices: z4.array(
1260
- z4.object({
1261
- text: z4.string(),
1262
- finish_reason: z4.string(),
1263
- logprobs: z4.object({
1264
- tokens: z4.array(z4.string()),
1265
- token_logprobs: z4.array(z4.number()),
1266
- top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
1477
+ var usageSchema = z7.object({
1478
+ prompt_tokens: z7.number(),
1479
+ completion_tokens: z7.number(),
1480
+ total_tokens: z7.number()
1481
+ });
1482
+ var openaiCompletionResponseSchema = z7.object({
1483
+ id: z7.string().nullish(),
1484
+ created: z7.number().nullish(),
1485
+ model: z7.string().nullish(),
1486
+ choices: z7.array(
1487
+ z7.object({
1488
+ text: z7.string(),
1489
+ finish_reason: z7.string(),
1490
+ logprobs: z7.object({
1491
+ tokens: z7.array(z7.string()),
1492
+ token_logprobs: z7.array(z7.number()),
1493
+ top_logprobs: z7.array(z7.record(z7.string(), z7.number())).nullish()
1267
1494
  }).nullish()
1268
1495
  })
1269
1496
  ),
1270
- usage: z4.object({
1271
- prompt_tokens: z4.number(),
1272
- completion_tokens: z4.number()
1273
- })
1497
+ usage: usageSchema.nullish()
1274
1498
  });
1275
- var openaiCompletionChunkSchema = z4.union([
1276
- z4.object({
1277
- id: z4.string().nullish(),
1278
- created: z4.number().nullish(),
1279
- model: z4.string().nullish(),
1280
- choices: z4.array(
1281
- z4.object({
1282
- text: z4.string(),
1283
- finish_reason: z4.string().nullish(),
1284
- index: z4.number(),
1285
- logprobs: z4.object({
1286
- tokens: z4.array(z4.string()),
1287
- token_logprobs: z4.array(z4.number()),
1288
- top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
1499
+ var openaiCompletionChunkSchema = z7.union([
1500
+ z7.object({
1501
+ id: z7.string().nullish(),
1502
+ created: z7.number().nullish(),
1503
+ model: z7.string().nullish(),
1504
+ choices: z7.array(
1505
+ z7.object({
1506
+ text: z7.string(),
1507
+ finish_reason: z7.string().nullish(),
1508
+ index: z7.number(),
1509
+ logprobs: z7.object({
1510
+ tokens: z7.array(z7.string()),
1511
+ token_logprobs: z7.array(z7.number()),
1512
+ top_logprobs: z7.array(z7.record(z7.string(), z7.number())).nullish()
1289
1513
  }).nullish()
1290
1514
  })
1291
1515
  ),
1292
- usage: z4.object({
1293
- prompt_tokens: z4.number(),
1294
- completion_tokens: z4.number()
1295
- }).nullish()
1516
+ usage: usageSchema.nullish()
1296
1517
  }),
1297
1518
  openaiErrorDataSchema
1298
1519
  ]);
@@ -1304,32 +1525,45 @@ import {
1304
1525
  import {
1305
1526
  combineHeaders as combineHeaders3,
1306
1527
  createJsonResponseHandler as createJsonResponseHandler3,
1528
+ parseProviderOptions as parseProviderOptions3,
1307
1529
  postJsonToApi as postJsonToApi3
1308
1530
  } from "@ai-sdk/provider-utils";
1309
- import { z as z5 } from "zod";
1531
+ import { z as z9 } from "zod/v4";
1532
+
1533
+ // src/openai-embedding-options.ts
1534
+ import { z as z8 } from "zod/v4";
1535
+ var openaiEmbeddingProviderOptions = z8.object({
1536
+ /**
1537
+ The number of dimensions the resulting output embeddings should have.
1538
+ Only supported in text-embedding-3 and later models.
1539
+ */
1540
+ dimensions: z8.number().optional(),
1541
+ /**
1542
+ A unique identifier representing your end-user, which can help OpenAI to
1543
+ monitor and detect abuse. Learn more.
1544
+ */
1545
+ user: z8.string().optional()
1546
+ });
1547
+
1548
+ // src/openai-embedding-model.ts
1310
1549
  var OpenAIEmbeddingModel = class {
1311
- constructor(modelId, settings, config) {
1550
+ constructor(modelId, config) {
1312
1551
  this.specificationVersion = "v2";
1552
+ this.maxEmbeddingsPerCall = 2048;
1553
+ this.supportsParallelCalls = true;
1313
1554
  this.modelId = modelId;
1314
- this.settings = settings;
1315
1555
  this.config = config;
1316
1556
  }
1317
1557
  get provider() {
1318
1558
  return this.config.provider;
1319
1559
  }
1320
- get maxEmbeddingsPerCall() {
1321
- var _a;
1322
- return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
1323
- }
1324
- get supportsParallelCalls() {
1325
- var _a;
1326
- return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
1327
- }
1328
1560
  async doEmbed({
1329
1561
  values,
1330
1562
  headers,
1331
- abortSignal
1563
+ abortSignal,
1564
+ providerOptions
1332
1565
  }) {
1566
+ var _a;
1333
1567
  if (values.length > this.maxEmbeddingsPerCall) {
1334
1568
  throw new TooManyEmbeddingValuesForCallError({
1335
1569
  provider: this.provider,
@@ -1338,6 +1572,11 @@ var OpenAIEmbeddingModel = class {
1338
1572
  values
1339
1573
  });
1340
1574
  }
1575
+ const openaiOptions = (_a = await parseProviderOptions3({
1576
+ provider: "openai",
1577
+ providerOptions,
1578
+ schema: openaiEmbeddingProviderOptions
1579
+ })) != null ? _a : {};
1341
1580
  const {
1342
1581
  responseHeaders,
1343
1582
  value: response,
@@ -1352,8 +1591,8 @@ var OpenAIEmbeddingModel = class {
1352
1591
  model: this.modelId,
1353
1592
  input: values,
1354
1593
  encoding_format: "float",
1355
- dimensions: this.settings.dimensions,
1356
- user: this.settings.user
1594
+ dimensions: openaiOptions.dimensions,
1595
+ user: openaiOptions.user
1357
1596
  },
1358
1597
  failedResponseHandler: openaiFailedResponseHandler,
1359
1598
  successfulResponseHandler: createJsonResponseHandler3(
@@ -1369,9 +1608,9 @@ var OpenAIEmbeddingModel = class {
1369
1608
  };
1370
1609
  }
1371
1610
  };
1372
- var openaiTextEmbeddingResponseSchema = z5.object({
1373
- data: z5.array(z5.object({ embedding: z5.array(z5.number()) })),
1374
- usage: z5.object({ prompt_tokens: z5.number() }).nullish()
1611
+ var openaiTextEmbeddingResponseSchema = z9.object({
1612
+ data: z9.array(z9.object({ embedding: z9.array(z9.number()) })),
1613
+ usage: z9.object({ prompt_tokens: z9.number() }).nullish()
1375
1614
  });
1376
1615
 
1377
1616
  // src/openai-image-model.ts
@@ -1380,25 +1619,26 @@ import {
1380
1619
  createJsonResponseHandler as createJsonResponseHandler4,
1381
1620
  postJsonToApi as postJsonToApi4
1382
1621
  } from "@ai-sdk/provider-utils";
1383
- import { z as z6 } from "zod";
1622
+ import { z as z10 } from "zod/v4";
1384
1623
 
1385
1624
  // src/openai-image-settings.ts
1386
1625
  var modelMaxImagesPerCall = {
1387
1626
  "dall-e-3": 1,
1388
- "dall-e-2": 10
1627
+ "dall-e-2": 10,
1628
+ "gpt-image-1": 10
1389
1629
  };
1630
+ var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
1390
1631
 
1391
1632
  // src/openai-image-model.ts
1392
1633
  var OpenAIImageModel = class {
1393
- constructor(modelId, settings, config) {
1634
+ constructor(modelId, config) {
1394
1635
  this.modelId = modelId;
1395
- this.settings = settings;
1396
1636
  this.config = config;
1397
- this.specificationVersion = "v1";
1637
+ this.specificationVersion = "v2";
1398
1638
  }
1399
1639
  get maxImagesPerCall() {
1400
- var _a, _b;
1401
- return (_b = (_a = this.settings.maxImagesPerCall) != null ? _a : modelMaxImagesPerCall[this.modelId]) != null ? _b : 1;
1640
+ var _a;
1641
+ return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
1402
1642
  }
1403
1643
  get provider() {
1404
1644
  return this.config.provider;
@@ -1438,7 +1678,7 @@ var OpenAIImageModel = class {
1438
1678
  n,
1439
1679
  size,
1440
1680
  ...(_d = providerOptions.openai) != null ? _d : {},
1441
- response_format: "b64_json"
1681
+ ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1442
1682
  },
1443
1683
  failedResponseHandler: openaiFailedResponseHandler,
1444
1684
  successfulResponseHandler: createJsonResponseHandler4(
@@ -1454,33 +1694,29 @@ var OpenAIImageModel = class {
1454
1694
  timestamp: currentDate,
1455
1695
  modelId: this.modelId,
1456
1696
  headers: responseHeaders
1697
+ },
1698
+ providerMetadata: {
1699
+ openai: {
1700
+ images: response.data.map(
1701
+ (item) => item.revised_prompt ? {
1702
+ revisedPrompt: item.revised_prompt
1703
+ } : null
1704
+ )
1705
+ }
1457
1706
  }
1458
1707
  };
1459
1708
  }
1460
1709
  };
1461
- var openaiImageResponseSchema = z6.object({
1462
- data: z6.array(z6.object({ b64_json: z6.string() }))
1710
+ var openaiImageResponseSchema = z10.object({
1711
+ data: z10.array(
1712
+ z10.object({ b64_json: z10.string(), revised_prompt: z10.string().optional() })
1713
+ )
1463
1714
  });
1464
1715
 
1465
1716
  // src/openai-tools.ts
1466
- import { z as z7 } from "zod";
1467
- var WebSearchPreviewParameters = z7.object({});
1468
- function webSearchPreviewTool({
1469
- searchContextSize,
1470
- userLocation
1471
- } = {}) {
1472
- return {
1473
- type: "provider-defined",
1474
- id: "openai.web_search_preview",
1475
- args: {
1476
- searchContextSize,
1477
- userLocation
1478
- },
1479
- parameters: WebSearchPreviewParameters
1480
- };
1481
- }
1482
1717
  var openaiTools = {
1483
- webSearchPreview: webSearchPreviewTool
1718
+ fileSearch,
1719
+ webSearchPreview
1484
1720
  };
1485
1721
 
1486
1722
  // src/openai-transcription-model.ts
@@ -1488,17 +1724,39 @@ import {
1488
1724
  combineHeaders as combineHeaders5,
1489
1725
  convertBase64ToUint8Array,
1490
1726
  createJsonResponseHandler as createJsonResponseHandler5,
1491
- parseProviderOptions as parseProviderOptions2,
1727
+ parseProviderOptions as parseProviderOptions4,
1492
1728
  postFormDataToApi
1493
1729
  } from "@ai-sdk/provider-utils";
1494
- import { z as z8 } from "zod";
1495
- var openAIProviderOptionsSchema = z8.object({
1496
- include: z8.array(z8.string()).nullish(),
1497
- language: z8.string().nullish(),
1498
- prompt: z8.string().nullish(),
1499
- temperature: z8.number().min(0).max(1).nullish().default(0),
1500
- timestampGranularities: z8.array(z8.enum(["word", "segment"])).nullish().default(["segment"])
1730
+ import { z as z12 } from "zod/v4";
1731
+
1732
+ // src/openai-transcription-options.ts
1733
+ import { z as z11 } from "zod/v4";
1734
+ var openAITranscriptionProviderOptions = z11.object({
1735
+ /**
1736
+ * Additional information to include in the transcription response.
1737
+ */
1738
+ include: z11.array(z11.string()).optional(),
1739
+ /**
1740
+ * The language of the input audio in ISO-639-1 format.
1741
+ */
1742
+ language: z11.string().optional(),
1743
+ /**
1744
+ * An optional text to guide the model's style or continue a previous audio segment.
1745
+ */
1746
+ prompt: z11.string().optional(),
1747
+ /**
1748
+ * The sampling temperature, between 0 and 1.
1749
+ * @default 0
1750
+ */
1751
+ temperature: z11.number().min(0).max(1).default(0).optional(),
1752
+ /**
1753
+ * The timestamp granularities to populate for this transcription.
1754
+ * @default ['segment']
1755
+ */
1756
+ timestampGranularities: z11.array(z11.enum(["word", "segment"])).default(["segment"]).optional()
1501
1757
  });
1758
+
1759
+ // src/openai-transcription-model.ts
1502
1760
  var languageMap = {
1503
1761
  afrikaans: "af",
1504
1762
  arabic: "ar",
@@ -1562,22 +1820,21 @@ var OpenAITranscriptionModel = class {
1562
1820
  constructor(modelId, config) {
1563
1821
  this.modelId = modelId;
1564
1822
  this.config = config;
1565
- this.specificationVersion = "v1";
1823
+ this.specificationVersion = "v2";
1566
1824
  }
1567
1825
  get provider() {
1568
1826
  return this.config.provider;
1569
1827
  }
1570
- getArgs({
1828
+ async getArgs({
1571
1829
  audio,
1572
1830
  mediaType,
1573
1831
  providerOptions
1574
1832
  }) {
1575
- var _a, _b, _c, _d, _e;
1576
1833
  const warnings = [];
1577
- const openAIOptions = parseProviderOptions2({
1834
+ const openAIOptions = await parseProviderOptions4({
1578
1835
  provider: "openai",
1579
1836
  providerOptions,
1580
- schema: openAIProviderOptionsSchema
1837
+ schema: openAITranscriptionProviderOptions
1581
1838
  });
1582
1839
  const formData = new FormData();
1583
1840
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
@@ -1585,15 +1842,14 @@ var OpenAITranscriptionModel = class {
1585
1842
  formData.append("file", new File([blob], "audio", { type: mediaType }));
1586
1843
  if (openAIOptions) {
1587
1844
  const transcriptionModelOptions = {
1588
- include: (_a = openAIOptions.include) != null ? _a : void 0,
1589
- language: (_b = openAIOptions.language) != null ? _b : void 0,
1590
- prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1591
- temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1592
- timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1845
+ include: openAIOptions.include,
1846
+ language: openAIOptions.language,
1847
+ prompt: openAIOptions.prompt,
1848
+ temperature: openAIOptions.temperature,
1849
+ timestamp_granularities: openAIOptions.timestampGranularities
1593
1850
  };
1594
- for (const key in transcriptionModelOptions) {
1595
- const value = transcriptionModelOptions[key];
1596
- if (value !== void 0) {
1851
+ for (const [key, value] of Object.entries(transcriptionModelOptions)) {
1852
+ if (value != null) {
1597
1853
  formData.append(key, String(value));
1598
1854
  }
1599
1855
  }
@@ -1606,7 +1862,7 @@ var OpenAITranscriptionModel = class {
1606
1862
  async doGenerate(options) {
1607
1863
  var _a, _b, _c, _d, _e, _f;
1608
1864
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1609
- const { formData, warnings } = this.getArgs(options);
1865
+ const { formData, warnings } = await this.getArgs(options);
1610
1866
  const {
1611
1867
  value: response,
1612
1868
  responseHeaders,
@@ -1645,38 +1901,44 @@ var OpenAITranscriptionModel = class {
1645
1901
  };
1646
1902
  }
1647
1903
  };
1648
- var openaiTranscriptionResponseSchema = z8.object({
1649
- text: z8.string(),
1650
- language: z8.string().nullish(),
1651
- duration: z8.number().nullish(),
1652
- words: z8.array(
1653
- z8.object({
1654
- word: z8.string(),
1655
- start: z8.number(),
1656
- end: z8.number()
1904
+ var openaiTranscriptionResponseSchema = z12.object({
1905
+ text: z12.string(),
1906
+ language: z12.string().nullish(),
1907
+ duration: z12.number().nullish(),
1908
+ words: z12.array(
1909
+ z12.object({
1910
+ word: z12.string(),
1911
+ start: z12.number(),
1912
+ end: z12.number()
1657
1913
  })
1658
1914
  ).nullish()
1659
1915
  });
1660
1916
 
1661
1917
  // src/responses/openai-responses-language-model.ts
1918
+ import {
1919
+ APICallError
1920
+ } from "@ai-sdk/provider";
1662
1921
  import {
1663
1922
  combineHeaders as combineHeaders6,
1664
1923
  createEventSourceResponseHandler as createEventSourceResponseHandler3,
1665
1924
  createJsonResponseHandler as createJsonResponseHandler6,
1666
1925
  generateId as generateId2,
1667
- parseProviderOptions as parseProviderOptions3,
1926
+ parseProviderOptions as parseProviderOptions6,
1668
1927
  postJsonToApi as postJsonToApi5
1669
1928
  } from "@ai-sdk/provider-utils";
1670
- import { z as z9 } from "zod";
1929
+ import { z as z14 } from "zod/v4";
1671
1930
 
1672
1931
  // src/responses/convert-to-openai-responses-messages.ts
1673
1932
  import {
1674
1933
  UnsupportedFunctionalityError as UnsupportedFunctionalityError4
1675
1934
  } from "@ai-sdk/provider";
1676
- function convertToOpenAIResponsesMessages({
1935
+ import { parseProviderOptions as parseProviderOptions5 } from "@ai-sdk/provider-utils";
1936
+ import { z as z13 } from "zod/v4";
1937
+ async function convertToOpenAIResponsesMessages({
1677
1938
  prompt,
1678
1939
  systemMessageMode
1679
1940
  }) {
1941
+ var _a, _b, _c, _d, _e, _f;
1680
1942
  const messages = [];
1681
1943
  const warnings = [];
1682
1944
  for (const { role, content } of prompt) {
@@ -1711,7 +1973,7 @@ function convertToOpenAIResponsesMessages({
1711
1973
  messages.push({
1712
1974
  role: "user",
1713
1975
  content: content.map((part, index) => {
1714
- var _a, _b, _c;
1976
+ var _a2, _b2, _c2;
1715
1977
  switch (part.type) {
1716
1978
  case "text": {
1717
1979
  return { type: "input_text", text: part.text };
@@ -1723,7 +1985,7 @@ function convertToOpenAIResponsesMessages({
1723
1985
  type: "input_image",
1724
1986
  image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
1725
1987
  // OpenAI specific extension: image detail
1726
- detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
1988
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
1727
1989
  };
1728
1990
  } else if (part.mediaType === "application/pdf") {
1729
1991
  if (part.data instanceof URL) {
@@ -1733,7 +1995,7 @@ function convertToOpenAIResponsesMessages({
1733
1995
  }
1734
1996
  return {
1735
1997
  type: "input_file",
1736
- filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
1998
+ filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
1737
1999
  file_data: `data:application/pdf;base64,${part.data}`
1738
2000
  };
1739
2001
  } else {
@@ -1748,22 +2010,72 @@ function convertToOpenAIResponsesMessages({
1748
2010
  break;
1749
2011
  }
1750
2012
  case "assistant": {
2013
+ const reasoningMessages = {};
1751
2014
  for (const part of content) {
1752
2015
  switch (part.type) {
1753
2016
  case "text": {
1754
2017
  messages.push({
1755
2018
  role: "assistant",
1756
- content: [{ type: "output_text", text: part.text }]
2019
+ content: [{ type: "output_text", text: part.text }],
2020
+ id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
1757
2021
  });
1758
2022
  break;
1759
2023
  }
1760
2024
  case "tool-call": {
2025
+ if (part.providerExecuted) {
2026
+ break;
2027
+ }
1761
2028
  messages.push({
1762
2029
  type: "function_call",
1763
2030
  call_id: part.toolCallId,
1764
2031
  name: part.toolName,
1765
- arguments: JSON.stringify(part.args)
2032
+ arguments: JSON.stringify(part.input),
2033
+ id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0
2034
+ });
2035
+ break;
2036
+ }
2037
+ case "tool-result": {
2038
+ warnings.push({
2039
+ type: "other",
2040
+ message: `tool result parts in assistant messages are not supported for OpenAI responses`
2041
+ });
2042
+ break;
2043
+ }
2044
+ case "reasoning": {
2045
+ const providerOptions = await parseProviderOptions5({
2046
+ provider: "openai",
2047
+ providerOptions: part.providerOptions,
2048
+ schema: openaiResponsesReasoningProviderOptionsSchema
1766
2049
  });
2050
+ const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
2051
+ if (reasoningId != null) {
2052
+ const existingReasoningMessage = reasoningMessages[reasoningId];
2053
+ const summaryParts = [];
2054
+ if (part.text.length > 0) {
2055
+ summaryParts.push({ type: "summary_text", text: part.text });
2056
+ } else if (existingReasoningMessage !== void 0) {
2057
+ warnings.push({
2058
+ type: "other",
2059
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
2060
+ });
2061
+ }
2062
+ if (existingReasoningMessage === void 0) {
2063
+ reasoningMessages[reasoningId] = {
2064
+ type: "reasoning",
2065
+ id: reasoningId,
2066
+ encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
2067
+ summary: summaryParts
2068
+ };
2069
+ messages.push(reasoningMessages[reasoningId]);
2070
+ } else {
2071
+ existingReasoningMessage.summary.push(...summaryParts);
2072
+ }
2073
+ } else {
2074
+ warnings.push({
2075
+ type: "other",
2076
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
2077
+ });
2078
+ }
1767
2079
  break;
1768
2080
  }
1769
2081
  }
@@ -1772,10 +2084,23 @@ function convertToOpenAIResponsesMessages({
1772
2084
  }
1773
2085
  case "tool": {
1774
2086
  for (const part of content) {
2087
+ const output = part.output;
2088
+ let contentValue;
2089
+ switch (output.type) {
2090
+ case "text":
2091
+ case "error-text":
2092
+ contentValue = output.value;
2093
+ break;
2094
+ case "content":
2095
+ case "json":
2096
+ case "error-json":
2097
+ contentValue = JSON.stringify(output.value);
2098
+ break;
2099
+ }
1775
2100
  messages.push({
1776
2101
  type: "function_call_output",
1777
2102
  call_id: part.toolCallId,
1778
- output: JSON.stringify(part.result)
2103
+ output: contentValue
1779
2104
  });
1780
2105
  }
1781
2106
  break;
@@ -1788,6 +2113,10 @@ function convertToOpenAIResponsesMessages({
1788
2113
  }
1789
2114
  return { messages, warnings };
1790
2115
  }
2116
+ var openaiResponsesReasoningProviderOptionsSchema = z13.object({
2117
+ itemId: z13.string().nullish(),
2118
+ reasoningEncryptedContent: z13.string().nullish()
2119
+ });
1791
2120
 
1792
2121
  // src/responses/map-openai-responses-finish-reason.ts
1793
2122
  function mapOpenAIResponseFinishReason({
@@ -1814,7 +2143,7 @@ import {
1814
2143
  function prepareResponsesTools({
1815
2144
  tools,
1816
2145
  toolChoice,
1817
- strict
2146
+ strictJsonSchema
1818
2147
  }) {
1819
2148
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1820
2149
  const toolWarnings = [];
@@ -1829,12 +2158,23 @@ function prepareResponsesTools({
1829
2158
  type: "function",
1830
2159
  name: tool.name,
1831
2160
  description: tool.description,
1832
- parameters: tool.parameters,
1833
- strict: strict ? true : void 0
2161
+ parameters: tool.inputSchema,
2162
+ strict: strictJsonSchema
1834
2163
  });
1835
2164
  break;
1836
2165
  case "provider-defined":
1837
2166
  switch (tool.id) {
2167
+ case "openai.file_search": {
2168
+ const args = fileSearchArgsSchema.parse(tool.args);
2169
+ openaiTools2.push({
2170
+ type: "file_search",
2171
+ vector_store_ids: args.vectorStoreIds,
2172
+ max_num_results: args.maxNumResults,
2173
+ ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
2174
+ filters: args.filters
2175
+ });
2176
+ break;
2177
+ }
1838
2178
  case "openai.web_search_preview":
1839
2179
  openaiTools2.push({
1840
2180
  type: "web_search_preview",
@@ -1864,7 +2204,7 @@ function prepareResponsesTools({
1864
2204
  case "tool":
1865
2205
  return {
1866
2206
  tools: openaiTools2,
1867
- toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2207
+ toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
1868
2208
  toolWarnings
1869
2209
  };
1870
2210
  default: {
@@ -1880,15 +2220,16 @@ function prepareResponsesTools({
1880
2220
  var OpenAIResponsesLanguageModel = class {
1881
2221
  constructor(modelId, config) {
1882
2222
  this.specificationVersion = "v2";
1883
- this.defaultObjectGenerationMode = "json";
1884
- this.supportsStructuredOutputs = true;
2223
+ this.supportedUrls = {
2224
+ "image/*": [/^https?:\/\/.*$/]
2225
+ };
1885
2226
  this.modelId = modelId;
1886
2227
  this.config = config;
1887
2228
  }
1888
2229
  get provider() {
1889
2230
  return this.config.provider;
1890
2231
  }
1891
- getArgs({
2232
+ async getArgs({
1892
2233
  maxOutputTokens,
1893
2234
  temperature,
1894
2235
  stopSequences,
@@ -1927,17 +2268,17 @@ var OpenAIResponsesLanguageModel = class {
1927
2268
  if (stopSequences != null) {
1928
2269
  warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
1929
2270
  }
1930
- const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
2271
+ const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
1931
2272
  prompt,
1932
2273
  systemMessageMode: modelConfig.systemMessageMode
1933
2274
  });
1934
2275
  warnings.push(...messageWarnings);
1935
- const openaiOptions = parseProviderOptions3({
2276
+ const openaiOptions = await parseProviderOptions6({
1936
2277
  provider: "openai",
1937
2278
  providerOptions,
1938
2279
  schema: openaiResponsesProviderOptionsSchema
1939
2280
  });
1940
- const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
2281
+ const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
1941
2282
  const baseArgs = {
1942
2283
  model: this.modelId,
1943
2284
  input: messages,
@@ -1948,7 +2289,7 @@ var OpenAIResponsesLanguageModel = class {
1948
2289
  text: {
1949
2290
  format: responseFormat.schema != null ? {
1950
2291
  type: "json_schema",
1951
- strict: isStrict,
2292
+ strict: strictJsonSchema,
1952
2293
  name: (_b = responseFormat.name) != null ? _b : "response",
1953
2294
  description: responseFormat.description,
1954
2295
  schema: responseFormat.schema
@@ -1962,9 +2303,18 @@ var OpenAIResponsesLanguageModel = class {
1962
2303
  store: openaiOptions == null ? void 0 : openaiOptions.store,
1963
2304
  user: openaiOptions == null ? void 0 : openaiOptions.user,
1964
2305
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2306
+ service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2307
+ include: openaiOptions == null ? void 0 : openaiOptions.include,
1965
2308
  // model-specific settings:
1966
- ...modelConfig.isReasoningModel && (openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
1967
- reasoning: { effort: openaiOptions == null ? void 0 : openaiOptions.reasoningEffort }
2309
+ ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2310
+ reasoning: {
2311
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
2312
+ effort: openaiOptions.reasoningEffort
2313
+ },
2314
+ ...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
2315
+ summary: openaiOptions.reasoningSummary
2316
+ }
2317
+ }
1968
2318
  },
1969
2319
  ...modelConfig.requiredAutoTruncation && {
1970
2320
  truncation: "auto"
@@ -1987,6 +2337,37 @@ var OpenAIResponsesLanguageModel = class {
1987
2337
  details: "topP is not supported for reasoning models"
1988
2338
  });
1989
2339
  }
2340
+ } else {
2341
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
2342
+ warnings.push({
2343
+ type: "unsupported-setting",
2344
+ setting: "reasoningEffort",
2345
+ details: "reasoningEffort is not supported for non-reasoning models"
2346
+ });
2347
+ }
2348
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
2349
+ warnings.push({
2350
+ type: "unsupported-setting",
2351
+ setting: "reasoningSummary",
2352
+ details: "reasoningSummary is not supported for non-reasoning models"
2353
+ });
2354
+ }
2355
+ }
2356
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2357
+ warnings.push({
2358
+ type: "unsupported-setting",
2359
+ setting: "serviceTier",
2360
+ details: "flex processing is only available for o3 and o4-mini models"
2361
+ });
2362
+ delete baseArgs.service_tier;
2363
+ }
2364
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !supportsPriorityProcessing2(this.modelId)) {
2365
+ warnings.push({
2366
+ type: "unsupported-setting",
2367
+ setting: "serviceTier",
2368
+ details: "priority processing is only available for supported models (GPT-4, o3, o4-mini) and requires Enterprise access"
2369
+ });
2370
+ delete baseArgs.service_tier;
1990
2371
  }
1991
2372
  const {
1992
2373
  tools: openaiTools2,
@@ -1995,7 +2376,7 @@ var OpenAIResponsesLanguageModel = class {
1995
2376
  } = prepareResponsesTools({
1996
2377
  tools,
1997
2378
  toolChoice,
1998
- strict: isStrict
2379
+ strictJsonSchema
1999
2380
  });
2000
2381
  return {
2001
2382
  args: {
@@ -2007,84 +2388,137 @@ var OpenAIResponsesLanguageModel = class {
2007
2388
  };
2008
2389
  }
2009
2390
  async doGenerate(options) {
2010
- var _a, _b, _c, _d, _e, _f, _g, _h;
2011
- const { args: body, warnings } = this.getArgs(options);
2391
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2392
+ const { args: body, warnings } = await this.getArgs(options);
2393
+ const url = this.config.url({
2394
+ path: "/responses",
2395
+ modelId: this.modelId
2396
+ });
2012
2397
  const {
2013
2398
  responseHeaders,
2014
2399
  value: response,
2015
2400
  rawValue: rawResponse
2016
2401
  } = await postJsonToApi5({
2017
- url: this.config.url({
2018
- path: "/responses",
2019
- modelId: this.modelId
2020
- }),
2402
+ url,
2021
2403
  headers: combineHeaders6(this.config.headers(), options.headers),
2022
2404
  body,
2023
2405
  failedResponseHandler: openaiFailedResponseHandler,
2024
2406
  successfulResponseHandler: createJsonResponseHandler6(
2025
- z9.object({
2026
- id: z9.string(),
2027
- created_at: z9.number(),
2028
- model: z9.string(),
2029
- output: z9.array(
2030
- z9.discriminatedUnion("type", [
2031
- z9.object({
2032
- type: z9.literal("message"),
2033
- role: z9.literal("assistant"),
2034
- content: z9.array(
2035
- z9.object({
2036
- type: z9.literal("output_text"),
2037
- text: z9.string(),
2038
- annotations: z9.array(
2039
- z9.object({
2040
- type: z9.literal("url_citation"),
2041
- start_index: z9.number(),
2042
- end_index: z9.number(),
2043
- url: z9.string(),
2044
- title: z9.string()
2407
+ z14.object({
2408
+ id: z14.string(),
2409
+ created_at: z14.number(),
2410
+ error: z14.object({
2411
+ code: z14.string(),
2412
+ message: z14.string()
2413
+ }).nullish(),
2414
+ model: z14.string(),
2415
+ output: z14.array(
2416
+ z14.discriminatedUnion("type", [
2417
+ z14.object({
2418
+ type: z14.literal("message"),
2419
+ role: z14.literal("assistant"),
2420
+ id: z14.string(),
2421
+ content: z14.array(
2422
+ z14.object({
2423
+ type: z14.literal("output_text"),
2424
+ text: z14.string(),
2425
+ annotations: z14.array(
2426
+ z14.object({
2427
+ type: z14.literal("url_citation"),
2428
+ start_index: z14.number(),
2429
+ end_index: z14.number(),
2430
+ url: z14.string(),
2431
+ title: z14.string()
2045
2432
  })
2046
2433
  )
2047
2434
  })
2048
2435
  )
2049
2436
  }),
2050
- z9.object({
2051
- type: z9.literal("function_call"),
2052
- call_id: z9.string(),
2053
- name: z9.string(),
2054
- arguments: z9.string()
2437
+ z14.object({
2438
+ type: z14.literal("function_call"),
2439
+ call_id: z14.string(),
2440
+ name: z14.string(),
2441
+ arguments: z14.string(),
2442
+ id: z14.string()
2055
2443
  }),
2056
- z9.object({
2057
- type: z9.literal("web_search_call")
2444
+ z14.object({
2445
+ type: z14.literal("web_search_call"),
2446
+ id: z14.string(),
2447
+ status: z14.string().optional()
2058
2448
  }),
2059
- z9.object({
2060
- type: z9.literal("computer_call")
2449
+ z14.object({
2450
+ type: z14.literal("computer_call"),
2451
+ id: z14.string(),
2452
+ status: z14.string().optional()
2061
2453
  }),
2062
- z9.object({
2063
- type: z9.literal("reasoning")
2454
+ z14.object({
2455
+ type: z14.literal("reasoning"),
2456
+ id: z14.string(),
2457
+ encrypted_content: z14.string().nullish(),
2458
+ summary: z14.array(
2459
+ z14.object({
2460
+ type: z14.literal("summary_text"),
2461
+ text: z14.string()
2462
+ })
2463
+ )
2064
2464
  })
2065
2465
  ])
2066
2466
  ),
2067
- incomplete_details: z9.object({ reason: z9.string() }).nullable(),
2068
- usage: usageSchema
2467
+ incomplete_details: z14.object({ reason: z14.string() }).nullable(),
2468
+ usage: usageSchema2
2069
2469
  })
2070
2470
  ),
2071
2471
  abortSignal: options.abortSignal,
2072
2472
  fetch: this.config.fetch
2073
2473
  });
2474
+ if (response.error) {
2475
+ throw new APICallError({
2476
+ message: response.error.message,
2477
+ url,
2478
+ requestBodyValues: body,
2479
+ statusCode: 400,
2480
+ responseHeaders,
2481
+ responseBody: rawResponse,
2482
+ isRetryable: false
2483
+ });
2484
+ }
2074
2485
  const content = [];
2075
2486
  for (const part of response.output) {
2076
2487
  switch (part.type) {
2488
+ case "reasoning": {
2489
+ if (part.summary.length === 0) {
2490
+ part.summary.push({ type: "summary_text", text: "" });
2491
+ }
2492
+ for (const summary of part.summary) {
2493
+ content.push({
2494
+ type: "reasoning",
2495
+ text: summary.text,
2496
+ providerMetadata: {
2497
+ openai: {
2498
+ itemId: part.id,
2499
+ reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
2500
+ }
2501
+ }
2502
+ });
2503
+ }
2504
+ break;
2505
+ }
2077
2506
  case "message": {
2078
2507
  for (const contentPart of part.content) {
2079
2508
  content.push({
2080
2509
  type: "text",
2081
- text: contentPart.text
2510
+ text: contentPart.text,
2511
+ providerMetadata: {
2512
+ openai: {
2513
+ itemId: part.id
2514
+ }
2515
+ }
2082
2516
  });
2083
2517
  for (const annotation of contentPart.annotations) {
2084
2518
  content.push({
2085
2519
  type: "source",
2086
2520
  sourceType: "url",
2087
- id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : generateId2(),
2521
+ id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : generateId2(),
2088
2522
  url: annotation.url,
2089
2523
  title: annotation.title
2090
2524
  });
@@ -2095,10 +2529,51 @@ var OpenAIResponsesLanguageModel = class {
2095
2529
  case "function_call": {
2096
2530
  content.push({
2097
2531
  type: "tool-call",
2098
- toolCallType: "function",
2099
2532
  toolCallId: part.call_id,
2100
2533
  toolName: part.name,
2101
- args: part.arguments
2534
+ input: part.arguments,
2535
+ providerMetadata: {
2536
+ openai: {
2537
+ itemId: part.id
2538
+ }
2539
+ }
2540
+ });
2541
+ break;
2542
+ }
2543
+ case "web_search_call": {
2544
+ content.push({
2545
+ type: "tool-call",
2546
+ toolCallId: part.id,
2547
+ toolName: "web_search_preview",
2548
+ input: "",
2549
+ providerExecuted: true
2550
+ });
2551
+ content.push({
2552
+ type: "tool-result",
2553
+ toolCallId: part.id,
2554
+ toolName: "web_search_preview",
2555
+ result: { status: part.status || "completed" },
2556
+ providerExecuted: true
2557
+ });
2558
+ break;
2559
+ }
2560
+ case "computer_call": {
2561
+ content.push({
2562
+ type: "tool-call",
2563
+ toolCallId: part.id,
2564
+ toolName: "computer_use",
2565
+ input: "",
2566
+ providerExecuted: true
2567
+ });
2568
+ content.push({
2569
+ type: "tool-result",
2570
+ toolCallId: part.id,
2571
+ toolName: "computer_use",
2572
+ result: {
2573
+ type: "computer_use_tool_result",
2574
+ status: part.status || "completed"
2575
+ },
2576
+ providerExecuted: true
2102
2577
  });
2103
2578
  break;
2104
2579
  }
@@ -2107,12 +2582,15 @@ var OpenAIResponsesLanguageModel = class {
2107
2582
  return {
2108
2583
  content,
2109
2584
  finishReason: mapOpenAIResponseFinishReason({
2110
- finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
2585
+ finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
2111
2586
  hasToolCalls: content.some((part) => part.type === "tool-call")
2112
2587
  }),
2113
2588
  usage: {
2114
2589
  inputTokens: response.usage.input_tokens,
2115
- outputTokens: response.usage.output_tokens
2590
+ outputTokens: response.usage.output_tokens,
2591
+ totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2592
+ reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
2593
+ cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
2116
2594
  },
2117
2595
  request: { body },
2118
2596
  response: {
@@ -2124,16 +2602,14 @@ var OpenAIResponsesLanguageModel = class {
2124
2602
  },
2125
2603
  providerMetadata: {
2126
2604
  openai: {
2127
- responseId: response.id,
2128
- cachedPromptTokens: (_f = (_e = response.usage.input_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : null,
2129
- reasoningTokens: (_h = (_g = response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : null
2605
+ responseId: response.id
2130
2606
  }
2131
2607
  },
2132
2608
  warnings
2133
2609
  };
2134
2610
  }
2135
2611
  async doStream(options) {
2136
- const { args: body, warnings } = this.getArgs(options);
2612
+ const { args: body, warnings } = await this.getArgs(options);
2137
2613
  const { responseHeaders, value: response } = await postJsonToApi5({
2138
2614
  url: this.config.url({
2139
2615
  path: "/responses",
@@ -2155,13 +2631,13 @@ var OpenAIResponsesLanguageModel = class {
2155
2631
  let finishReason = "unknown";
2156
2632
  const usage = {
2157
2633
  inputTokens: void 0,
2158
- outputTokens: void 0
2634
+ outputTokens: void 0,
2635
+ totalTokens: void 0
2159
2636
  };
2160
- let cachedPromptTokens = null;
2161
- let reasoningTokens = null;
2162
2637
  let responseId = null;
2163
2638
  const ongoingToolCalls = {};
2164
2639
  let hasToolCalls = false;
2640
+ const activeReasoning = {};
2165
2641
  return {
2166
2642
  stream: response.pipeThrough(
2167
2643
  new TransformStream({
@@ -2169,7 +2645,10 @@ var OpenAIResponsesLanguageModel = class {
2169
2645
  controller.enqueue({ type: "stream-start", warnings });
2170
2646
  },
2171
2647
  transform(chunk, controller) {
2172
- var _a, _b, _c, _d, _e, _f, _g, _h;
2648
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2649
+ if (options.includeRawChunks) {
2650
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2651
+ }
2173
2652
  if (!chunk.success) {
2174
2653
  finishReason = "error";
2175
2654
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2183,22 +2662,151 @@ var OpenAIResponsesLanguageModel = class {
2183
2662
  toolCallId: value.item.call_id
2184
2663
  };
2185
2664
  controller.enqueue({
2186
- type: "tool-call-delta",
2187
- toolCallType: "function",
2665
+ type: "tool-input-start",
2666
+ id: value.item.call_id,
2667
+ toolName: value.item.name
2668
+ });
2669
+ } else if (value.item.type === "web_search_call") {
2670
+ ongoingToolCalls[value.output_index] = {
2671
+ toolName: "web_search_preview",
2672
+ toolCallId: value.item.id
2673
+ };
2674
+ controller.enqueue({
2675
+ type: "tool-input-start",
2676
+ id: value.item.id,
2677
+ toolName: "web_search_preview"
2678
+ });
2679
+ } else if (value.item.type === "computer_call") {
2680
+ ongoingToolCalls[value.output_index] = {
2681
+ toolName: "computer_use",
2682
+ toolCallId: value.item.id
2683
+ };
2684
+ controller.enqueue({
2685
+ type: "tool-input-start",
2686
+ id: value.item.id,
2687
+ toolName: "computer_use"
2688
+ });
2689
+ } else if (value.item.type === "message") {
2690
+ controller.enqueue({
2691
+ type: "text-start",
2692
+ id: value.item.id,
2693
+ providerMetadata: {
2694
+ openai: {
2695
+ itemId: value.item.id
2696
+ }
2697
+ }
2698
+ });
2699
+ } else if (isResponseOutputItemAddedReasoningChunk(value)) {
2700
+ activeReasoning[value.item.id] = {
2701
+ encryptedContent: value.item.encrypted_content,
2702
+ summaryParts: [0]
2703
+ };
2704
+ controller.enqueue({
2705
+ type: "reasoning-start",
2706
+ id: `${value.item.id}:0`,
2707
+ providerMetadata: {
2708
+ openai: {
2709
+ itemId: value.item.id,
2710
+ reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
2711
+ }
2712
+ }
2713
+ });
2714
+ }
2715
+ } else if (isResponseOutputItemDoneChunk(value)) {
2716
+ if (value.item.type === "function_call") {
2717
+ ongoingToolCalls[value.output_index] = void 0;
2718
+ hasToolCalls = true;
2719
+ controller.enqueue({
2720
+ type: "tool-input-end",
2721
+ id: value.item.call_id
2722
+ });
2723
+ controller.enqueue({
2724
+ type: "tool-call",
2188
2725
  toolCallId: value.item.call_id,
2189
2726
  toolName: value.item.name,
2190
- argsTextDelta: value.item.arguments
2727
+ input: value.item.arguments,
2728
+ providerMetadata: {
2729
+ openai: {
2730
+ itemId: value.item.id
2731
+ }
2732
+ }
2733
+ });
2734
+ } else if (value.item.type === "web_search_call") {
2735
+ ongoingToolCalls[value.output_index] = void 0;
2736
+ hasToolCalls = true;
2737
+ controller.enqueue({
2738
+ type: "tool-input-end",
2739
+ id: value.item.id
2740
+ });
2741
+ controller.enqueue({
2742
+ type: "tool-call",
2743
+ toolCallId: value.item.id,
2744
+ toolName: "web_search_preview",
2745
+ input: "",
2746
+ providerExecuted: true
2747
+ });
2748
+ controller.enqueue({
2749
+ type: "tool-result",
2750
+ toolCallId: value.item.id,
2751
+ toolName: "web_search_preview",
2752
+ result: {
2753
+ type: "web_search_tool_result",
2754
+ status: value.item.status || "completed"
2755
+ },
2756
+ providerExecuted: true
2757
+ });
2758
+ } else if (value.item.type === "computer_call") {
2759
+ ongoingToolCalls[value.output_index] = void 0;
2760
+ hasToolCalls = true;
2761
+ controller.enqueue({
2762
+ type: "tool-input-end",
2763
+ id: value.item.id
2764
+ });
2765
+ controller.enqueue({
2766
+ type: "tool-call",
2767
+ toolCallId: value.item.id,
2768
+ toolName: "computer_use",
2769
+ input: "",
2770
+ providerExecuted: true
2191
2771
  });
2772
+ controller.enqueue({
2773
+ type: "tool-result",
2774
+ toolCallId: value.item.id,
2775
+ toolName: "computer_use",
2776
+ result: {
2777
+ type: "computer_use_tool_result",
2778
+ status: value.item.status || "completed"
2779
+ },
2780
+ providerExecuted: true
2781
+ });
2782
+ } else if (value.item.type === "message") {
2783
+ controller.enqueue({
2784
+ type: "text-end",
2785
+ id: value.item.id
2786
+ });
2787
+ } else if (isResponseOutputItemDoneReasoningChunk(value)) {
2788
+ const activeReasoningPart = activeReasoning[value.item.id];
2789
+ for (const summaryIndex of activeReasoningPart.summaryParts) {
2790
+ controller.enqueue({
2791
+ type: "reasoning-end",
2792
+ id: `${value.item.id}:${summaryIndex}`,
2793
+ providerMetadata: {
2794
+ openai: {
2795
+ itemId: value.item.id,
2796
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2797
+ }
2798
+ }
2799
+ });
2800
+ }
2801
+ delete activeReasoning[value.item.id];
2192
2802
  }
2193
2803
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
2194
2804
  const toolCall = ongoingToolCalls[value.output_index];
2195
2805
  if (toolCall != null) {
2196
2806
  controller.enqueue({
2197
- type: "tool-call-delta",
2198
- toolCallType: "function",
2199
- toolCallId: toolCall.toolCallId,
2200
- toolName: toolCall.toolName,
2201
- argsTextDelta: value.delta
2807
+ type: "tool-input-delta",
2808
+ id: toolCall.toolCallId,
2809
+ delta: value.delta
2202
2810
  });
2203
2811
  }
2204
2812
  } else if (isResponseCreatedChunk(value)) {
@@ -2211,36 +2819,57 @@ var OpenAIResponsesLanguageModel = class {
2211
2819
  });
2212
2820
  } else if (isTextDeltaChunk(value)) {
2213
2821
  controller.enqueue({
2214
- type: "text",
2215
- text: value.delta
2822
+ type: "text-delta",
2823
+ id: value.item_id,
2824
+ delta: value.delta
2216
2825
  });
2217
- } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2218
- ongoingToolCalls[value.output_index] = void 0;
2219
- hasToolCalls = true;
2826
+ } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2827
+ if (value.summary_index > 0) {
2828
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2829
+ value.summary_index
2830
+ );
2831
+ controller.enqueue({
2832
+ type: "reasoning-start",
2833
+ id: `${value.item_id}:${value.summary_index}`,
2834
+ providerMetadata: {
2835
+ openai: {
2836
+ itemId: value.item_id,
2837
+ reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2838
+ }
2839
+ }
2840
+ });
2841
+ }
2842
+ } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2220
2843
  controller.enqueue({
2221
- type: "tool-call",
2222
- toolCallType: "function",
2223
- toolCallId: value.item.call_id,
2224
- toolName: value.item.name,
2225
- args: value.item.arguments
2844
+ type: "reasoning-delta",
2845
+ id: `${value.item_id}:${value.summary_index}`,
2846
+ delta: value.delta,
2847
+ providerMetadata: {
2848
+ openai: {
2849
+ itemId: value.item_id
2850
+ }
2851
+ }
2226
2852
  });
2227
2853
  } else if (isResponseFinishedChunk(value)) {
2228
2854
  finishReason = mapOpenAIResponseFinishReason({
2229
- finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
2855
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2230
2856
  hasToolCalls
2231
2857
  });
2232
2858
  usage.inputTokens = value.response.usage.input_tokens;
2233
2859
  usage.outputTokens = value.response.usage.output_tokens;
2234
- cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
2235
- reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
2860
+ usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2861
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2862
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2236
2863
  } else if (isResponseAnnotationAddedChunk(value)) {
2237
2864
  controller.enqueue({
2238
2865
  type: "source",
2239
2866
  sourceType: "url",
2240
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
2867
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
2241
2868
  url: value.annotation.url,
2242
2869
  title: value.annotation.title
2243
2870
  });
2871
+ } else if (isErrorChunk(value)) {
2872
+ controller.enqueue({ type: "error", error: value });
2244
2873
  }
2245
2874
  },
2246
2875
  flush(controller) {
@@ -2248,13 +2877,9 @@ var OpenAIResponsesLanguageModel = class {
2248
2877
  type: "finish",
2249
2878
  finishReason,
2250
2879
  usage,
2251
- ...(cachedPromptTokens != null || reasoningTokens != null) && {
2252
- providerMetadata: {
2253
- openai: {
2254
- responseId,
2255
- cachedPromptTokens,
2256
- reasoningTokens
2257
- }
2880
+ providerMetadata: {
2881
+ openai: {
2882
+ responseId
2258
2883
  }
2259
2884
  }
2260
2885
  });
@@ -2266,87 +2891,141 @@ var OpenAIResponsesLanguageModel = class {
2266
2891
  };
2267
2892
  }
2268
2893
  };
2269
- var usageSchema = z9.object({
2270
- input_tokens: z9.number(),
2271
- input_tokens_details: z9.object({ cached_tokens: z9.number().nullish() }).nullish(),
2272
- output_tokens: z9.number(),
2273
- output_tokens_details: z9.object({ reasoning_tokens: z9.number().nullish() }).nullish()
2894
+ var usageSchema2 = z14.object({
2895
+ input_tokens: z14.number(),
2896
+ input_tokens_details: z14.object({ cached_tokens: z14.number().nullish() }).nullish(),
2897
+ output_tokens: z14.number(),
2898
+ output_tokens_details: z14.object({ reasoning_tokens: z14.number().nullish() }).nullish()
2899
+ });
2900
+ var textDeltaChunkSchema = z14.object({
2901
+ type: z14.literal("response.output_text.delta"),
2902
+ item_id: z14.string(),
2903
+ delta: z14.string()
2274
2904
  });
2275
- var textDeltaChunkSchema = z9.object({
2276
- type: z9.literal("response.output_text.delta"),
2277
- delta: z9.string()
2905
+ var errorChunkSchema = z14.object({
2906
+ type: z14.literal("error"),
2907
+ code: z14.string(),
2908
+ message: z14.string(),
2909
+ param: z14.string().nullish(),
2910
+ sequence_number: z14.number()
2278
2911
  });
2279
- var responseFinishedChunkSchema = z9.object({
2280
- type: z9.enum(["response.completed", "response.incomplete"]),
2281
- response: z9.object({
2282
- incomplete_details: z9.object({ reason: z9.string() }).nullish(),
2283
- usage: usageSchema
2912
+ var responseFinishedChunkSchema = z14.object({
2913
+ type: z14.enum(["response.completed", "response.incomplete"]),
2914
+ response: z14.object({
2915
+ incomplete_details: z14.object({ reason: z14.string() }).nullish(),
2916
+ usage: usageSchema2
2284
2917
  })
2285
2918
  });
2286
- var responseCreatedChunkSchema = z9.object({
2287
- type: z9.literal("response.created"),
2288
- response: z9.object({
2289
- id: z9.string(),
2290
- created_at: z9.number(),
2291
- model: z9.string()
2919
+ var responseCreatedChunkSchema = z14.object({
2920
+ type: z14.literal("response.created"),
2921
+ response: z14.object({
2922
+ id: z14.string(),
2923
+ created_at: z14.number(),
2924
+ model: z14.string()
2292
2925
  })
2293
2926
  });
2294
- var responseOutputItemDoneSchema = z9.object({
2295
- type: z9.literal("response.output_item.done"),
2296
- output_index: z9.number(),
2297
- item: z9.discriminatedUnion("type", [
2298
- z9.object({
2299
- type: z9.literal("message")
2927
+ var responseOutputItemAddedSchema = z14.object({
2928
+ type: z14.literal("response.output_item.added"),
2929
+ output_index: z14.number(),
2930
+ item: z14.discriminatedUnion("type", [
2931
+ z14.object({
2932
+ type: z14.literal("message"),
2933
+ id: z14.string()
2300
2934
  }),
2301
- z9.object({
2302
- type: z9.literal("function_call"),
2303
- id: z9.string(),
2304
- call_id: z9.string(),
2305
- name: z9.string(),
2306
- arguments: z9.string(),
2307
- status: z9.literal("completed")
2935
+ z14.object({
2936
+ type: z14.literal("reasoning"),
2937
+ id: z14.string(),
2938
+ encrypted_content: z14.string().nullish()
2939
+ }),
2940
+ z14.object({
2941
+ type: z14.literal("function_call"),
2942
+ id: z14.string(),
2943
+ call_id: z14.string(),
2944
+ name: z14.string(),
2945
+ arguments: z14.string()
2946
+ }),
2947
+ z14.object({
2948
+ type: z14.literal("web_search_call"),
2949
+ id: z14.string(),
2950
+ status: z14.string()
2951
+ }),
2952
+ z14.object({
2953
+ type: z14.literal("computer_call"),
2954
+ id: z14.string(),
2955
+ status: z14.string()
2308
2956
  })
2309
2957
  ])
2310
2958
  });
2311
- var responseFunctionCallArgumentsDeltaSchema = z9.object({
2312
- type: z9.literal("response.function_call_arguments.delta"),
2313
- item_id: z9.string(),
2314
- output_index: z9.number(),
2315
- delta: z9.string()
2316
- });
2317
- var responseOutputItemAddedSchema = z9.object({
2318
- type: z9.literal("response.output_item.added"),
2319
- output_index: z9.number(),
2320
- item: z9.discriminatedUnion("type", [
2321
- z9.object({
2322
- type: z9.literal("message")
2959
+ var responseOutputItemDoneSchema = z14.object({
2960
+ type: z14.literal("response.output_item.done"),
2961
+ output_index: z14.number(),
2962
+ item: z14.discriminatedUnion("type", [
2963
+ z14.object({
2964
+ type: z14.literal("message"),
2965
+ id: z14.string()
2966
+ }),
2967
+ z14.object({
2968
+ type: z14.literal("reasoning"),
2969
+ id: z14.string(),
2970
+ encrypted_content: z14.string().nullish()
2971
+ }),
2972
+ z14.object({
2973
+ type: z14.literal("function_call"),
2974
+ id: z14.string(),
2975
+ call_id: z14.string(),
2976
+ name: z14.string(),
2977
+ arguments: z14.string(),
2978
+ status: z14.literal("completed")
2323
2979
  }),
2324
- z9.object({
2325
- type: z9.literal("function_call"),
2326
- id: z9.string(),
2327
- call_id: z9.string(),
2328
- name: z9.string(),
2329
- arguments: z9.string()
2980
+ z14.object({
2981
+ type: z14.literal("web_search_call"),
2982
+ id: z14.string(),
2983
+ status: z14.literal("completed")
2984
+ }),
2985
+ z14.object({
2986
+ type: z14.literal("computer_call"),
2987
+ id: z14.string(),
2988
+ status: z14.literal("completed")
2330
2989
  })
2331
2990
  ])
2332
2991
  });
2333
- var responseAnnotationAddedSchema = z9.object({
2334
- type: z9.literal("response.output_text.annotation.added"),
2335
- annotation: z9.object({
2336
- type: z9.literal("url_citation"),
2337
- url: z9.string(),
2338
- title: z9.string()
2992
+ var responseFunctionCallArgumentsDeltaSchema = z14.object({
2993
+ type: z14.literal("response.function_call_arguments.delta"),
2994
+ item_id: z14.string(),
2995
+ output_index: z14.number(),
2996
+ delta: z14.string()
2997
+ });
2998
+ var responseAnnotationAddedSchema = z14.object({
2999
+ type: z14.literal("response.output_text.annotation.added"),
3000
+ annotation: z14.object({
3001
+ type: z14.literal("url_citation"),
3002
+ url: z14.string(),
3003
+ title: z14.string()
2339
3004
  })
2340
3005
  });
2341
- var openaiResponsesChunkSchema = z9.union([
3006
+ var responseReasoningSummaryPartAddedSchema = z14.object({
3007
+ type: z14.literal("response.reasoning_summary_part.added"),
3008
+ item_id: z14.string(),
3009
+ summary_index: z14.number()
3010
+ });
3011
+ var responseReasoningSummaryTextDeltaSchema = z14.object({
3012
+ type: z14.literal("response.reasoning_summary_text.delta"),
3013
+ item_id: z14.string(),
3014
+ summary_index: z14.number(),
3015
+ delta: z14.string()
3016
+ });
3017
+ var openaiResponsesChunkSchema = z14.union([
2342
3018
  textDeltaChunkSchema,
2343
3019
  responseFinishedChunkSchema,
2344
3020
  responseCreatedChunkSchema,
3021
+ responseOutputItemAddedSchema,
2345
3022
  responseOutputItemDoneSchema,
2346
3023
  responseFunctionCallArgumentsDeltaSchema,
2347
- responseOutputItemAddedSchema,
2348
3024
  responseAnnotationAddedSchema,
2349
- z9.object({ type: z9.string() }).passthrough()
3025
+ responseReasoningSummaryPartAddedSchema,
3026
+ responseReasoningSummaryTextDeltaSchema,
3027
+ errorChunkSchema,
3028
+ z14.object({ type: z14.string() }).loose()
2350
3029
  // fallback for unknown chunks
2351
3030
  ]);
2352
3031
  function isTextDeltaChunk(chunk) {
@@ -2355,6 +3034,9 @@ function isTextDeltaChunk(chunk) {
2355
3034
  function isResponseOutputItemDoneChunk(chunk) {
2356
3035
  return chunk.type === "response.output_item.done";
2357
3036
  }
3037
+ function isResponseOutputItemDoneReasoningChunk(chunk) {
3038
+ return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
3039
+ }
2358
3040
  function isResponseFinishedChunk(chunk) {
2359
3041
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
2360
3042
  }
@@ -2367,11 +3049,23 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
2367
3049
  function isResponseOutputItemAddedChunk(chunk) {
2368
3050
  return chunk.type === "response.output_item.added";
2369
3051
  }
3052
+ function isResponseOutputItemAddedReasoningChunk(chunk) {
3053
+ return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
3054
+ }
2370
3055
  function isResponseAnnotationAddedChunk(chunk) {
2371
3056
  return chunk.type === "response.output_text.annotation.added";
2372
3057
  }
3058
+ function isResponseReasoningSummaryPartAddedChunk(chunk) {
3059
+ return chunk.type === "response.reasoning_summary_part.added";
3060
+ }
3061
+ function isResponseReasoningSummaryTextDeltaChunk(chunk) {
3062
+ return chunk.type === "response.reasoning_summary_text.delta";
3063
+ }
3064
+ function isErrorChunk(chunk) {
3065
+ return chunk.type === "error";
3066
+ }
2373
3067
  function getResponsesModelConfig(modelId) {
2374
- if (modelId.startsWith("o")) {
3068
+ if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
2375
3069
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
2376
3070
  return {
2377
3071
  isReasoningModel: true,
@@ -2391,48 +3085,58 @@ function getResponsesModelConfig(modelId) {
2391
3085
  requiredAutoTruncation: false
2392
3086
  };
2393
3087
  }
2394
- var openaiResponsesProviderOptionsSchema = z9.object({
2395
- metadata: z9.any().nullish(),
2396
- parallelToolCalls: z9.boolean().nullish(),
2397
- previousResponseId: z9.string().nullish(),
2398
- store: z9.boolean().nullish(),
2399
- user: z9.string().nullish(),
2400
- reasoningEffort: z9.string().nullish(),
2401
- strictSchemas: z9.boolean().nullish(),
2402
- instructions: z9.string().nullish()
3088
+ function supportsFlexProcessing2(modelId) {
3089
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3090
+ }
3091
+ function supportsPriorityProcessing2(modelId) {
3092
+ return modelId.startsWith("gpt-4") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3093
+ }
3094
+ var openaiResponsesProviderOptionsSchema = z14.object({
3095
+ metadata: z14.any().nullish(),
3096
+ parallelToolCalls: z14.boolean().nullish(),
3097
+ previousResponseId: z14.string().nullish(),
3098
+ store: z14.boolean().nullish(),
3099
+ user: z14.string().nullish(),
3100
+ reasoningEffort: z14.string().nullish(),
3101
+ strictJsonSchema: z14.boolean().nullish(),
3102
+ instructions: z14.string().nullish(),
3103
+ reasoningSummary: z14.string().nullish(),
3104
+ serviceTier: z14.enum(["auto", "flex", "priority"]).nullish(),
3105
+ include: z14.array(z14.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish()
2403
3106
  });
2404
3107
 
2405
3108
  // src/openai-speech-model.ts
2406
3109
  import {
2407
3110
  combineHeaders as combineHeaders7,
2408
3111
  createBinaryResponseHandler,
2409
- parseProviderOptions as parseProviderOptions4,
3112
+ parseProviderOptions as parseProviderOptions7,
2410
3113
  postJsonToApi as postJsonToApi6
2411
3114
  } from "@ai-sdk/provider-utils";
2412
- import { z as z10 } from "zod";
2413
- var OpenAIProviderOptionsSchema = z10.object({
2414
- instructions: z10.string().nullish(),
2415
- speed: z10.number().min(0.25).max(4).default(1).nullish()
3115
+ import { z as z15 } from "zod/v4";
3116
+ var OpenAIProviderOptionsSchema = z15.object({
3117
+ instructions: z15.string().nullish(),
3118
+ speed: z15.number().min(0.25).max(4).default(1).nullish()
2416
3119
  });
2417
3120
  var OpenAISpeechModel = class {
2418
3121
  constructor(modelId, config) {
2419
3122
  this.modelId = modelId;
2420
3123
  this.config = config;
2421
- this.specificationVersion = "v1";
3124
+ this.specificationVersion = "v2";
2422
3125
  }
2423
3126
  get provider() {
2424
3127
  return this.config.provider;
2425
3128
  }
2426
- getArgs({
3129
+ async getArgs({
2427
3130
  text,
2428
3131
  voice = "alloy",
2429
3132
  outputFormat = "mp3",
2430
3133
  speed,
2431
3134
  instructions,
3135
+ language,
2432
3136
  providerOptions
2433
3137
  }) {
2434
3138
  const warnings = [];
2435
- const openAIOptions = parseProviderOptions4({
3139
+ const openAIOptions = await parseProviderOptions7({
2436
3140
  provider: "openai",
2437
3141
  providerOptions,
2438
3142
  schema: OpenAIProviderOptionsSchema
@@ -2465,6 +3169,13 @@ var OpenAISpeechModel = class {
2465
3169
  }
2466
3170
  }
2467
3171
  }
3172
+ if (language) {
3173
+ warnings.push({
3174
+ type: "unsupported-setting",
3175
+ setting: "language",
3176
+ details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
3177
+ });
3178
+ }
2468
3179
  return {
2469
3180
  requestBody,
2470
3181
  warnings
@@ -2473,7 +3184,7 @@ var OpenAISpeechModel = class {
2473
3184
  async doGenerate(options) {
2474
3185
  var _a, _b, _c;
2475
3186
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2476
- const { requestBody, warnings } = this.getArgs(options);
3187
+ const { requestBody, warnings } = await this.getArgs(options);
2477
3188
  const {
2478
3189
  value: audio,
2479
3190
  responseHeaders,
@@ -2508,10 +3219,9 @@ var OpenAISpeechModel = class {
2508
3219
 
2509
3220
  // src/openai-provider.ts
2510
3221
  function createOpenAI(options = {}) {
2511
- var _a, _b, _c;
3222
+ var _a, _b;
2512
3223
  const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
2513
- const compatibility = (_b = options.compatibility) != null ? _b : "compatible";
2514
- const providerName = (_c = options.name) != null ? _c : "openai";
3224
+ const providerName = (_b = options.name) != null ? _b : "openai";
2515
3225
  const getHeaders = () => ({
2516
3226
  Authorization: `Bearer ${loadApiKey({
2517
3227
  apiKey: options.apiKey,
@@ -2522,27 +3232,25 @@ function createOpenAI(options = {}) {
2522
3232
  "OpenAI-Project": options.project,
2523
3233
  ...options.headers
2524
3234
  });
2525
- const createChatModel = (modelId, settings = {}) => new OpenAIChatLanguageModel(modelId, settings, {
3235
+ const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
2526
3236
  provider: `${providerName}.chat`,
2527
3237
  url: ({ path }) => `${baseURL}${path}`,
2528
3238
  headers: getHeaders,
2529
- compatibility,
2530
3239
  fetch: options.fetch
2531
3240
  });
2532
- const createCompletionModel = (modelId, settings = {}) => new OpenAICompletionLanguageModel(modelId, settings, {
3241
+ const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
2533
3242
  provider: `${providerName}.completion`,
2534
3243
  url: ({ path }) => `${baseURL}${path}`,
2535
3244
  headers: getHeaders,
2536
- compatibility,
2537
3245
  fetch: options.fetch
2538
3246
  });
2539
- const createEmbeddingModel = (modelId, settings = {}) => new OpenAIEmbeddingModel(modelId, settings, {
3247
+ const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
2540
3248
  provider: `${providerName}.embedding`,
2541
3249
  url: ({ path }) => `${baseURL}${path}`,
2542
3250
  headers: getHeaders,
2543
3251
  fetch: options.fetch
2544
3252
  });
2545
- const createImageModel = (modelId, settings = {}) => new OpenAIImageModel(modelId, settings, {
3253
+ const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
2546
3254
  provider: `${providerName}.image`,
2547
3255
  url: ({ path }) => `${baseURL}${path}`,
2548
3256
  headers: getHeaders,
@@ -2560,19 +3268,13 @@ function createOpenAI(options = {}) {
2560
3268
  headers: getHeaders,
2561
3269
  fetch: options.fetch
2562
3270
  });
2563
- const createLanguageModel = (modelId, settings) => {
3271
+ const createLanguageModel = (modelId) => {
2564
3272
  if (new.target) {
2565
3273
  throw new Error(
2566
3274
  "The OpenAI model function cannot be called with the new keyword."
2567
3275
  );
2568
3276
  }
2569
- if (modelId === "gpt-3.5-turbo-instruct") {
2570
- return createCompletionModel(
2571
- modelId,
2572
- settings
2573
- );
2574
- }
2575
- return createChatModel(modelId, settings);
3277
+ return createResponsesModel(modelId);
2576
3278
  };
2577
3279
  const createResponsesModel = (modelId) => {
2578
3280
  return new OpenAIResponsesLanguageModel(modelId, {
@@ -2582,8 +3284,8 @@ function createOpenAI(options = {}) {
2582
3284
  fetch: options.fetch
2583
3285
  });
2584
3286
  };
2585
- const provider = function(modelId, settings) {
2586
- return createLanguageModel(modelId, settings);
3287
+ const provider = function(modelId) {
3288
+ return createLanguageModel(modelId);
2587
3289
  };
2588
3290
  provider.languageModel = createLanguageModel;
2589
3291
  provider.chat = createChatModel;
@@ -2601,10 +3303,7 @@ function createOpenAI(options = {}) {
2601
3303
  provider.tools = openaiTools;
2602
3304
  return provider;
2603
3305
  }
2604
- var openai = createOpenAI({
2605
- compatibility: "strict"
2606
- // strict for OpenAI API
2607
- });
3306
+ var openai = createOpenAI();
2608
3307
  export {
2609
3308
  createOpenAI,
2610
3309
  openai