@ai-sdk/openai 2.0.74 → 2.0.76

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,17 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.76
4
+
5
+ ### Patch Changes
6
+
7
+ - 61545c4: feat (provider/openai): include more image generation response metadata
8
+
9
+ ## 2.0.75
10
+
11
+ ### Patch Changes
12
+
13
+ - 1c7ff4a: distinguish between OpenAI and Azure in Responses API providerMetadata
14
+
3
15
  ## 2.0.74
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1652,12 +1652,26 @@ var import_v48 = require("zod/v4");
1652
1652
  var openaiImageResponseSchema = (0, import_provider_utils12.lazyValidator)(
1653
1653
  () => (0, import_provider_utils12.zodSchema)(
1654
1654
  import_v48.z.object({
1655
+ created: import_v48.z.number().nullish(),
1655
1656
  data: import_v48.z.array(
1656
1657
  import_v48.z.object({
1657
1658
  b64_json: import_v48.z.string(),
1658
1659
  revised_prompt: import_v48.z.string().nullish()
1659
1660
  })
1660
- )
1661
+ ),
1662
+ background: import_v48.z.string().nullish(),
1663
+ output_format: import_v48.z.string().nullish(),
1664
+ size: import_v48.z.string().nullish(),
1665
+ quality: import_v48.z.string().nullish(),
1666
+ usage: import_v48.z.object({
1667
+ input_tokens: import_v48.z.number().nullish(),
1668
+ output_tokens: import_v48.z.number().nullish(),
1669
+ total_tokens: import_v48.z.number().nullish(),
1670
+ input_tokens_details: import_v48.z.object({
1671
+ image_tokens: import_v48.z.number().nullish(),
1672
+ text_tokens: import_v48.z.number().nullish()
1673
+ }).nullish()
1674
+ }).nullish()
1661
1675
  })
1662
1676
  )
1663
1677
  );
@@ -1742,11 +1756,14 @@ var OpenAIImageModel = class {
1742
1756
  },
1743
1757
  providerMetadata: {
1744
1758
  openai: {
1745
- images: response.data.map(
1746
- (item) => item.revised_prompt ? {
1747
- revisedPrompt: item.revised_prompt
1748
- } : null
1749
- )
1759
+ images: response.data.map((item) => ({
1760
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1761
+ ...response.created != null ? { created: response.created } : {},
1762
+ ...response.size != null ? { size: response.size } : {},
1763
+ ...response.quality != null ? { quality: response.quality } : {},
1764
+ ...response.background != null ? { background: response.background } : {},
1765
+ ...response.output_format != null ? { outputFormat: response.output_format } : {}
1766
+ }))
1750
1767
  }
1751
1768
  }
1752
1769
  };
@@ -3340,7 +3357,7 @@ var OpenAIResponsesLanguageModel = class {
3340
3357
  };
3341
3358
  }
3342
3359
  async doGenerate(options) {
3343
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
3360
+ 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, _y, _z, _A, _B;
3344
3361
  const {
3345
3362
  args: body,
3346
3363
  warnings,
@@ -3350,6 +3367,7 @@ var OpenAIResponsesLanguageModel = class {
3350
3367
  path: "/responses",
3351
3368
  modelId: this.modelId
3352
3369
  });
3370
+ const providerKey = this.config.provider.replace(".responses", "");
3353
3371
  const {
3354
3372
  responseHeaders,
3355
3373
  value: response,
@@ -3390,7 +3408,7 @@ var OpenAIResponsesLanguageModel = class {
3390
3408
  type: "reasoning",
3391
3409
  text: summary.text,
3392
3410
  providerMetadata: {
3393
- openai: {
3411
+ [providerKey]: {
3394
3412
  itemId: part.id,
3395
3413
  reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
3396
3414
  }
@@ -3427,7 +3445,7 @@ var OpenAIResponsesLanguageModel = class {
3427
3445
  action: part.action
3428
3446
  }),
3429
3447
  providerMetadata: {
3430
- openai: {
3448
+ [providerKey]: {
3431
3449
  itemId: part.id
3432
3450
  }
3433
3451
  }
@@ -3443,7 +3461,7 @@ var OpenAIResponsesLanguageModel = class {
3443
3461
  type: "text",
3444
3462
  text: contentPart.text,
3445
3463
  providerMetadata: {
3446
- openai: {
3464
+ [providerKey]: {
3447
3465
  itemId: part.id
3448
3466
  }
3449
3467
  }
@@ -3467,12 +3485,43 @@ var OpenAIResponsesLanguageModel = class {
3467
3485
  filename: (_l = annotation.filename) != null ? _l : annotation.file_id,
3468
3486
  ...annotation.file_id ? {
3469
3487
  providerMetadata: {
3470
- openai: {
3488
+ [providerKey]: {
3471
3489
  fileId: annotation.file_id
3472
3490
  }
3473
3491
  }
3474
3492
  } : {}
3475
3493
  });
3494
+ } else if (annotation.type === "container_file_citation") {
3495
+ content.push({
3496
+ type: "source",
3497
+ sourceType: "document",
3498
+ id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils24.generateId)(),
3499
+ mediaType: "text/plain",
3500
+ title: (_q = (_p = annotation.filename) != null ? _p : annotation.file_id) != null ? _q : "Document",
3501
+ filename: (_r = annotation.filename) != null ? _r : annotation.file_id,
3502
+ providerMetadata: {
3503
+ [providerKey]: {
3504
+ fileId: annotation.file_id,
3505
+ containerId: annotation.container_id,
3506
+ ...annotation.index != null ? { index: annotation.index } : {}
3507
+ }
3508
+ }
3509
+ });
3510
+ } else if (annotation.type === "file_path") {
3511
+ content.push({
3512
+ type: "source",
3513
+ sourceType: "document",
3514
+ id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils24.generateId)(),
3515
+ mediaType: "application/octet-stream",
3516
+ title: annotation.file_id,
3517
+ filename: annotation.file_id,
3518
+ providerMetadata: {
3519
+ [providerKey]: {
3520
+ fileId: annotation.file_id,
3521
+ ...annotation.index != null ? { index: annotation.index } : {}
3522
+ }
3523
+ }
3524
+ });
3476
3525
  }
3477
3526
  }
3478
3527
  }
@@ -3486,7 +3535,7 @@ var OpenAIResponsesLanguageModel = class {
3486
3535
  toolName: part.name,
3487
3536
  input: part.arguments,
3488
3537
  providerMetadata: {
3489
- openai: {
3538
+ [providerKey]: {
3490
3539
  itemId: part.id
3491
3540
  }
3492
3541
  }
@@ -3544,13 +3593,13 @@ var OpenAIResponsesLanguageModel = class {
3544
3593
  toolName: "file_search",
3545
3594
  result: {
3546
3595
  queries: part.queries,
3547
- results: (_n = (_m = part.results) == null ? void 0 : _m.map((result) => ({
3596
+ results: (_w = (_v = part.results) == null ? void 0 : _v.map((result) => ({
3548
3597
  attributes: result.attributes,
3549
3598
  fileId: result.file_id,
3550
3599
  filename: result.filename,
3551
3600
  score: result.score,
3552
3601
  text: result.text
3553
- }))) != null ? _n : null
3602
+ }))) != null ? _w : null
3554
3603
  },
3555
3604
  providerExecuted: true
3556
3605
  });
@@ -3581,29 +3630,29 @@ var OpenAIResponsesLanguageModel = class {
3581
3630
  }
3582
3631
  }
3583
3632
  const providerMetadata = {
3584
- openai: {
3633
+ [providerKey]: {
3585
3634
  ...response.id != null ? { responseId: response.id } : {}
3586
3635
  }
3587
3636
  };
3588
3637
  if (logprobs.length > 0) {
3589
- providerMetadata.openai.logprobs = logprobs;
3638
+ providerMetadata[providerKey].logprobs = logprobs;
3590
3639
  }
3591
3640
  if (typeof response.service_tier === "string") {
3592
- providerMetadata.openai.serviceTier = response.service_tier;
3641
+ providerMetadata[providerKey].serviceTier = response.service_tier;
3593
3642
  }
3594
3643
  const usage = response.usage;
3595
3644
  return {
3596
3645
  content,
3597
3646
  finishReason: mapOpenAIResponseFinishReason({
3598
- finishReason: (_o = response.incomplete_details) == null ? void 0 : _o.reason,
3647
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
3599
3648
  hasFunctionCall
3600
3649
  }),
3601
3650
  usage: {
3602
3651
  inputTokens: usage.input_tokens,
3603
3652
  outputTokens: usage.output_tokens,
3604
3653
  totalTokens: usage.input_tokens + usage.output_tokens,
3605
- reasoningTokens: (_q = (_p = usage.output_tokens_details) == null ? void 0 : _p.reasoning_tokens) != null ? _q : void 0,
3606
- cachedInputTokens: (_s = (_r = usage.input_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : void 0
3654
+ reasoningTokens: (_z = (_y = usage.output_tokens_details) == null ? void 0 : _y.reasoning_tokens) != null ? _z : void 0,
3655
+ cachedInputTokens: (_B = (_A = usage.input_tokens_details) == null ? void 0 : _A.cached_tokens) != null ? _B : void 0
3607
3656
  },
3608
3657
  request: { body },
3609
3658
  response: {
@@ -3642,6 +3691,7 @@ var OpenAIResponsesLanguageModel = class {
3642
3691
  fetch: this.config.fetch
3643
3692
  });
3644
3693
  const self = this;
3694
+ const providerKey = this.config.provider.replace(".responses", "");
3645
3695
  let finishReason = "unknown";
3646
3696
  const usage = {
3647
3697
  inputTokens: void 0,
@@ -3757,7 +3807,7 @@ var OpenAIResponsesLanguageModel = class {
3757
3807
  type: "text-start",
3758
3808
  id: value.item.id,
3759
3809
  providerMetadata: {
3760
- openai: {
3810
+ [providerKey]: {
3761
3811
  itemId: value.item.id
3762
3812
  }
3763
3813
  }
@@ -3771,7 +3821,7 @@ var OpenAIResponsesLanguageModel = class {
3771
3821
  type: "reasoning-start",
3772
3822
  id: `${value.item.id}:0`,
3773
3823
  providerMetadata: {
3774
- openai: {
3824
+ [providerKey]: {
3775
3825
  itemId: value.item.id,
3776
3826
  reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
3777
3827
  }
@@ -3784,7 +3834,7 @@ var OpenAIResponsesLanguageModel = class {
3784
3834
  type: "text-end",
3785
3835
  id: value.item.id,
3786
3836
  providerMetadata: {
3787
- openai: {
3837
+ [providerKey]: {
3788
3838
  itemId: value.item.id,
3789
3839
  ...ongoingAnnotations.length > 0 && {
3790
3840
  annotations: ongoingAnnotations
@@ -3805,7 +3855,7 @@ var OpenAIResponsesLanguageModel = class {
3805
3855
  toolName: value.item.name,
3806
3856
  input: value.item.arguments,
3807
3857
  providerMetadata: {
3808
- openai: {
3858
+ [providerKey]: {
3809
3859
  itemId: value.item.id
3810
3860
  }
3811
3861
  }
@@ -3898,7 +3948,7 @@ var OpenAIResponsesLanguageModel = class {
3898
3948
  }
3899
3949
  }),
3900
3950
  providerMetadata: {
3901
- openai: { itemId: value.item.id }
3951
+ [providerKey]: { itemId: value.item.id }
3902
3952
  }
3903
3953
  });
3904
3954
  } else if (value.item.type === "reasoning") {
@@ -3913,7 +3963,7 @@ var OpenAIResponsesLanguageModel = class {
3913
3963
  type: "reasoning-end",
3914
3964
  id: `${value.item.id}:${summaryIndex}`,
3915
3965
  providerMetadata: {
3916
- openai: {
3966
+ [providerKey]: {
3917
3967
  itemId: value.item.id,
3918
3968
  reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
3919
3969
  }
@@ -3993,7 +4043,9 @@ var OpenAIResponsesLanguageModel = class {
3993
4043
  controller.enqueue({
3994
4044
  type: "reasoning-end",
3995
4045
  id: `${value.item_id}:${summaryIndex}`,
3996
- providerMetadata: { openai: { itemId: value.item_id } }
4046
+ providerMetadata: {
4047
+ [providerKey]: { itemId: value.item_id }
4048
+ }
3997
4049
  });
3998
4050
  activeReasoningPart.summaryParts[summaryIndex] = "concluded";
3999
4051
  }
@@ -4002,7 +4054,7 @@ var OpenAIResponsesLanguageModel = class {
4002
4054
  type: "reasoning-start",
4003
4055
  id: `${value.item_id}:${value.summary_index}`,
4004
4056
  providerMetadata: {
4005
- openai: {
4057
+ [providerKey]: {
4006
4058
  itemId: value.item_id,
4007
4059
  reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
4008
4060
  }
@@ -4015,7 +4067,7 @@ var OpenAIResponsesLanguageModel = class {
4015
4067
  id: `${value.item_id}:${value.summary_index}`,
4016
4068
  delta: value.delta,
4017
4069
  providerMetadata: {
4018
- openai: {
4070
+ [providerKey]: {
4019
4071
  itemId: value.item_id
4020
4072
  }
4021
4073
  }
@@ -4026,7 +4078,7 @@ var OpenAIResponsesLanguageModel = class {
4026
4078
  type: "reasoning-end",
4027
4079
  id: `${value.item_id}:${value.summary_index}`,
4028
4080
  providerMetadata: {
4029
- openai: { itemId: value.item_id }
4081
+ [providerKey]: { itemId: value.item_id }
4030
4082
  }
4031
4083
  });
4032
4084
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "concluded";
@@ -4066,7 +4118,7 @@ var OpenAIResponsesLanguageModel = class {
4066
4118
  filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id,
4067
4119
  ...value.annotation.file_id ? {
4068
4120
  providerMetadata: {
4069
- openai: {
4121
+ [providerKey]: {
4070
4122
  fileId: value.annotation.file_id
4071
4123
  }
4072
4124
  }
@@ -4079,15 +4131,15 @@ var OpenAIResponsesLanguageModel = class {
4079
4131
  },
4080
4132
  flush(controller) {
4081
4133
  const providerMetadata = {
4082
- openai: {
4134
+ [providerKey]: {
4083
4135
  responseId
4084
4136
  }
4085
4137
  };
4086
4138
  if (logprobs.length > 0) {
4087
- providerMetadata.openai.logprobs = logprobs;
4139
+ providerMetadata[providerKey].logprobs = logprobs;
4088
4140
  }
4089
4141
  if (serviceTier !== void 0) {
4090
- providerMetadata.openai.serviceTier = serviceTier;
4142
+ providerMetadata[providerKey].serviceTier = serviceTier;
4091
4143
  }
4092
4144
  controller.enqueue({
4093
4145
  type: "finish",
@@ -4530,7 +4582,7 @@ var OpenAITranscriptionModel = class {
4530
4582
  };
4531
4583
 
4532
4584
  // src/version.ts
4533
- var VERSION = true ? "2.0.74" : "0.0.0-test";
4585
+ var VERSION = true ? "2.0.76" : "0.0.0-test";
4534
4586
 
4535
4587
  // src/openai-provider.ts
4536
4588
  function createOpenAI(options = {}) {