@ai-sdk/openai 2.0.0-beta.3 → 2.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/openai-provider.ts
29
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
29
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
30
30
 
31
31
  // src/openai-chat-language-model.ts
32
32
  var import_provider3 = require("@ai-sdk/provider");
@@ -1867,15 +1867,19 @@ var openaiTranscriptionResponseSchema = import_v412.z.object({
1867
1867
  });
1868
1868
 
1869
1869
  // src/responses/openai-responses-language-model.ts
1870
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
1871
- var import_v413 = require("zod/v4");
1870
+ var import_provider8 = require("@ai-sdk/provider");
1871
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1872
+ var import_v414 = require("zod/v4");
1872
1873
 
1873
1874
  // src/responses/convert-to-openai-responses-messages.ts
1874
1875
  var import_provider6 = require("@ai-sdk/provider");
1875
- function convertToOpenAIResponsesMessages({
1876
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1877
+ var import_v413 = require("zod/v4");
1878
+ async function convertToOpenAIResponsesMessages({
1876
1879
  prompt,
1877
1880
  systemMessageMode
1878
1881
  }) {
1882
+ var _a, _b;
1879
1883
  const messages = [];
1880
1884
  const warnings = [];
1881
1885
  for (const { role, content } of prompt) {
@@ -1910,7 +1914,7 @@ function convertToOpenAIResponsesMessages({
1910
1914
  messages.push({
1911
1915
  role: "user",
1912
1916
  content: content.map((part, index) => {
1913
- var _a, _b, _c;
1917
+ var _a2, _b2, _c;
1914
1918
  switch (part.type) {
1915
1919
  case "text": {
1916
1920
  return { type: "input_text", text: part.text };
@@ -1922,7 +1926,7 @@ function convertToOpenAIResponsesMessages({
1922
1926
  type: "input_image",
1923
1927
  image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
1924
1928
  // OpenAI specific extension: image detail
1925
- detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
1929
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
1926
1930
  };
1927
1931
  } else if (part.mediaType === "application/pdf") {
1928
1932
  if (part.data instanceof URL) {
@@ -1947,6 +1951,7 @@ function convertToOpenAIResponsesMessages({
1947
1951
  break;
1948
1952
  }
1949
1953
  case "assistant": {
1954
+ const reasoningMessages = {};
1950
1955
  for (const part of content) {
1951
1956
  switch (part.type) {
1952
1957
  case "text": {
@@ -1975,6 +1980,43 @@ function convertToOpenAIResponsesMessages({
1975
1980
  });
1976
1981
  break;
1977
1982
  }
1983
+ case "reasoning": {
1984
+ const providerOptions = await (0, import_provider_utils10.parseProviderOptions)({
1985
+ provider: "openai",
1986
+ providerOptions: part.providerOptions,
1987
+ schema: openaiResponsesReasoningProviderOptionsSchema
1988
+ });
1989
+ const reasoningId = (_a = providerOptions == null ? void 0 : providerOptions.reasoning) == null ? void 0 : _a.id;
1990
+ if (reasoningId != null) {
1991
+ const existingReasoningMessage = reasoningMessages[reasoningId];
1992
+ const summaryParts = [];
1993
+ if (part.text.length > 0) {
1994
+ summaryParts.push({ type: "summary_text", text: part.text });
1995
+ } else if (existingReasoningMessage !== void 0) {
1996
+ warnings.push({
1997
+ type: "other",
1998
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
1999
+ });
2000
+ }
2001
+ if (existingReasoningMessage === void 0) {
2002
+ reasoningMessages[reasoningId] = {
2003
+ type: "reasoning",
2004
+ id: reasoningId,
2005
+ encrypted_content: (_b = providerOptions == null ? void 0 : providerOptions.reasoning) == null ? void 0 : _b.encryptedContent,
2006
+ summary: summaryParts
2007
+ };
2008
+ messages.push(reasoningMessages[reasoningId]);
2009
+ } else {
2010
+ existingReasoningMessage.summary.push(...summaryParts);
2011
+ }
2012
+ } else {
2013
+ warnings.push({
2014
+ type: "other",
2015
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
2016
+ });
2017
+ }
2018
+ break;
2019
+ }
1978
2020
  }
1979
2021
  }
1980
2022
  break;
@@ -2010,6 +2052,12 @@ function convertToOpenAIResponsesMessages({
2010
2052
  }
2011
2053
  return { messages, warnings };
2012
2054
  }
2055
+ var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
2056
+ reasoning: import_v413.z.object({
2057
+ id: import_v413.z.string().nullish(),
2058
+ encryptedContent: import_v413.z.string().nullish()
2059
+ }).nullish()
2060
+ });
2013
2061
 
2014
2062
  // src/responses/map-openai-responses-finish-reason.ts
2015
2063
  function mapOpenAIResponseFinishReason({
@@ -2148,12 +2196,12 @@ var OpenAIResponsesLanguageModel = class {
2148
2196
  if (stopSequences != null) {
2149
2197
  warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
2150
2198
  }
2151
- const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
2199
+ const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2152
2200
  prompt,
2153
2201
  systemMessageMode: modelConfig.systemMessageMode
2154
2202
  });
2155
2203
  warnings.push(...messageWarnings);
2156
- const openaiOptions = await (0, import_provider_utils10.parseProviderOptions)({
2204
+ const openaiOptions = await (0, import_provider_utils11.parseProviderOptions)({
2157
2205
  provider: "openai",
2158
2206
  providerOptions,
2159
2207
  schema: openaiResponsesProviderOptionsSchema
@@ -2184,6 +2232,7 @@ var OpenAIResponsesLanguageModel = class {
2184
2232
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2185
2233
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2186
2234
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2235
+ include: openaiOptions == null ? void 0 : openaiOptions.include,
2187
2236
  // model-specific settings:
2188
2237
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2189
2238
  reasoning: {
@@ -2216,6 +2265,21 @@ var OpenAIResponsesLanguageModel = class {
2216
2265
  details: "topP is not supported for reasoning models"
2217
2266
  });
2218
2267
  }
2268
+ } else {
2269
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
2270
+ warnings.push({
2271
+ type: "unsupported-setting",
2272
+ setting: "reasoningEffort",
2273
+ details: "reasoningEffort is not supported for non-reasoning models"
2274
+ });
2275
+ }
2276
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
2277
+ warnings.push({
2278
+ type: "unsupported-setting",
2279
+ setting: "reasoningSummary",
2280
+ details: "reasoningSummary is not supported for non-reasoning models"
2281
+ });
2282
+ }
2219
2283
  }
2220
2284
  if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2221
2285
  warnings.push({
@@ -2244,88 +2308,119 @@ var OpenAIResponsesLanguageModel = class {
2244
2308
  };
2245
2309
  }
2246
2310
  async doGenerate(options) {
2247
- var _a, _b, _c, _d, _e, _f, _g, _h;
2311
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2248
2312
  const { args: body, warnings } = await this.getArgs(options);
2313
+ const url = this.config.url({
2314
+ path: "/responses",
2315
+ modelId: this.modelId
2316
+ });
2249
2317
  const {
2250
2318
  responseHeaders,
2251
2319
  value: response,
2252
2320
  rawValue: rawResponse
2253
- } = await (0, import_provider_utils10.postJsonToApi)({
2254
- url: this.config.url({
2255
- path: "/responses",
2256
- modelId: this.modelId
2257
- }),
2258
- headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
2321
+ } = await (0, import_provider_utils11.postJsonToApi)({
2322
+ url,
2323
+ headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
2259
2324
  body,
2260
2325
  failedResponseHandler: openaiFailedResponseHandler,
2261
- successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
2262
- import_v413.z.object({
2263
- id: import_v413.z.string(),
2264
- created_at: import_v413.z.number(),
2265
- model: import_v413.z.string(),
2266
- output: import_v413.z.array(
2267
- import_v413.z.discriminatedUnion("type", [
2268
- import_v413.z.object({
2269
- type: import_v413.z.literal("message"),
2270
- role: import_v413.z.literal("assistant"),
2271
- content: import_v413.z.array(
2272
- import_v413.z.object({
2273
- type: import_v413.z.literal("output_text"),
2274
- text: import_v413.z.string(),
2275
- annotations: import_v413.z.array(
2276
- import_v413.z.object({
2277
- type: import_v413.z.literal("url_citation"),
2278
- start_index: import_v413.z.number(),
2279
- end_index: import_v413.z.number(),
2280
- url: import_v413.z.string(),
2281
- title: import_v413.z.string()
2326
+ successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
2327
+ import_v414.z.object({
2328
+ id: import_v414.z.string(),
2329
+ created_at: import_v414.z.number(),
2330
+ error: import_v414.z.object({
2331
+ code: import_v414.z.string(),
2332
+ message: import_v414.z.string()
2333
+ }).nullish(),
2334
+ model: import_v414.z.string(),
2335
+ output: import_v414.z.array(
2336
+ import_v414.z.discriminatedUnion("type", [
2337
+ import_v414.z.object({
2338
+ type: import_v414.z.literal("message"),
2339
+ role: import_v414.z.literal("assistant"),
2340
+ content: import_v414.z.array(
2341
+ import_v414.z.object({
2342
+ type: import_v414.z.literal("output_text"),
2343
+ text: import_v414.z.string(),
2344
+ annotations: import_v414.z.array(
2345
+ import_v414.z.object({
2346
+ type: import_v414.z.literal("url_citation"),
2347
+ start_index: import_v414.z.number(),
2348
+ end_index: import_v414.z.number(),
2349
+ url: import_v414.z.string(),
2350
+ title: import_v414.z.string()
2282
2351
  })
2283
2352
  )
2284
2353
  })
2285
2354
  )
2286
2355
  }),
2287
- import_v413.z.object({
2288
- type: import_v413.z.literal("function_call"),
2289
- call_id: import_v413.z.string(),
2290
- name: import_v413.z.string(),
2291
- arguments: import_v413.z.string()
2356
+ import_v414.z.object({
2357
+ type: import_v414.z.literal("function_call"),
2358
+ call_id: import_v414.z.string(),
2359
+ name: import_v414.z.string(),
2360
+ arguments: import_v414.z.string()
2292
2361
  }),
2293
- import_v413.z.object({
2294
- type: import_v413.z.literal("web_search_call"),
2295
- id: import_v413.z.string(),
2296
- status: import_v413.z.string().optional()
2362
+ import_v414.z.object({
2363
+ type: import_v414.z.literal("web_search_call"),
2364
+ id: import_v414.z.string(),
2365
+ status: import_v414.z.string().optional()
2297
2366
  }),
2298
- import_v413.z.object({
2299
- type: import_v413.z.literal("computer_call"),
2300
- id: import_v413.z.string(),
2301
- status: import_v413.z.string().optional()
2367
+ import_v414.z.object({
2368
+ type: import_v414.z.literal("computer_call"),
2369
+ id: import_v414.z.string(),
2370
+ status: import_v414.z.string().optional()
2302
2371
  }),
2303
- import_v413.z.object({
2304
- type: import_v413.z.literal("reasoning"),
2305
- summary: import_v413.z.array(
2306
- import_v413.z.object({
2307
- type: import_v413.z.literal("summary_text"),
2308
- text: import_v413.z.string()
2372
+ import_v414.z.object({
2373
+ type: import_v414.z.literal("reasoning"),
2374
+ id: import_v414.z.string(),
2375
+ encrypted_content: import_v414.z.string().nullish(),
2376
+ summary: import_v414.z.array(
2377
+ import_v414.z.object({
2378
+ type: import_v414.z.literal("summary_text"),
2379
+ text: import_v414.z.string()
2309
2380
  })
2310
2381
  )
2311
2382
  })
2312
2383
  ])
2313
2384
  ),
2314
- incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullable(),
2385
+ incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullable(),
2315
2386
  usage: usageSchema2
2316
2387
  })
2317
2388
  ),
2318
2389
  abortSignal: options.abortSignal,
2319
2390
  fetch: this.config.fetch
2320
2391
  });
2392
+ if (response.error) {
2393
+ throw new import_provider8.APICallError({
2394
+ message: response.error.message,
2395
+ url,
2396
+ requestBodyValues: body,
2397
+ statusCode: 400,
2398
+ responseHeaders,
2399
+ responseBody: rawResponse,
2400
+ isRetryable: false
2401
+ });
2402
+ }
2321
2403
  const content = [];
2322
2404
  for (const part of response.output) {
2323
2405
  switch (part.type) {
2324
2406
  case "reasoning": {
2325
- content.push({
2326
- type: "reasoning",
2327
- text: part.summary.map((summary) => summary.text).join()
2328
- });
2407
+ if (part.summary.length === 0) {
2408
+ part.summary.push({ type: "summary_text", text: "" });
2409
+ }
2410
+ for (const summary of part.summary) {
2411
+ content.push({
2412
+ type: "reasoning",
2413
+ text: summary.text,
2414
+ providerMetadata: {
2415
+ openai: {
2416
+ reasoning: {
2417
+ id: part.id,
2418
+ encryptedContent: (_a = part.encrypted_content) != null ? _a : null
2419
+ }
2420
+ }
2421
+ }
2422
+ });
2423
+ }
2329
2424
  break;
2330
2425
  }
2331
2426
  case "message": {
@@ -2338,7 +2433,7 @@ var OpenAIResponsesLanguageModel = class {
2338
2433
  content.push({
2339
2434
  type: "source",
2340
2435
  sourceType: "url",
2341
- id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils10.generateId)(),
2436
+ id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : (0, import_provider_utils11.generateId)(),
2342
2437
  url: annotation.url,
2343
2438
  title: annotation.title
2344
2439
  });
@@ -2397,15 +2492,15 @@ var OpenAIResponsesLanguageModel = class {
2397
2492
  return {
2398
2493
  content,
2399
2494
  finishReason: mapOpenAIResponseFinishReason({
2400
- finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
2495
+ finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
2401
2496
  hasToolCalls: content.some((part) => part.type === "tool-call")
2402
2497
  }),
2403
2498
  usage: {
2404
2499
  inputTokens: response.usage.input_tokens,
2405
2500
  outputTokens: response.usage.output_tokens,
2406
2501
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2407
- reasoningTokens: (_f = (_e = response.usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0,
2408
- cachedInputTokens: (_h = (_g = response.usage.input_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : void 0
2502
+ reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
2503
+ cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
2409
2504
  },
2410
2505
  request: { body },
2411
2506
  response: {
@@ -2425,18 +2520,18 @@ var OpenAIResponsesLanguageModel = class {
2425
2520
  }
2426
2521
  async doStream(options) {
2427
2522
  const { args: body, warnings } = await this.getArgs(options);
2428
- const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
2523
+ const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
2429
2524
  url: this.config.url({
2430
2525
  path: "/responses",
2431
2526
  modelId: this.modelId
2432
2527
  }),
2433
- headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
2528
+ headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
2434
2529
  body: {
2435
2530
  ...body,
2436
2531
  stream: true
2437
2532
  },
2438
2533
  failedResponseHandler: openaiFailedResponseHandler,
2439
- successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
2534
+ successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
2440
2535
  openaiResponsesChunkSchema
2441
2536
  ),
2442
2537
  abortSignal: options.abortSignal,
@@ -2459,7 +2554,7 @@ var OpenAIResponsesLanguageModel = class {
2459
2554
  controller.enqueue({ type: "stream-start", warnings });
2460
2555
  },
2461
2556
  transform(chunk, controller) {
2462
- var _a, _b, _c, _d, _e, _f, _g, _h;
2557
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2463
2558
  if (options.includeRawChunks) {
2464
2559
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2465
2560
  }
@@ -2508,7 +2603,15 @@ var OpenAIResponsesLanguageModel = class {
2508
2603
  } else if (value.item.type === "reasoning") {
2509
2604
  controller.enqueue({
2510
2605
  type: "reasoning-start",
2511
- id: value.item.id
2606
+ id: value.item.id,
2607
+ providerMetadata: {
2608
+ openai: {
2609
+ reasoning: {
2610
+ id: value.item.id,
2611
+ encryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
2612
+ }
2613
+ }
2614
+ }
2512
2615
  });
2513
2616
  }
2514
2617
  } else if (isResponseOutputItemDoneChunk(value)) {
@@ -2581,7 +2684,15 @@ var OpenAIResponsesLanguageModel = class {
2581
2684
  } else if (value.item.type === "reasoning") {
2582
2685
  controller.enqueue({
2583
2686
  type: "reasoning-end",
2584
- id: value.item.id
2687
+ id: value.item.id,
2688
+ providerMetadata: {
2689
+ openai: {
2690
+ reasoning: {
2691
+ id: value.item.id,
2692
+ encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2693
+ }
2694
+ }
2695
+ }
2585
2696
  });
2586
2697
  }
2587
2698
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
@@ -2610,27 +2721,29 @@ var OpenAIResponsesLanguageModel = class {
2610
2721
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2611
2722
  controller.enqueue({
2612
2723
  type: "reasoning-delta",
2613
- delta: value.delta,
2614
- id: value.item_id
2724
+ id: value.item_id,
2725
+ delta: value.delta
2615
2726
  });
2616
2727
  } else if (isResponseFinishedChunk(value)) {
2617
2728
  finishReason = mapOpenAIResponseFinishReason({
2618
- finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
2729
+ finishReason: (_c = value.response.incomplete_details) == null ? void 0 : _c.reason,
2619
2730
  hasToolCalls
2620
2731
  });
2621
2732
  usage.inputTokens = value.response.usage.input_tokens;
2622
2733
  usage.outputTokens = value.response.usage.output_tokens;
2623
2734
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2624
- usage.reasoningTokens = (_c = (_b = value.response.usage.output_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : void 0;
2625
- usage.cachedInputTokens = (_e = (_d = value.response.usage.input_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : void 0;
2735
+ usage.reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
2736
+ usage.cachedInputTokens = (_g = (_f = value.response.usage.input_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
2626
2737
  } else if (isResponseAnnotationAddedChunk(value)) {
2627
2738
  controller.enqueue({
2628
2739
  type: "source",
2629
2740
  sourceType: "url",
2630
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
2741
+ id: (_j = (_i = (_h = self.config).generateId) == null ? void 0 : _i.call(_h)) != null ? _j : (0, import_provider_utils11.generateId)(),
2631
2742
  url: value.annotation.url,
2632
2743
  title: value.annotation.title
2633
2744
  });
2745
+ } else if (isErrorChunk(value)) {
2746
+ controller.enqueue({ type: "error", error: value });
2634
2747
  }
2635
2748
  },
2636
2749
  flush(controller) {
@@ -2652,124 +2765,136 @@ var OpenAIResponsesLanguageModel = class {
2652
2765
  };
2653
2766
  }
2654
2767
  };
2655
- var usageSchema2 = import_v413.z.object({
2656
- input_tokens: import_v413.z.number(),
2657
- input_tokens_details: import_v413.z.object({ cached_tokens: import_v413.z.number().nullish() }).nullish(),
2658
- output_tokens: import_v413.z.number(),
2659
- output_tokens_details: import_v413.z.object({ reasoning_tokens: import_v413.z.number().nullish() }).nullish()
2768
+ var usageSchema2 = import_v414.z.object({
2769
+ input_tokens: import_v414.z.number(),
2770
+ input_tokens_details: import_v414.z.object({ cached_tokens: import_v414.z.number().nullish() }).nullish(),
2771
+ output_tokens: import_v414.z.number(),
2772
+ output_tokens_details: import_v414.z.object({ reasoning_tokens: import_v414.z.number().nullish() }).nullish()
2773
+ });
2774
+ var textDeltaChunkSchema = import_v414.z.object({
2775
+ type: import_v414.z.literal("response.output_text.delta"),
2776
+ item_id: import_v414.z.string(),
2777
+ delta: import_v414.z.string()
2660
2778
  });
2661
- var textDeltaChunkSchema = import_v413.z.object({
2662
- type: import_v413.z.literal("response.output_text.delta"),
2663
- item_id: import_v413.z.string(),
2664
- delta: import_v413.z.string()
2779
+ var errorChunkSchema = import_v414.z.object({
2780
+ type: import_v414.z.literal("error"),
2781
+ code: import_v414.z.string(),
2782
+ message: import_v414.z.string(),
2783
+ param: import_v414.z.string().nullish(),
2784
+ sequence_number: import_v414.z.number()
2665
2785
  });
2666
- var responseFinishedChunkSchema = import_v413.z.object({
2667
- type: import_v413.z.enum(["response.completed", "response.incomplete"]),
2668
- response: import_v413.z.object({
2669
- incomplete_details: import_v413.z.object({ reason: import_v413.z.string() }).nullish(),
2786
+ var responseFinishedChunkSchema = import_v414.z.object({
2787
+ type: import_v414.z.enum(["response.completed", "response.incomplete"]),
2788
+ response: import_v414.z.object({
2789
+ incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullish(),
2670
2790
  usage: usageSchema2
2671
2791
  })
2672
2792
  });
2673
- var responseCreatedChunkSchema = import_v413.z.object({
2674
- type: import_v413.z.literal("response.created"),
2675
- response: import_v413.z.object({
2676
- id: import_v413.z.string(),
2677
- created_at: import_v413.z.number(),
2678
- model: import_v413.z.string()
2793
+ var responseCreatedChunkSchema = import_v414.z.object({
2794
+ type: import_v414.z.literal("response.created"),
2795
+ response: import_v414.z.object({
2796
+ id: import_v414.z.string(),
2797
+ created_at: import_v414.z.number(),
2798
+ model: import_v414.z.string()
2679
2799
  })
2680
2800
  });
2681
- var responseOutputItemAddedSchema = import_v413.z.object({
2682
- type: import_v413.z.literal("response.output_item.added"),
2683
- output_index: import_v413.z.number(),
2684
- item: import_v413.z.discriminatedUnion("type", [
2685
- import_v413.z.object({
2686
- type: import_v413.z.literal("message"),
2687
- id: import_v413.z.string()
2801
+ var responseOutputItemAddedSchema = import_v414.z.object({
2802
+ type: import_v414.z.literal("response.output_item.added"),
2803
+ output_index: import_v414.z.number(),
2804
+ item: import_v414.z.discriminatedUnion("type", [
2805
+ import_v414.z.object({
2806
+ type: import_v414.z.literal("message"),
2807
+ id: import_v414.z.string()
2688
2808
  }),
2689
- import_v413.z.object({
2690
- type: import_v413.z.literal("reasoning"),
2691
- id: import_v413.z.string()
2809
+ import_v414.z.object({
2810
+ type: import_v414.z.literal("reasoning"),
2811
+ id: import_v414.z.string(),
2812
+ encrypted_content: import_v414.z.string().nullish(),
2813
+ summary: import_v414.z.array(
2814
+ import_v414.z.object({
2815
+ type: import_v414.z.literal("summary_text"),
2816
+ text: import_v414.z.string()
2817
+ })
2818
+ )
2692
2819
  }),
2693
- import_v413.z.object({
2694
- type: import_v413.z.literal("function_call"),
2695
- id: import_v413.z.string(),
2696
- call_id: import_v413.z.string(),
2697
- name: import_v413.z.string(),
2698
- arguments: import_v413.z.string()
2820
+ import_v414.z.object({
2821
+ type: import_v414.z.literal("function_call"),
2822
+ id: import_v414.z.string(),
2823
+ call_id: import_v414.z.string(),
2824
+ name: import_v414.z.string(),
2825
+ arguments: import_v414.z.string()
2699
2826
  }),
2700
- import_v413.z.object({
2701
- type: import_v413.z.literal("web_search_call"),
2702
- id: import_v413.z.string(),
2703
- status: import_v413.z.string()
2827
+ import_v414.z.object({
2828
+ type: import_v414.z.literal("web_search_call"),
2829
+ id: import_v414.z.string(),
2830
+ status: import_v414.z.string()
2704
2831
  }),
2705
- import_v413.z.object({
2706
- type: import_v413.z.literal("computer_call"),
2707
- id: import_v413.z.string(),
2708
- status: import_v413.z.string()
2832
+ import_v414.z.object({
2833
+ type: import_v414.z.literal("computer_call"),
2834
+ id: import_v414.z.string(),
2835
+ status: import_v414.z.string()
2709
2836
  })
2710
2837
  ])
2711
2838
  });
2712
- var responseOutputItemDoneSchema = import_v413.z.object({
2713
- type: import_v413.z.literal("response.output_item.done"),
2714
- output_index: import_v413.z.number(),
2715
- item: import_v413.z.discriminatedUnion("type", [
2716
- import_v413.z.object({
2717
- type: import_v413.z.literal("message"),
2718
- id: import_v413.z.string()
2839
+ var responseOutputItemDoneSchema = import_v414.z.object({
2840
+ type: import_v414.z.literal("response.output_item.done"),
2841
+ output_index: import_v414.z.number(),
2842
+ item: import_v414.z.discriminatedUnion("type", [
2843
+ import_v414.z.object({
2844
+ type: import_v414.z.literal("message"),
2845
+ id: import_v414.z.string()
2719
2846
  }),
2720
- import_v413.z.object({
2721
- type: import_v413.z.literal("reasoning"),
2722
- id: import_v413.z.string()
2847
+ import_v414.z.object({
2848
+ type: import_v414.z.literal("reasoning"),
2849
+ id: import_v414.z.string(),
2850
+ encrypted_content: import_v414.z.string().nullish(),
2851
+ summary: import_v414.z.array(
2852
+ import_v414.z.object({
2853
+ type: import_v414.z.literal("summary_text"),
2854
+ text: import_v414.z.string()
2855
+ })
2856
+ )
2723
2857
  }),
2724
- import_v413.z.object({
2725
- type: import_v413.z.literal("function_call"),
2726
- id: import_v413.z.string(),
2727
- call_id: import_v413.z.string(),
2728
- name: import_v413.z.string(),
2729
- arguments: import_v413.z.string(),
2730
- status: import_v413.z.literal("completed")
2858
+ import_v414.z.object({
2859
+ type: import_v414.z.literal("function_call"),
2860
+ id: import_v414.z.string(),
2861
+ call_id: import_v414.z.string(),
2862
+ name: import_v414.z.string(),
2863
+ arguments: import_v414.z.string(),
2864
+ status: import_v414.z.literal("completed")
2731
2865
  }),
2732
- import_v413.z.object({
2733
- type: import_v413.z.literal("web_search_call"),
2734
- id: import_v413.z.string(),
2735
- status: import_v413.z.literal("completed")
2866
+ import_v414.z.object({
2867
+ type: import_v414.z.literal("web_search_call"),
2868
+ id: import_v414.z.string(),
2869
+ status: import_v414.z.literal("completed")
2736
2870
  }),
2737
- import_v413.z.object({
2738
- type: import_v413.z.literal("computer_call"),
2739
- id: import_v413.z.string(),
2740
- status: import_v413.z.literal("completed")
2871
+ import_v414.z.object({
2872
+ type: import_v414.z.literal("computer_call"),
2873
+ id: import_v414.z.string(),
2874
+ status: import_v414.z.literal("completed")
2741
2875
  })
2742
2876
  ])
2743
2877
  });
2744
- var responseFunctionCallArgumentsDeltaSchema = import_v413.z.object({
2745
- type: import_v413.z.literal("response.function_call_arguments.delta"),
2746
- item_id: import_v413.z.string(),
2747
- output_index: import_v413.z.number(),
2748
- delta: import_v413.z.string()
2878
+ var responseFunctionCallArgumentsDeltaSchema = import_v414.z.object({
2879
+ type: import_v414.z.literal("response.function_call_arguments.delta"),
2880
+ item_id: import_v414.z.string(),
2881
+ output_index: import_v414.z.number(),
2882
+ delta: import_v414.z.string()
2749
2883
  });
2750
- var responseAnnotationAddedSchema = import_v413.z.object({
2751
- type: import_v413.z.literal("response.output_text.annotation.added"),
2752
- annotation: import_v413.z.object({
2753
- type: import_v413.z.literal("url_citation"),
2754
- url: import_v413.z.string(),
2755
- title: import_v413.z.string()
2884
+ var responseAnnotationAddedSchema = import_v414.z.object({
2885
+ type: import_v414.z.literal("response.output_text.annotation.added"),
2886
+ annotation: import_v414.z.object({
2887
+ type: import_v414.z.literal("url_citation"),
2888
+ url: import_v414.z.string(),
2889
+ title: import_v414.z.string()
2756
2890
  })
2757
2891
  });
2758
- var responseReasoningSummaryTextDeltaSchema = import_v413.z.object({
2759
- type: import_v413.z.literal("response.reasoning_summary_text.delta"),
2760
- item_id: import_v413.z.string(),
2761
- output_index: import_v413.z.number(),
2762
- summary_index: import_v413.z.number(),
2763
- delta: import_v413.z.string()
2892
+ var responseReasoningSummaryTextDeltaSchema = import_v414.z.object({
2893
+ type: import_v414.z.literal("response.reasoning_summary_text.delta"),
2894
+ item_id: import_v414.z.string(),
2895
+ delta: import_v414.z.string()
2764
2896
  });
2765
- var responseReasoningSummaryPartDoneSchema = import_v413.z.object({
2766
- type: import_v413.z.literal("response.reasoning_summary_part.done"),
2767
- item_id: import_v413.z.string(),
2768
- output_index: import_v413.z.number(),
2769
- summary_index: import_v413.z.number(),
2770
- part: import_v413.z.unknown().nullish()
2771
- });
2772
- var openaiResponsesChunkSchema = import_v413.z.union([
2897
+ var openaiResponsesChunkSchema = import_v414.z.union([
2773
2898
  textDeltaChunkSchema,
2774
2899
  responseFinishedChunkSchema,
2775
2900
  responseCreatedChunkSchema,
@@ -2778,8 +2903,8 @@ var openaiResponsesChunkSchema = import_v413.z.union([
2778
2903
  responseFunctionCallArgumentsDeltaSchema,
2779
2904
  responseAnnotationAddedSchema,
2780
2905
  responseReasoningSummaryTextDeltaSchema,
2781
- responseReasoningSummaryPartDoneSchema,
2782
- import_v413.z.object({ type: import_v413.z.string() }).passthrough()
2906
+ errorChunkSchema,
2907
+ import_v414.z.object({ type: import_v414.z.string() }).loose()
2783
2908
  // fallback for unknown chunks
2784
2909
  ]);
2785
2910
  function isTextDeltaChunk(chunk) {
@@ -2806,8 +2931,11 @@ function isResponseAnnotationAddedChunk(chunk) {
2806
2931
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2807
2932
  return chunk.type === "response.reasoning_summary_text.delta";
2808
2933
  }
2934
+ function isErrorChunk(chunk) {
2935
+ return chunk.type === "error";
2936
+ }
2809
2937
  function getResponsesModelConfig(modelId) {
2810
- if (modelId.startsWith("o")) {
2938
+ if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
2811
2939
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
2812
2940
  return {
2813
2941
  isReasoningModel: true,
@@ -2830,25 +2958,26 @@ function getResponsesModelConfig(modelId) {
2830
2958
  function supportsFlexProcessing2(modelId) {
2831
2959
  return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
2832
2960
  }
2833
- var openaiResponsesProviderOptionsSchema = import_v413.z.object({
2834
- metadata: import_v413.z.any().nullish(),
2835
- parallelToolCalls: import_v413.z.boolean().nullish(),
2836
- previousResponseId: import_v413.z.string().nullish(),
2837
- store: import_v413.z.boolean().nullish(),
2838
- user: import_v413.z.string().nullish(),
2839
- reasoningEffort: import_v413.z.string().nullish(),
2840
- strictJsonSchema: import_v413.z.boolean().nullish(),
2841
- instructions: import_v413.z.string().nullish(),
2842
- reasoningSummary: import_v413.z.string().nullish(),
2843
- serviceTier: import_v413.z.enum(["auto", "flex"]).nullish()
2961
+ var openaiResponsesProviderOptionsSchema = import_v414.z.object({
2962
+ metadata: import_v414.z.any().nullish(),
2963
+ parallelToolCalls: import_v414.z.boolean().nullish(),
2964
+ previousResponseId: import_v414.z.string().nullish(),
2965
+ store: import_v414.z.boolean().nullish(),
2966
+ user: import_v414.z.string().nullish(),
2967
+ reasoningEffort: import_v414.z.string().nullish(),
2968
+ strictJsonSchema: import_v414.z.boolean().nullish(),
2969
+ instructions: import_v414.z.string().nullish(),
2970
+ reasoningSummary: import_v414.z.string().nullish(),
2971
+ serviceTier: import_v414.z.enum(["auto", "flex"]).nullish(),
2972
+ include: import_v414.z.array(import_v414.z.enum(["reasoning.encrypted_content"])).nullish()
2844
2973
  });
2845
2974
 
2846
2975
  // src/openai-speech-model.ts
2847
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
2848
- var import_v414 = require("zod/v4");
2849
- var OpenAIProviderOptionsSchema = import_v414.z.object({
2850
- instructions: import_v414.z.string().nullish(),
2851
- speed: import_v414.z.number().min(0.25).max(4).default(1).nullish()
2976
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2977
+ var import_v415 = require("zod/v4");
2978
+ var OpenAIProviderOptionsSchema = import_v415.z.object({
2979
+ instructions: import_v415.z.string().nullish(),
2980
+ speed: import_v415.z.number().min(0.25).max(4).default(1).nullish()
2852
2981
  });
2853
2982
  var OpenAISpeechModel = class {
2854
2983
  constructor(modelId, config) {
@@ -2869,7 +2998,7 @@ var OpenAISpeechModel = class {
2869
2998
  providerOptions
2870
2999
  }) {
2871
3000
  const warnings = [];
2872
- const openAIOptions = await (0, import_provider_utils11.parseProviderOptions)({
3001
+ const openAIOptions = await (0, import_provider_utils12.parseProviderOptions)({
2873
3002
  provider: "openai",
2874
3003
  providerOptions,
2875
3004
  schema: OpenAIProviderOptionsSchema
@@ -2922,15 +3051,15 @@ var OpenAISpeechModel = class {
2922
3051
  value: audio,
2923
3052
  responseHeaders,
2924
3053
  rawValue: rawResponse
2925
- } = await (0, import_provider_utils11.postJsonToApi)({
3054
+ } = await (0, import_provider_utils12.postJsonToApi)({
2926
3055
  url: this.config.url({
2927
3056
  path: "/audio/speech",
2928
3057
  modelId: this.modelId
2929
3058
  }),
2930
- headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
3059
+ headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
2931
3060
  body: requestBody,
2932
3061
  failedResponseHandler: openaiFailedResponseHandler,
2933
- successfulResponseHandler: (0, import_provider_utils11.createBinaryResponseHandler)(),
3062
+ successfulResponseHandler: (0, import_provider_utils12.createBinaryResponseHandler)(),
2934
3063
  abortSignal: options.abortSignal,
2935
3064
  fetch: this.config.fetch
2936
3065
  });
@@ -2953,10 +3082,10 @@ var OpenAISpeechModel = class {
2953
3082
  // src/openai-provider.ts
2954
3083
  function createOpenAI(options = {}) {
2955
3084
  var _a, _b;
2956
- const baseURL = (_a = (0, import_provider_utils12.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
3085
+ const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
2957
3086
  const providerName = (_b = options.name) != null ? _b : "openai";
2958
3087
  const getHeaders = () => ({
2959
- Authorization: `Bearer ${(0, import_provider_utils12.loadApiKey)({
3088
+ Authorization: `Bearer ${(0, import_provider_utils13.loadApiKey)({
2960
3089
  apiKey: options.apiKey,
2961
3090
  environmentVariableName: "OPENAI_API_KEY",
2962
3091
  description: "OpenAI"