@ai-sdk/openai 3.0.76 → 3.0.78

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
+ ## 3.0.78
4
+
5
+ ### Patch Changes
6
+
7
+ - 64a701d: Return a helpful error when the Responses stream parser receives Chat Completions chunks.
8
+
9
+ ## 3.0.77
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [b30e43a]
14
+ - @ai-sdk/provider-utils@4.0.33
15
+
3
16
  ## 3.0.76
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -5566,11 +5566,12 @@ var OpenAIResponsesLanguageModel = class {
5566
5566
  providerOptionsName,
5567
5567
  isShellProviderExecuted
5568
5568
  } = await this.getArgs(options);
5569
+ const url = this.config.url({
5570
+ path: "/responses",
5571
+ modelId: this.modelId
5572
+ });
5569
5573
  const { responseHeaders, value: response } = await (0, import_provider_utils30.postJsonToApi)({
5570
- url: this.config.url({
5571
- path: "/responses",
5572
- modelId: this.modelId
5573
- }),
5574
+ url,
5574
5575
  headers: (0, import_provider_utils30.combineHeaders)(this.config.headers(), options.headers),
5575
5576
  body: {
5576
5577
  ...body,
@@ -5612,8 +5613,15 @@ var OpenAIResponsesLanguageModel = class {
5612
5613
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
5613
5614
  }
5614
5615
  if (!chunk.success) {
5616
+ const error = isOpenAIChatCompletionChunk(chunk.rawValue) ? createOpenAIResponsesChatCompletionsMismatchError({
5617
+ value: chunk.rawValue,
5618
+ cause: chunk.error,
5619
+ url,
5620
+ requestBodyValues: body,
5621
+ responseHeaders
5622
+ }) : chunk.error;
5615
5623
  finishReason = { unified: "error", raw: void 0 };
5616
- controller.enqueue({ type: "error", error: chunk.error });
5624
+ controller.enqueue({ type: "error", error });
5617
5625
  return;
5618
5626
  }
5619
5627
  const value = chunk.value;
@@ -6440,6 +6448,31 @@ var OpenAIResponsesLanguageModel = class {
6440
6448
  function isTextDeltaChunk(chunk) {
6441
6449
  return chunk.type === "response.output_text.delta";
6442
6450
  }
6451
+ function isOpenAIChatCompletionChunk(value) {
6452
+ const chunk = asRecord(value);
6453
+ return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
6454
+ }
6455
+ function createOpenAIResponsesChatCompletionsMismatchError({
6456
+ value,
6457
+ cause,
6458
+ url,
6459
+ requestBodyValues,
6460
+ responseHeaders
6461
+ }) {
6462
+ return new import_provider8.APICallError({
6463
+ message: "Received a Chat Completions stream while using the OpenAI Responses API. The default OpenAI provider model uses the Responses API. If your custom baseURL targets a Chat Completions-compatible endpoint, use openai.chat('model-id') or createOpenAI(...).chat('model-id') instead. You can also use @ai-sdk/openai-compatible for OpenAI-compatible providers.",
6464
+ url,
6465
+ requestBodyValues,
6466
+ responseHeaders,
6467
+ responseBody: JSON.stringify(value),
6468
+ cause,
6469
+ data: value,
6470
+ isRetryable: false
6471
+ });
6472
+ }
6473
+ function asRecord(value) {
6474
+ return typeof value === "object" && value != null ? value : void 0;
6475
+ }
6443
6476
  function isResponseOutputItemDoneChunk(chunk) {
6444
6477
  return chunk.type === "response.output_item.done";
6445
6478
  }
@@ -6867,7 +6900,7 @@ var OpenAITranscriptionModel = class {
6867
6900
  };
6868
6901
 
6869
6902
  // src/version.ts
6870
- var VERSION = true ? "3.0.76" : "0.0.0-test";
6903
+ var VERSION = true ? "3.0.78" : "0.0.0-test";
6871
6904
 
6872
6905
  // src/openai-provider.ts
6873
6906
  function createOpenAI(options = {}) {