@ai-sdk/openai 0.0.54 → 0.0.56

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 ADDED
@@ -0,0 +1,438 @@
1
+ # @ai-sdk/openai
2
+
3
+ ## 0.0.56
4
+
5
+ ### Patch Changes
6
+
7
+ - 03313cd: feat (ai): expose response id, response model, response timestamp in telemetry and api
8
+ - Updated dependencies [03313cd]
9
+ - Updated dependencies [3be7c1c]
10
+ - @ai-sdk/provider-utils@1.0.18
11
+ - @ai-sdk/provider@0.0.23
12
+
13
+ ## 0.0.55
14
+
15
+ ### Patch Changes
16
+
17
+ - 28cbf2e: fix (provider/openai): support tool call deltas when arguments are sent in the first chunk
18
+
19
+ ## 0.0.54
20
+
21
+ ### Patch Changes
22
+
23
+ - 26515cb: feat (ai/provider): introduce ProviderV1 specification
24
+ - Updated dependencies [26515cb]
25
+ - @ai-sdk/provider@0.0.22
26
+ - @ai-sdk/provider-utils@1.0.17
27
+
28
+ ## 0.0.53
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [09f895f]
33
+ - @ai-sdk/provider-utils@1.0.16
34
+
35
+ ## 0.0.52
36
+
37
+ ### Patch Changes
38
+
39
+ - d5b6a15: feat (provider/openai): support partial usage information
40
+
41
+ ## 0.0.51
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [d67fa9c]
46
+ - @ai-sdk/provider-utils@1.0.15
47
+
48
+ ## 0.0.50
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [f2c025e]
53
+ - @ai-sdk/provider@0.0.21
54
+ - @ai-sdk/provider-utils@1.0.14
55
+
56
+ ## 0.0.49
57
+
58
+ ### Patch Changes
59
+
60
+ - f42d9bd: fix (provider/openai): support OpenRouter streaming errors
61
+
62
+ ## 0.0.48
63
+
64
+ ### Patch Changes
65
+
66
+ - Updated dependencies [6ac355e]
67
+ - @ai-sdk/provider@0.0.20
68
+ - @ai-sdk/provider-utils@1.0.13
69
+
70
+ ## 0.0.47
71
+
72
+ ### Patch Changes
73
+
74
+ - 4ffbaee: fix (provider/openai): fix strict flag for structured outputs with tools
75
+ - dd712ac: fix: use FetchFunction type to prevent self-reference
76
+ - Updated dependencies [dd712ac]
77
+ - @ai-sdk/provider-utils@1.0.12
78
+
79
+ ## 0.0.46
80
+
81
+ ### Patch Changes
82
+
83
+ - 89b18ca: fix (ai/provider): send finish reason 'unknown' by default
84
+ - Updated dependencies [dd4a0f5]
85
+ - @ai-sdk/provider@0.0.19
86
+ - @ai-sdk/provider-utils@1.0.11
87
+
88
+ ## 0.0.45
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies [4bd27a9]
93
+ - Updated dependencies [845754b]
94
+ - @ai-sdk/provider-utils@1.0.10
95
+ - @ai-sdk/provider@0.0.18
96
+
97
+ ## 0.0.44
98
+
99
+ ### Patch Changes
100
+
101
+ - 029af4c: feat (ai/core): support schema name & description in generateObject & streamObject
102
+ - Updated dependencies [029af4c]
103
+ - @ai-sdk/provider@0.0.17
104
+ - @ai-sdk/provider-utils@1.0.9
105
+
106
+ ## 0.0.43
107
+
108
+ ### Patch Changes
109
+
110
+ - d58517b: feat (ai/openai): structured outputs
111
+ - c0a73ee: feat (provider/openai): add gpt-4o-2024-08-06 to list of supported models
112
+ - Updated dependencies [d58517b]
113
+ - @ai-sdk/provider@0.0.16
114
+ - @ai-sdk/provider-utils@1.0.8
115
+
116
+ ## 0.0.42
117
+
118
+ ### Patch Changes
119
+
120
+ - Updated dependencies [96aed25]
121
+ - @ai-sdk/provider@0.0.15
122
+ - @ai-sdk/provider-utils@1.0.7
123
+
124
+ ## 0.0.41
125
+
126
+ ### Patch Changes
127
+
128
+ - 7a2eb27: feat (provider/openai): make role nullish to enhance provider support
129
+ - Updated dependencies [9614584]
130
+ - Updated dependencies [0762a22]
131
+ - @ai-sdk/provider-utils@1.0.6
132
+
133
+ ## 0.0.40
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies [a8d1c9e9]
138
+ - @ai-sdk/provider-utils@1.0.5
139
+ - @ai-sdk/provider@0.0.14
140
+
141
+ ## 0.0.39
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies [4f88248f]
146
+ - @ai-sdk/provider-utils@1.0.4
147
+
148
+ ## 0.0.38
149
+
150
+ ### Patch Changes
151
+
152
+ - 2b9da0f0: feat (core): support stopSequences setting.
153
+ - 909b9d27: feat (ai/openai): Support legacy function calls
154
+ - a5b58845: feat (core): support topK setting
155
+ - 4aa8deb3: feat (provider): support responseFormat setting in provider api
156
+ - 13b27ec6: chore (ai/core): remove grammar mode
157
+ - Updated dependencies [2b9da0f0]
158
+ - Updated dependencies [a5b58845]
159
+ - Updated dependencies [4aa8deb3]
160
+ - Updated dependencies [13b27ec6]
161
+ - @ai-sdk/provider@0.0.13
162
+ - @ai-sdk/provider-utils@1.0.3
163
+
164
+ ## 0.0.37
165
+
166
+ ### Patch Changes
167
+
168
+ - 89947fc5: chore (provider/openai): update model list for type-ahead support
169
+
170
+ ## 0.0.36
171
+
172
+ ### Patch Changes
173
+
174
+ - b7290943: feat (ai/core): add token usage to embed and embedMany
175
+ - Updated dependencies [b7290943]
176
+ - @ai-sdk/provider@0.0.12
177
+ - @ai-sdk/provider-utils@1.0.2
178
+
179
+ ## 0.0.35
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [d481729f]
184
+ - @ai-sdk/provider-utils@1.0.1
185
+
186
+ ## 0.0.34
187
+
188
+ ### Patch Changes
189
+
190
+ - 5edc6110: feat (ai/core): add custom request header support
191
+ - Updated dependencies [5edc6110]
192
+ - Updated dependencies [5edc6110]
193
+ - Updated dependencies [5edc6110]
194
+ - @ai-sdk/provider@0.0.11
195
+ - @ai-sdk/provider-utils@1.0.0
196
+
197
+ ## 0.0.33
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies [02f6a088]
202
+ - @ai-sdk/provider-utils@0.0.16
203
+
204
+ ## 0.0.32
205
+
206
+ ### Patch Changes
207
+
208
+ - 1b37b8b9: fix (@ai-sdk/openai): only send logprobs settings when logprobs are requested
209
+
210
+ ## 0.0.31
211
+
212
+ ### Patch Changes
213
+
214
+ - eba071dd: feat (@ai-sdk/azure): add azure openai completion support
215
+ - 1ea890fe: feat (@ai-sdk/azure): add azure openai completion support
216
+
217
+ ## 0.0.30
218
+
219
+ ### Patch Changes
220
+
221
+ - Updated dependencies [85712895]
222
+ - Updated dependencies [85712895]
223
+ - @ai-sdk/provider-utils@0.0.15
224
+
225
+ ## 0.0.29
226
+
227
+ ### Patch Changes
228
+
229
+ - 4728c37f: feat (core): add text embedding model support to provider registry
230
+ - 7910ae84: feat (providers): support custom fetch implementations
231
+ - Updated dependencies [7910ae84]
232
+ - @ai-sdk/provider-utils@0.0.14
233
+
234
+ ## 0.0.28
235
+
236
+ ### Patch Changes
237
+
238
+ - f9db8fd6: feat (@ai-sdk/openai): add parallelToolCalls setting
239
+
240
+ ## 0.0.27
241
+
242
+ ### Patch Changes
243
+
244
+ - fc9552ec: fix (@ai-sdk/azure): allow for nullish delta
245
+
246
+ ## 0.0.26
247
+
248
+ ### Patch Changes
249
+
250
+ - 7530f861: fix (@ai-sdk/openai): add internal dist to bundle
251
+
252
+ ## 0.0.25
253
+
254
+ ### Patch Changes
255
+
256
+ - 8b1362a7: chore (@ai-sdk/openai): expose models under /internal for reuse in other providers
257
+
258
+ ## 0.0.24
259
+
260
+ ### Patch Changes
261
+
262
+ - 0e78960c: fix (@ai-sdk/openai): make function name and arguments nullish
263
+
264
+ ## 0.0.23
265
+
266
+ ### Patch Changes
267
+
268
+ - a68fe74a: fix (@ai-sdk/openai): allow null tool_calls value.
269
+
270
+ ## 0.0.22
271
+
272
+ ### Patch Changes
273
+
274
+ - Updated dependencies [102ca22f]
275
+ - @ai-sdk/provider@0.0.10
276
+ - @ai-sdk/provider-utils@0.0.13
277
+
278
+ ## 0.0.21
279
+
280
+ ### Patch Changes
281
+
282
+ - fca7d026: feat (provider/openai): support streaming tool calls that are sent in one chunk
283
+ - Updated dependencies [09295e2e]
284
+ - Updated dependencies [09295e2e]
285
+ - Updated dependencies [043a5de2]
286
+ - @ai-sdk/provider@0.0.9
287
+ - @ai-sdk/provider-utils@0.0.12
288
+
289
+ ## 0.0.20
290
+
291
+ ### Patch Changes
292
+
293
+ - a1d08f3e: fix (provider/openai): handle error chunks when streaming
294
+
295
+ ## 0.0.19
296
+
297
+ ### Patch Changes
298
+
299
+ - beb8b739: fix (provider/openai): return unknown finish reasons as unknown
300
+
301
+ ## 0.0.18
302
+
303
+ ### Patch Changes
304
+
305
+ - fb42e760: feat (provider/openai): send user message content as text when possible
306
+
307
+ ## 0.0.17
308
+
309
+ ### Patch Changes
310
+
311
+ - f39c0dd2: feat (provider): implement toolChoice support
312
+ - Updated dependencies [f39c0dd2]
313
+ - @ai-sdk/provider@0.0.8
314
+ - @ai-sdk/provider-utils@0.0.11
315
+
316
+ ## 0.0.16
317
+
318
+ ### Patch Changes
319
+
320
+ - 2b18fa11: fix (provider/openai): remove object type validation
321
+
322
+ ## 0.0.15
323
+
324
+ ### Patch Changes
325
+
326
+ - 24683b72: fix (providers): Zod is required dependency
327
+ - Updated dependencies [8e780288]
328
+ - @ai-sdk/provider@0.0.7
329
+ - @ai-sdk/provider-utils@0.0.10
330
+
331
+ ## 0.0.14
332
+
333
+ ### Patch Changes
334
+
335
+ - Updated dependencies [6a50ac4]
336
+ - Updated dependencies [6a50ac4]
337
+ - @ai-sdk/provider@0.0.6
338
+ - @ai-sdk/provider-utils@0.0.9
339
+
340
+ ## 0.0.13
341
+
342
+ ### Patch Changes
343
+
344
+ - 4e3c922: fix (provider/openai): introduce compatibility mode in which "stream_options" are not sent
345
+
346
+ ## 0.0.12
347
+
348
+ ### Patch Changes
349
+
350
+ - 6f48839: feat (provider/openai): add gpt-4o to the list of supported models
351
+ - 1009594: feat (provider/openai): set stream_options/include_usage to true when streaming
352
+ - 0f6bc4e: feat (ai/core): add embed function
353
+ - Updated dependencies [0f6bc4e]
354
+ - @ai-sdk/provider@0.0.5
355
+ - @ai-sdk/provider-utils@0.0.8
356
+
357
+ ## 0.0.11
358
+
359
+ ### Patch Changes
360
+
361
+ - Updated dependencies [325ca55]
362
+ - @ai-sdk/provider@0.0.4
363
+ - @ai-sdk/provider-utils@0.0.7
364
+
365
+ ## 0.0.10
366
+
367
+ ### Patch Changes
368
+
369
+ - Updated dependencies [276f22b]
370
+ - @ai-sdk/provider-utils@0.0.6
371
+
372
+ ## 0.0.9
373
+
374
+ ### Patch Changes
375
+
376
+ - Updated dependencies [41d5736]
377
+ - @ai-sdk/provider@0.0.3
378
+ - @ai-sdk/provider-utils@0.0.5
379
+
380
+ ## 0.0.8
381
+
382
+ ### Patch Changes
383
+
384
+ - Updated dependencies [56ef84a]
385
+ - @ai-sdk/provider-utils@0.0.4
386
+
387
+ ## 0.0.7
388
+
389
+ ### Patch Changes
390
+
391
+ - 0833e19: Allow optional content to support Fireworks function calling.
392
+
393
+ ## 0.0.6
394
+
395
+ ### Patch Changes
396
+
397
+ - d6431ae: ai/core: add logprobs support (thanks @SamStenner for the contribution)
398
+ - 25f3350: ai/core: add support for getting raw response headers.
399
+ - Updated dependencies [d6431ae]
400
+ - Updated dependencies [25f3350]
401
+ - @ai-sdk/provider@0.0.2
402
+ - @ai-sdk/provider-utils@0.0.3
403
+
404
+ ## 0.0.5
405
+
406
+ ### Patch Changes
407
+
408
+ - eb150a6: ai/core: remove scaling of setting values (breaking change). If you were using the temperature, frequency penalty, or presence penalty settings, you need to update the providers and adjust the setting values.
409
+ - Updated dependencies [eb150a6]
410
+ - @ai-sdk/provider-utils@0.0.2
411
+ - @ai-sdk/provider@0.0.1
412
+
413
+ ## 0.0.4
414
+
415
+ ### Patch Changes
416
+
417
+ - c6fc35b: Add custom header and OpenAI project support.
418
+
419
+ ## 0.0.3
420
+
421
+ ### Patch Changes
422
+
423
+ - ab60b18: Simplified model construction by directly calling provider functions. Add create... functions to create provider instances.
424
+
425
+ ## 0.0.2
426
+
427
+ ### Patch Changes
428
+
429
+ - 2bff460: Fix build for release.
430
+
431
+ ## 0.0.1
432
+
433
+ ### Patch Changes
434
+
435
+ - 7b8791d: Support streams with 'chat.completion' objects.
436
+ - 7b8791d: Rename baseUrl to baseURL. Automatically remove trailing slashes.
437
+ - Updated dependencies [7b8791d]
438
+ - @ai-sdk/provider-utils@0.0.1
package/dist/index.js CHANGED
@@ -196,6 +196,19 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
196
196
  errorToMessage: (data) => data.error.message
197
197
  });
198
198
 
199
+ // src/get-response-metadata.ts
200
+ function getResponseMetadata({
201
+ id,
202
+ model,
203
+ created
204
+ }) {
205
+ return {
206
+ id: id != null ? id : void 0,
207
+ modelId: model != null ? model : void 0,
208
+ timestamp: created != null ? new Date(created * 1e3) : void 0
209
+ };
210
+ }
211
+
199
212
  // src/openai-chat-language-model.ts
200
213
  var OpenAIChatLanguageModel = class {
201
214
  constructor(modelId, settings, config) {
@@ -394,6 +407,7 @@ var OpenAIChatLanguageModel = class {
394
407
  },
395
408
  rawCall: { rawPrompt, rawSettings },
396
409
  rawResponse: { headers: responseHeaders },
410
+ response: getResponseMetadata(response),
397
411
  warnings,
398
412
  logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs)
399
413
  };
@@ -427,6 +441,7 @@ var OpenAIChatLanguageModel = class {
427
441
  completionTokens: void 0
428
442
  };
429
443
  let logprobs;
444
+ let isFirstChunk = true;
430
445
  const { useLegacyFunctionCalling } = this.settings;
431
446
  return {
432
447
  stream: response.pipeThrough(
@@ -444,6 +459,13 @@ var OpenAIChatLanguageModel = class {
444
459
  controller.enqueue({ type: "error", error: value.error });
445
460
  return;
446
461
  }
462
+ if (isFirstChunk) {
463
+ isFirstChunk = false;
464
+ controller.enqueue({
465
+ type: "response-metadata",
466
+ ...getResponseMetadata(value)
467
+ });
468
+ }
447
469
  if (value.usage != null) {
448
470
  usage = {
449
471
  promptTokens: (_a = value.usage.prompt_tokens) != null ? _a : void 0,
@@ -510,21 +532,25 @@ var OpenAIChatLanguageModel = class {
510
532
  }
511
533
  };
512
534
  const toolCall2 = toolCalls[index];
513
- if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
514
- controller.enqueue({
515
- type: "tool-call-delta",
516
- toolCallType: "function",
517
- toolCallId: toolCall2.id,
518
- toolName: toolCall2.function.name,
519
- argsTextDelta: toolCall2.function.arguments
520
- });
521
- controller.enqueue({
522
- type: "tool-call",
523
- toolCallType: "function",
524
- toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(),
525
- toolName: toolCall2.function.name,
526
- args: toolCall2.function.arguments
527
- });
535
+ if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
536
+ if (toolCall2.function.arguments.length > 0) {
537
+ controller.enqueue({
538
+ type: "tool-call-delta",
539
+ toolCallType: "function",
540
+ toolCallId: toolCall2.id,
541
+ toolName: toolCall2.function.name,
542
+ argsTextDelta: toolCall2.function.arguments
543
+ });
544
+ }
545
+ if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
546
+ controller.enqueue({
547
+ type: "tool-call",
548
+ toolCallType: "function",
549
+ toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(),
550
+ toolName: toolCall2.function.name,
551
+ args: toolCall2.function.arguments
552
+ });
553
+ }
528
554
  }
529
555
  continue;
530
556
  }
@@ -576,6 +602,9 @@ var openAITokenUsageSchema = import_zod2.z.object({
576
602
  completion_tokens: import_zod2.z.number().nullish()
577
603
  }).nullish();
578
604
  var openAIChatResponseSchema = import_zod2.z.object({
605
+ id: import_zod2.z.string().nullish(),
606
+ created: import_zod2.z.number().nullish(),
607
+ model: import_zod2.z.string().nullish(),
579
608
  choices: import_zod2.z.array(
580
609
  import_zod2.z.object({
581
610
  message: import_zod2.z.object({
@@ -618,6 +647,9 @@ var openAIChatResponseSchema = import_zod2.z.object({
618
647
  });
619
648
  var openaiChatChunkSchema = import_zod2.z.union([
620
649
  import_zod2.z.object({
650
+ id: import_zod2.z.string().nullish(),
651
+ created: import_zod2.z.number().nullish(),
652
+ model: import_zod2.z.string().nullish(),
621
653
  choices: import_zod2.z.array(
622
654
  import_zod2.z.object({
623
655
  delta: import_zod2.z.object({
@@ -962,6 +994,7 @@ var OpenAICompletionLanguageModel = class {
962
994
  logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
963
995
  rawCall: { rawPrompt, rawSettings },
964
996
  rawResponse: { headers: responseHeaders },
997
+ response: getResponseMetadata(response),
965
998
  warnings
966
999
  };
967
1000
  }
@@ -993,6 +1026,7 @@ var OpenAICompletionLanguageModel = class {
993
1026
  completionTokens: Number.NaN
994
1027
  };
995
1028
  let logprobs;
1029
+ let isFirstChunk = true;
996
1030
  return {
997
1031
  stream: response.pipeThrough(
998
1032
  new TransformStream({
@@ -1008,6 +1042,13 @@ var OpenAICompletionLanguageModel = class {
1008
1042
  controller.enqueue({ type: "error", error: value.error });
1009
1043
  return;
1010
1044
  }
1045
+ if (isFirstChunk) {
1046
+ isFirstChunk = false;
1047
+ controller.enqueue({
1048
+ type: "response-metadata",
1049
+ ...getResponseMetadata(value)
1050
+ });
1051
+ }
1011
1052
  if (value.usage != null) {
1012
1053
  usage = {
1013
1054
  promptTokens: value.usage.prompt_tokens,
@@ -1049,6 +1090,9 @@ var OpenAICompletionLanguageModel = class {
1049
1090
  }
1050
1091
  };
1051
1092
  var openAICompletionResponseSchema = import_zod3.z.object({
1093
+ id: import_zod3.z.string().nullish(),
1094
+ created: import_zod3.z.number().nullish(),
1095
+ model: import_zod3.z.string().nullish(),
1052
1096
  choices: import_zod3.z.array(
1053
1097
  import_zod3.z.object({
1054
1098
  text: import_zod3.z.string(),
@@ -1057,7 +1101,7 @@ var openAICompletionResponseSchema = import_zod3.z.object({
1057
1101
  tokens: import_zod3.z.array(import_zod3.z.string()),
1058
1102
  token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1059
1103
  top_logprobs: import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())).nullable()
1060
- }).nullable().optional()
1104
+ }).nullish()
1061
1105
  })
1062
1106
  ),
1063
1107
  usage: import_zod3.z.object({
@@ -1067,6 +1111,9 @@ var openAICompletionResponseSchema = import_zod3.z.object({
1067
1111
  });
1068
1112
  var openaiCompletionChunkSchema = import_zod3.z.union([
1069
1113
  import_zod3.z.object({
1114
+ id: import_zod3.z.string().nullish(),
1115
+ created: import_zod3.z.number().nullish(),
1116
+ model: import_zod3.z.string().nullish(),
1070
1117
  choices: import_zod3.z.array(
1071
1118
  import_zod3.z.object({
1072
1119
  text: import_zod3.z.string(),
@@ -1076,13 +1123,13 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
1076
1123
  tokens: import_zod3.z.array(import_zod3.z.string()),
1077
1124
  token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1078
1125
  top_logprobs: import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())).nullable()
1079
- }).nullable().optional()
1126
+ }).nullish()
1080
1127
  })
1081
1128
  ),
1082
1129
  usage: import_zod3.z.object({
1083
1130
  prompt_tokens: import_zod3.z.number(),
1084
1131
  completion_tokens: import_zod3.z.number()
1085
- }).optional().nullable()
1132
+ }).nullish()
1086
1133
  }),
1087
1134
  openAIErrorDataSchema
1088
1135
  ]);