@ai-sdk/openai 1.3.21 → 1.3.23

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 1.3.23
4
+
5
+ ### Patch Changes
6
+
7
+ - c3f5106: fix (provider/openai): handle responses api errors
8
+
9
+ ## 1.3.22
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [d87b9d1]
14
+ - @ai-sdk/provider-utils@2.2.8
15
+
3
16
  ## 1.3.21
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AI SDK - OpenAI Provider
2
2
 
3
- The **[OpenAI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/openai)** for the [AI SDK](https://sdk.vercel.ai/docs)
3
+ The **[OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai)** for the [AI SDK](https://ai-sdk.dev/docs)
4
4
  contains language model support for the OpenAI chat and completion APIs and embedding model support for the OpenAI embeddings API.
5
5
 
6
6
  ## Setup
@@ -33,4 +33,4 @@ const { text } = await generateText({
33
33
 
34
34
  ## Documentation
35
35
 
36
- Please check out the **[OpenAI provider documentation](https://sdk.vercel.ai/providers/ai-sdk-providers/openai)** for more information.
36
+ Please check out the **[OpenAI provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/openai)** for more information.
package/dist/index.js CHANGED
@@ -1794,6 +1794,7 @@ var openaiTranscriptionResponseSchema = import_zod6.z.object({
1794
1794
  });
1795
1795
 
1796
1796
  // src/responses/openai-responses-language-model.ts
1797
+ var import_provider9 = require("@ai-sdk/provider");
1797
1798
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
1798
1799
  var import_zod7 = require("zod");
1799
1800
 
@@ -2206,15 +2207,16 @@ var OpenAIResponsesLanguageModel = class {
2206
2207
  async doGenerate(options) {
2207
2208
  var _a, _b, _c, _d, _e, _f, _g;
2208
2209
  const { args: body, warnings } = this.getArgs(options);
2210
+ const url = this.config.url({
2211
+ path: "/responses",
2212
+ modelId: this.modelId
2213
+ });
2209
2214
  const {
2210
2215
  responseHeaders,
2211
2216
  value: response,
2212
2217
  rawValue: rawResponse
2213
2218
  } = await (0, import_provider_utils9.postJsonToApi)({
2214
- url: this.config.url({
2215
- path: "/responses",
2216
- modelId: this.modelId
2217
- }),
2219
+ url,
2218
2220
  headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2219
2221
  body,
2220
2222
  failedResponseHandler: openaiFailedResponseHandler,
@@ -2222,6 +2224,10 @@ var OpenAIResponsesLanguageModel = class {
2222
2224
  import_zod7.z.object({
2223
2225
  id: import_zod7.z.string(),
2224
2226
  created_at: import_zod7.z.number(),
2227
+ error: import_zod7.z.object({
2228
+ message: import_zod7.z.string(),
2229
+ code: import_zod7.z.string()
2230
+ }).nullish(),
2225
2231
  model: import_zod7.z.string(),
2226
2232
  output: import_zod7.z.array(
2227
2233
  import_zod7.z.discriminatedUnion("type", [
@@ -2274,6 +2280,17 @@ var OpenAIResponsesLanguageModel = class {
2274
2280
  abortSignal: options.abortSignal,
2275
2281
  fetch: this.config.fetch
2276
2282
  });
2283
+ if (response.error) {
2284
+ throw new import_provider9.APICallError({
2285
+ message: response.error.message,
2286
+ url,
2287
+ requestBodyValues: body,
2288
+ statusCode: 400,
2289
+ responseHeaders,
2290
+ responseBody: rawResponse,
2291
+ isRetryable: false
2292
+ });
2293
+ }
2277
2294
  const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
2278
2295
  const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
2279
2296
  toolCallType: "function",
@@ -2445,6 +2462,8 @@ var OpenAIResponsesLanguageModel = class {
2445
2462
  title: value.annotation.title
2446
2463
  }
2447
2464
  });
2465
+ } else if (isErrorChunk(value)) {
2466
+ controller.enqueue({ type: "error", error: value });
2448
2467
  }
2449
2468
  },
2450
2469
  flush(controller) {
@@ -2554,6 +2573,13 @@ var responseReasoningSummaryTextDeltaSchema = import_zod7.z.object({
2554
2573
  summary_index: import_zod7.z.number(),
2555
2574
  delta: import_zod7.z.string()
2556
2575
  });
2576
+ var errorChunkSchema = import_zod7.z.object({
2577
+ type: import_zod7.z.literal("error"),
2578
+ code: import_zod7.z.string(),
2579
+ message: import_zod7.z.string(),
2580
+ param: import_zod7.z.string().nullish(),
2581
+ sequence_number: import_zod7.z.number()
2582
+ });
2557
2583
  var openaiResponsesChunkSchema = import_zod7.z.union([
2558
2584
  textDeltaChunkSchema,
2559
2585
  responseFinishedChunkSchema,
@@ -2563,6 +2589,7 @@ var openaiResponsesChunkSchema = import_zod7.z.union([
2563
2589
  responseOutputItemAddedSchema,
2564
2590
  responseAnnotationAddedSchema,
2565
2591
  responseReasoningSummaryTextDeltaSchema,
2592
+ errorChunkSchema,
2566
2593
  import_zod7.z.object({ type: import_zod7.z.string() }).passthrough()
2567
2594
  // fallback for unknown chunks
2568
2595
  ]);
@@ -2590,6 +2617,9 @@ function isResponseAnnotationAddedChunk(chunk) {
2590
2617
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2591
2618
  return chunk.type === "response.reasoning_summary_text.delta";
2592
2619
  }
2620
+ function isErrorChunk(chunk) {
2621
+ return chunk.type === "error";
2622
+ }
2593
2623
  function getResponsesModelConfig(modelId) {
2594
2624
  if (modelId.startsWith("o")) {
2595
2625
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {