@ai-sdk/openai 3.0.25 → 3.0.27
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 +14 -0
- package/dist/index.d.mts +31 -5
- package/dist/index.d.ts +31 -5
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -12
- package/dist/internal/index.d.ts +12 -12
- package/dist/internal/index.js +24 -24
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +19 -19
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +49 -38
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model.ts +2 -2
- package/src/chat/openai-chat-options.ts +3 -3
- package/src/completion/openai-completion-language-model.ts +3 -3
- package/src/completion/openai-completion-options.ts +3 -3
- package/src/embedding/openai-embedding-model.ts +2 -2
- package/src/embedding/openai-embedding-options.ts +3 -3
- package/src/index.ts +14 -2
- package/src/responses/openai-responses-language-model.ts +3 -3
- package/src/responses/openai-responses-options.ts +3 -3
- package/src/speech/openai-speech-model.ts +2 -2
- package/src/speech/openai-speech-options.ts +3 -3
- package/src/transcription/openai-transcription-model.ts +4 -4
- package/src/transcription/openai-transcription-options.ts +3 -3
package/docs/03-openai.mdx
CHANGED
|
@@ -135,10 +135,10 @@ const model = openai('gpt-5');
|
|
|
135
135
|
```
|
|
136
136
|
|
|
137
137
|
Further configuration can be done using OpenAI provider options.
|
|
138
|
-
You can validate the provider options using the `
|
|
138
|
+
You can validate the provider options using the `OpenAILanguageModelResponsesOptions` type.
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
|
-
import { openai,
|
|
141
|
+
import { openai, OpenAILanguageModelResponsesOptions } from '@ai-sdk/openai';
|
|
142
142
|
import { generateText } from 'ai';
|
|
143
143
|
|
|
144
144
|
const result = await generateText({
|
|
@@ -149,7 +149,7 @@ const result = await generateText({
|
|
|
149
149
|
store: false,
|
|
150
150
|
user: 'user_123',
|
|
151
151
|
// ...
|
|
152
|
-
} satisfies
|
|
152
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
153
153
|
},
|
|
154
154
|
// ...
|
|
155
155
|
});
|
|
@@ -292,7 +292,10 @@ The following OpenAI-specific metadata may be returned:
|
|
|
292
292
|
For reasoning models like `gpt-5`, you can enable reasoning summaries to see the model's thought process. Different models support different summarizers—for example, `o4-mini` supports detailed summaries. Set `reasoningSummary: "auto"` to automatically receive the richest level available.
|
|
293
293
|
|
|
294
294
|
```ts highlight="8-9,16"
|
|
295
|
-
import {
|
|
295
|
+
import {
|
|
296
|
+
openai,
|
|
297
|
+
type OpenAILanguageModelResponsesOptions,
|
|
298
|
+
} from '@ai-sdk/openai';
|
|
296
299
|
import { streamText } from 'ai';
|
|
297
300
|
|
|
298
301
|
const result = streamText({
|
|
@@ -301,7 +304,7 @@ const result = streamText({
|
|
|
301
304
|
providerOptions: {
|
|
302
305
|
openai: {
|
|
303
306
|
reasoningSummary: 'detailed', // 'auto' for condensed or 'detailed' for comprehensive
|
|
304
|
-
},
|
|
307
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
305
308
|
},
|
|
306
309
|
});
|
|
307
310
|
|
|
@@ -317,7 +320,10 @@ for await (const part of result.fullStream) {
|
|
|
317
320
|
For non-streaming calls with `generateText`, the reasoning summaries are available in the `reasoning` field of the response:
|
|
318
321
|
|
|
319
322
|
```ts highlight="8-9,13"
|
|
320
|
-
import {
|
|
323
|
+
import {
|
|
324
|
+
openai,
|
|
325
|
+
type OpenAILanguageModelResponsesOptions,
|
|
326
|
+
} from '@ai-sdk/openai';
|
|
321
327
|
import { generateText } from 'ai';
|
|
322
328
|
|
|
323
329
|
const result = await generateText({
|
|
@@ -326,7 +332,7 @@ const result = await generateText({
|
|
|
326
332
|
providerOptions: {
|
|
327
333
|
openai: {
|
|
328
334
|
reasoningSummary: 'auto',
|
|
329
|
-
},
|
|
335
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
330
336
|
},
|
|
331
337
|
});
|
|
332
338
|
console.log('Reasoning:', result.reasoning);
|
|
@@ -339,7 +345,10 @@ Learn more about reasoning summaries in the [OpenAI documentation](https://platf
|
|
|
339
345
|
You can control the length and detail of model responses using the `textVerbosity` parameter:
|
|
340
346
|
|
|
341
347
|
```ts
|
|
342
|
-
import {
|
|
348
|
+
import {
|
|
349
|
+
openai,
|
|
350
|
+
type OpenAILanguageModelResponsesOptions,
|
|
351
|
+
} from '@ai-sdk/openai';
|
|
343
352
|
import { generateText } from 'ai';
|
|
344
353
|
|
|
345
354
|
const result = await generateText({
|
|
@@ -348,7 +357,7 @@ const result = await generateText({
|
|
|
348
357
|
providerOptions: {
|
|
349
358
|
openai: {
|
|
350
359
|
textVerbosity: 'low', // 'low' for concise, 'medium' (default), or 'high' for verbose
|
|
351
|
-
},
|
|
360
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
352
361
|
},
|
|
353
362
|
});
|
|
354
363
|
```
|
|
@@ -439,7 +448,7 @@ const result = await generateText({
|
|
|
439
448
|
openai: {
|
|
440
449
|
// optional: include results
|
|
441
450
|
include: ['file_search_call.results'],
|
|
442
|
-
} satisfies
|
|
451
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
443
452
|
},
|
|
444
453
|
});
|
|
445
454
|
```
|
|
@@ -1014,7 +1023,7 @@ This metadata includes the following fields:
|
|
|
1014
1023
|
import {
|
|
1015
1024
|
openai,
|
|
1016
1025
|
type OpenaiResponsesReasoningProviderMetadata,
|
|
1017
|
-
type
|
|
1026
|
+
type OpenAILanguageModelResponsesOptions,
|
|
1018
1027
|
} from '@ai-sdk/openai';
|
|
1019
1028
|
import { generateText } from 'ai';
|
|
1020
1029
|
|
|
@@ -1025,7 +1034,7 @@ const result = await generateText({
|
|
|
1025
1034
|
openai: {
|
|
1026
1035
|
store: false,
|
|
1027
1036
|
include: ['reasoning.encrypted_content'],
|
|
1028
|
-
} satisfies
|
|
1037
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
1029
1038
|
},
|
|
1030
1039
|
});
|
|
1031
1040
|
|
|
@@ -1130,7 +1139,7 @@ OpenAI chat models support also some model specific provider options that are no
|
|
|
1130
1139
|
You can pass them in the `providerOptions` argument:
|
|
1131
1140
|
|
|
1132
1141
|
```ts
|
|
1133
|
-
import { openai, type
|
|
1142
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1134
1143
|
|
|
1135
1144
|
const model = openai.chat('gpt-5');
|
|
1136
1145
|
|
|
@@ -1143,7 +1152,7 @@ await generateText({
|
|
|
1143
1152
|
'50256': -100,
|
|
1144
1153
|
},
|
|
1145
1154
|
user: 'test-user', // optional unique user identifier
|
|
1146
|
-
} satisfies
|
|
1155
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1147
1156
|
},
|
|
1148
1157
|
});
|
|
1149
1158
|
```
|
|
@@ -1261,7 +1270,7 @@ They support additional settings and response metadata:
|
|
|
1261
1270
|
- You can use response `providerMetadata` to access the number of reasoning tokens that the model generated.
|
|
1262
1271
|
|
|
1263
1272
|
```ts highlight="4,7-11,17"
|
|
1264
|
-
import { openai } from '@ai-sdk/openai';
|
|
1273
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1265
1274
|
import { generateText } from 'ai';
|
|
1266
1275
|
|
|
1267
1276
|
const { text, usage, providerMetadata } = await generateText({
|
|
@@ -1270,7 +1279,7 @@ const { text, usage, providerMetadata } = await generateText({
|
|
|
1270
1279
|
providerOptions: {
|
|
1271
1280
|
openai: {
|
|
1272
1281
|
reasoningEffort: 'low',
|
|
1273
|
-
},
|
|
1282
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1274
1283
|
},
|
|
1275
1284
|
});
|
|
1276
1285
|
|
|
@@ -1293,7 +1302,7 @@ console.log('Usage:', {
|
|
|
1293
1302
|
- `remove`: remove the system message from the messages.
|
|
1294
1303
|
|
|
1295
1304
|
```ts highlight="12"
|
|
1296
|
-
import { openai } from '@ai-sdk/openai';
|
|
1305
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1297
1306
|
import { generateText } from 'ai';
|
|
1298
1307
|
|
|
1299
1308
|
const result = await generateText({
|
|
@@ -1305,7 +1314,7 @@ const result = await generateText({
|
|
|
1305
1314
|
providerOptions: {
|
|
1306
1315
|
openai: {
|
|
1307
1316
|
systemMessageMode: 'system',
|
|
1308
|
-
},
|
|
1317
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1309
1318
|
},
|
|
1310
1319
|
});
|
|
1311
1320
|
```
|
|
@@ -1327,7 +1336,7 @@ Strict structured outputs are enabled by default.
|
|
|
1327
1336
|
You can disable them by setting the `strictJsonSchema` option to `false`.
|
|
1328
1337
|
|
|
1329
1338
|
```ts highlight="7"
|
|
1330
|
-
import { openai,
|
|
1339
|
+
import { openai, OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1331
1340
|
import { generateObject } from 'ai';
|
|
1332
1341
|
import { z } from 'zod';
|
|
1333
1342
|
|
|
@@ -1336,7 +1345,7 @@ const result = await generateObject({
|
|
|
1336
1345
|
providerOptions: {
|
|
1337
1346
|
openai: {
|
|
1338
1347
|
strictJsonSchema: false,
|
|
1339
|
-
} satisfies
|
|
1348
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1340
1349
|
},
|
|
1341
1350
|
schemaName: 'recipe',
|
|
1342
1351
|
schemaDescription: 'A recipe for lasagna.',
|
|
@@ -1373,7 +1382,7 @@ OpenAI provides logprobs information for completion/chat models.
|
|
|
1373
1382
|
You can access it in the `providerMetadata` object.
|
|
1374
1383
|
|
|
1375
1384
|
```ts highlight="11"
|
|
1376
|
-
import { openai } from '@ai-sdk/openai';
|
|
1385
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1377
1386
|
import { generateText } from 'ai';
|
|
1378
1387
|
|
|
1379
1388
|
const result = await generateText({
|
|
@@ -1384,7 +1393,7 @@ const result = await generateText({
|
|
|
1384
1393
|
// this can also be a number,
|
|
1385
1394
|
// refer to logprobs provider options section for more
|
|
1386
1395
|
logprobs: true,
|
|
1387
|
-
},
|
|
1396
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1388
1397
|
},
|
|
1389
1398
|
});
|
|
1390
1399
|
|
|
@@ -1510,7 +1519,7 @@ const result = streamText({
|
|
|
1510
1519
|
type: 'content',
|
|
1511
1520
|
content: existingCode,
|
|
1512
1521
|
},
|
|
1513
|
-
},
|
|
1522
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1514
1523
|
},
|
|
1515
1524
|
});
|
|
1516
1525
|
```
|
|
@@ -1574,7 +1583,7 @@ If you want to store a generation for use in the distillation process, you can a
|
|
|
1574
1583
|
This will save the generation to the OpenAI platform for later use in distillation.
|
|
1575
1584
|
|
|
1576
1585
|
```typescript highlight="9-16"
|
|
1577
|
-
import { openai } from '@ai-sdk/openai';
|
|
1586
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1578
1587
|
import { generateText } from 'ai';
|
|
1579
1588
|
import 'dotenv/config';
|
|
1580
1589
|
|
|
@@ -1588,7 +1597,7 @@ async function main() {
|
|
|
1588
1597
|
metadata: {
|
|
1589
1598
|
custom: 'value',
|
|
1590
1599
|
},
|
|
1591
|
-
},
|
|
1600
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1592
1601
|
},
|
|
1593
1602
|
});
|
|
1594
1603
|
|
|
@@ -1630,7 +1639,7 @@ console.log(`usage:`, {
|
|
|
1630
1639
|
To improve cache hit rates, you can manually control caching using the `promptCacheKey` option:
|
|
1631
1640
|
|
|
1632
1641
|
```ts highlight="7-11"
|
|
1633
|
-
import { openai } from '@ai-sdk/openai';
|
|
1642
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1634
1643
|
import { generateText } from 'ai';
|
|
1635
1644
|
|
|
1636
1645
|
const { text, usage, providerMetadata } = await generateText({
|
|
@@ -1639,7 +1648,7 @@ const { text, usage, providerMetadata } = await generateText({
|
|
|
1639
1648
|
providerOptions: {
|
|
1640
1649
|
openai: {
|
|
1641
1650
|
promptCacheKey: 'my-custom-cache-key-123',
|
|
1642
|
-
},
|
|
1651
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1643
1652
|
},
|
|
1644
1653
|
});
|
|
1645
1654
|
|
|
@@ -1652,7 +1661,7 @@ console.log(`usage:`, {
|
|
|
1652
1661
|
For GPT-5.1 models, you can enable extended prompt caching that keeps cached prefixes active for up to 24 hours:
|
|
1653
1662
|
|
|
1654
1663
|
```ts highlight="7-12"
|
|
1655
|
-
import { openai } from '@ai-sdk/openai';
|
|
1664
|
+
import { openai, type OpenAILanguageModelChatOptions } from '@ai-sdk/openai';
|
|
1656
1665
|
import { generateText } from 'ai';
|
|
1657
1666
|
|
|
1658
1667
|
const { text, usage, providerMetadata } = await generateText({
|
|
@@ -1662,7 +1671,7 @@ const { text, usage, providerMetadata } = await generateText({
|
|
|
1662
1671
|
openai: {
|
|
1663
1672
|
promptCacheKey: 'my-custom-cache-key-123',
|
|
1664
1673
|
promptCacheRetention: '24h', // Extended caching for GPT-5.1
|
|
1665
|
-
},
|
|
1674
|
+
} satisfies OpenAILanguageModelChatOptions,
|
|
1666
1675
|
},
|
|
1667
1676
|
});
|
|
1668
1677
|
|
|
@@ -1729,7 +1738,7 @@ await model.doGenerate({
|
|
|
1729
1738
|
},
|
|
1730
1739
|
suffix: 'some text', // optional suffix that comes after a completion of inserted text
|
|
1731
1740
|
user: 'test-user', // optional unique user identifier
|
|
1732
|
-
},
|
|
1741
|
+
} satisfies OpenAILanguageModelCompletionOptions,
|
|
1733
1742
|
},
|
|
1734
1743
|
});
|
|
1735
1744
|
```
|
|
@@ -1819,7 +1828,7 @@ OpenAI embedding models support several additional provider options.
|
|
|
1819
1828
|
You can pass them as an options argument:
|
|
1820
1829
|
|
|
1821
1830
|
```ts
|
|
1822
|
-
import { openai } from '@ai-sdk/openai';
|
|
1831
|
+
import { openai, type OpenAIEmbeddingModelOptions } from '@ai-sdk/openai';
|
|
1823
1832
|
import { embed } from 'ai';
|
|
1824
1833
|
|
|
1825
1834
|
const { embedding } = await embed({
|
|
@@ -1829,7 +1838,7 @@ const { embedding } = await embed({
|
|
|
1829
1838
|
openai: {
|
|
1830
1839
|
dimensions: 512, // optional, number of dimensions for the embedding
|
|
1831
1840
|
user: 'test-user', // optional unique user identifier
|
|
1832
|
-
},
|
|
1841
|
+
} satisfies OpenAIEmbeddingModelOptions,
|
|
1833
1842
|
},
|
|
1834
1843
|
});
|
|
1835
1844
|
```
|
|
@@ -2009,12 +2018,14 @@ You can also pass additional provider-specific options using the `providerOption
|
|
|
2009
2018
|
|
|
2010
2019
|
```ts highlight="6"
|
|
2011
2020
|
import { experimental_transcribe as transcribe } from 'ai';
|
|
2012
|
-
import { openai } from '@ai-sdk/openai';
|
|
2021
|
+
import { openai, type OpenAITranscriptionModelOptions } from '@ai-sdk/openai';
|
|
2013
2022
|
|
|
2014
2023
|
const result = await transcribe({
|
|
2015
2024
|
model: openai.transcription('whisper-1'),
|
|
2016
2025
|
audio: new Uint8Array([1, 2, 3, 4]),
|
|
2017
|
-
providerOptions: {
|
|
2026
|
+
providerOptions: {
|
|
2027
|
+
openai: { language: 'en' } satisfies OpenAITranscriptionModelOptions,
|
|
2028
|
+
},
|
|
2018
2029
|
});
|
|
2019
2030
|
```
|
|
2020
2031
|
|
|
@@ -2022,7 +2033,7 @@ To get word-level timestamps, specify the granularity:
|
|
|
2022
2033
|
|
|
2023
2034
|
```ts highlight="8-9"
|
|
2024
2035
|
import { experimental_transcribe as transcribe } from 'ai';
|
|
2025
|
-
import { openai } from '@ai-sdk/openai';
|
|
2036
|
+
import { openai, type OpenAITranscriptionModelOptions } from '@ai-sdk/openai';
|
|
2026
2037
|
|
|
2027
2038
|
const result = await transcribe({
|
|
2028
2039
|
model: openai.transcription('whisper-1'),
|
|
@@ -2031,7 +2042,7 @@ const result = await transcribe({
|
|
|
2031
2042
|
openai: {
|
|
2032
2043
|
//timestampGranularities: ['word'],
|
|
2033
2044
|
timestampGranularities: ['segment'],
|
|
2034
|
-
},
|
|
2045
|
+
} satisfies OpenAITranscriptionModelOptions,
|
|
2035
2046
|
},
|
|
2036
2047
|
});
|
|
2037
2048
|
|
|
@@ -2099,7 +2110,7 @@ You can also pass additional provider-specific options using the `providerOption
|
|
|
2099
2110
|
|
|
2100
2111
|
```ts highlight="7-9"
|
|
2101
2112
|
import { experimental_generateSpeech as generateSpeech } from 'ai';
|
|
2102
|
-
import { openai } from '@ai-sdk/openai';
|
|
2113
|
+
import { openai, type OpenAISpeechModelOptions } from '@ai-sdk/openai';
|
|
2103
2114
|
|
|
2104
2115
|
const result = await generateSpeech({
|
|
2105
2116
|
model: openai.speech('tts-1'),
|
|
@@ -2108,7 +2119,7 @@ const result = await generateSpeech({
|
|
|
2108
2119
|
providerOptions: {
|
|
2109
2120
|
openai: {
|
|
2110
2121
|
speed: 1.2,
|
|
2111
|
-
},
|
|
2122
|
+
} satisfies OpenAISpeechModelOptions,
|
|
2112
2123
|
},
|
|
2113
2124
|
});
|
|
2114
2125
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.27",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/provider": "3.0.
|
|
40
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
39
|
+
"@ai-sdk/provider": "3.0.8",
|
|
40
|
+
"@ai-sdk/provider-utils": "4.0.14"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "20.17.24",
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from './openai-chat-api';
|
|
38
38
|
import {
|
|
39
39
|
OpenAIChatModelId,
|
|
40
|
-
|
|
40
|
+
openaiLanguageModelChatOptions,
|
|
41
41
|
} from './openai-chat-options';
|
|
42
42
|
import { prepareChatTools } from './openai-chat-prepare-tools';
|
|
43
43
|
|
|
@@ -90,7 +90,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV3 {
|
|
|
90
90
|
(await parseProviderOptions({
|
|
91
91
|
provider: 'openai',
|
|
92
92
|
providerOptions,
|
|
93
|
-
schema:
|
|
93
|
+
schema: openaiLanguageModelChatOptions,
|
|
94
94
|
})) ?? {};
|
|
95
95
|
|
|
96
96
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
@@ -47,7 +47,7 @@ export type OpenAIChatModelId =
|
|
|
47
47
|
| 'gpt-5.2-pro'
|
|
48
48
|
| (string & {});
|
|
49
49
|
|
|
50
|
-
export const
|
|
50
|
+
export const openaiLanguageModelChatOptions = lazySchema(() =>
|
|
51
51
|
zodSchema(
|
|
52
52
|
z.object({
|
|
53
53
|
/**
|
|
@@ -181,6 +181,6 @@ export const openaiChatLanguageModelOptions = lazySchema(() =>
|
|
|
181
181
|
),
|
|
182
182
|
);
|
|
183
183
|
|
|
184
|
-
export type
|
|
185
|
-
typeof
|
|
184
|
+
export type OpenAILanguageModelChatOptions = InferSchema<
|
|
185
|
+
typeof openaiLanguageModelChatOptions
|
|
186
186
|
>;
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from './openai-completion-api';
|
|
33
33
|
import {
|
|
34
34
|
OpenAICompletionModelId,
|
|
35
|
-
|
|
35
|
+
openaiLanguageModelCompletionOptions,
|
|
36
36
|
} from './openai-completion-options';
|
|
37
37
|
|
|
38
38
|
type OpenAICompletionConfig = {
|
|
@@ -91,12 +91,12 @@ export class OpenAICompletionLanguageModel implements LanguageModelV3 {
|
|
|
91
91
|
...(await parseProviderOptions({
|
|
92
92
|
provider: 'openai',
|
|
93
93
|
providerOptions,
|
|
94
|
-
schema:
|
|
94
|
+
schema: openaiLanguageModelCompletionOptions,
|
|
95
95
|
})),
|
|
96
96
|
...(await parseProviderOptions({
|
|
97
97
|
provider: this.providerOptionsName,
|
|
98
98
|
providerOptions,
|
|
99
|
-
schema:
|
|
99
|
+
schema: openaiLanguageModelCompletionOptions,
|
|
100
100
|
})),
|
|
101
101
|
};
|
|
102
102
|
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod/v4';
|
|
|
4
4
|
// https://platform.openai.com/docs/models
|
|
5
5
|
export type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {});
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const openaiLanguageModelCompletionOptions = lazySchema(() =>
|
|
8
8
|
zodSchema(
|
|
9
9
|
z.object({
|
|
10
10
|
/**
|
|
@@ -53,6 +53,6 @@ export const openaiCompletionProviderOptions = lazySchema(() =>
|
|
|
53
53
|
),
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
-
export type
|
|
57
|
-
typeof
|
|
56
|
+
export type OpenAILanguageModelCompletionOptions = InferSchema<
|
|
57
|
+
typeof openaiLanguageModelCompletionOptions
|
|
58
58
|
>;
|
|
@@ -12,7 +12,7 @@ import { OpenAIConfig } from '../openai-config';
|
|
|
12
12
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
13
13
|
import {
|
|
14
14
|
OpenAIEmbeddingModelId,
|
|
15
|
-
|
|
15
|
+
openaiEmbeddingModelOptions,
|
|
16
16
|
} from './openai-embedding-options';
|
|
17
17
|
import { openaiTextEmbeddingResponseSchema } from './openai-embedding-api';
|
|
18
18
|
|
|
@@ -55,7 +55,7 @@ export class OpenAIEmbeddingModel implements EmbeddingModelV3 {
|
|
|
55
55
|
(await parseProviderOptions({
|
|
56
56
|
provider: 'openai',
|
|
57
57
|
providerOptions,
|
|
58
|
-
schema:
|
|
58
|
+
schema: openaiEmbeddingModelOptions,
|
|
59
59
|
})) ?? {};
|
|
60
60
|
|
|
61
61
|
const {
|
|
@@ -7,7 +7,7 @@ export type OpenAIEmbeddingModelId =
|
|
|
7
7
|
| 'text-embedding-ada-002'
|
|
8
8
|
| (string & {});
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const openaiEmbeddingModelOptions = lazySchema(() =>
|
|
11
11
|
zodSchema(
|
|
12
12
|
z.object({
|
|
13
13
|
/**
|
|
@@ -25,6 +25,6 @@ export const openaiEmbeddingProviderOptions = lazySchema(() =>
|
|
|
25
25
|
),
|
|
26
26
|
);
|
|
27
27
|
|
|
28
|
-
export type
|
|
29
|
-
typeof
|
|
28
|
+
export type OpenAIEmbeddingModelOptions = InferSchema<
|
|
29
|
+
typeof openaiEmbeddingModelOptions
|
|
30
30
|
>;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
export { createOpenAI, openai } from './openai-provider';
|
|
2
2
|
export type { OpenAIProvider, OpenAIProviderSettings } from './openai-provider';
|
|
3
|
-
export type {
|
|
4
|
-
|
|
3
|
+
export type {
|
|
4
|
+
OpenAILanguageModelResponsesOptions,
|
|
5
|
+
/** @deprecated Use `OpenAILanguageModelResponsesOptions` instead. */
|
|
6
|
+
OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions,
|
|
7
|
+
} from './responses/openai-responses-options';
|
|
8
|
+
export type {
|
|
9
|
+
OpenAILanguageModelChatOptions,
|
|
10
|
+
/** @deprecated Use `OpenAILanguageModelChatOptions` instead. */
|
|
11
|
+
OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions,
|
|
12
|
+
} from './chat/openai-chat-options';
|
|
13
|
+
export type { OpenAILanguageModelCompletionOptions } from './completion/openai-completion-options';
|
|
14
|
+
export type { OpenAIEmbeddingModelOptions } from './embedding/openai-embedding-options';
|
|
15
|
+
export type { OpenAISpeechModelOptions } from './speech/openai-speech-options';
|
|
16
|
+
export type { OpenAITranscriptionModelOptions } from './transcription/openai-transcription-options';
|
|
5
17
|
export type {
|
|
6
18
|
OpenaiResponsesProviderMetadata,
|
|
7
19
|
OpenaiResponsesReasoningProviderMetadata,
|
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
} from './openai-responses-api';
|
|
59
59
|
import {
|
|
60
60
|
OpenAIResponsesModelId,
|
|
61
|
-
|
|
61
|
+
openaiLanguageModelResponsesOptionsSchema,
|
|
62
62
|
TOP_LOGPROBS_MAX,
|
|
63
63
|
} from './openai-responses-options';
|
|
64
64
|
import { prepareResponsesTools } from './openai-responses-prepare-tools';
|
|
@@ -159,14 +159,14 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
159
159
|
let openaiOptions = await parseProviderOptions({
|
|
160
160
|
provider: providerOptionsName,
|
|
161
161
|
providerOptions,
|
|
162
|
-
schema:
|
|
162
|
+
schema: openaiLanguageModelResponsesOptionsSchema,
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
if (openaiOptions == null && providerOptionsName !== 'openai') {
|
|
166
166
|
openaiOptions = await parseProviderOptions({
|
|
167
167
|
provider: 'openai',
|
|
168
168
|
providerOptions,
|
|
169
|
-
schema:
|
|
169
|
+
schema: openaiLanguageModelResponsesOptionsSchema,
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -129,7 +129,7 @@ export type OpenAIResponsesModelId =
|
|
|
129
129
|
| (string & {});
|
|
130
130
|
|
|
131
131
|
// TODO AI SDK 6: use optional here instead of nullish
|
|
132
|
-
export const
|
|
132
|
+
export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
133
133
|
zodSchema(
|
|
134
134
|
z.object({
|
|
135
135
|
/**
|
|
@@ -307,6 +307,6 @@ export const openaiResponsesProviderOptionsSchema = lazySchema(() =>
|
|
|
307
307
|
),
|
|
308
308
|
);
|
|
309
309
|
|
|
310
|
-
export type
|
|
311
|
-
typeof
|
|
310
|
+
export type OpenAILanguageModelResponsesOptions = InferSchema<
|
|
311
|
+
typeof openaiLanguageModelResponsesOptionsSchema
|
|
312
312
|
>;
|
|
@@ -9,7 +9,7 @@ import { OpenAIConfig } from '../openai-config';
|
|
|
9
9
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
10
10
|
import { OpenAISpeechAPITypes } from './openai-speech-api';
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
openaiSpeechModelOptionsSchema,
|
|
13
13
|
OpenAISpeechModelId,
|
|
14
14
|
} from './openai-speech-options';
|
|
15
15
|
|
|
@@ -46,7 +46,7 @@ export class OpenAISpeechModel implements SpeechModelV3 {
|
|
|
46
46
|
const openAIOptions = await parseProviderOptions({
|
|
47
47
|
provider: 'openai',
|
|
48
48
|
providerOptions,
|
|
49
|
-
schema:
|
|
49
|
+
schema: openaiSpeechModelOptionsSchema,
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
// Create request body
|
|
@@ -8,7 +8,7 @@ export type OpenAISpeechModelId =
|
|
|
8
8
|
| (string & {});
|
|
9
9
|
|
|
10
10
|
// https://platform.openai.com/docs/api-reference/audio/createSpeech
|
|
11
|
-
export const
|
|
11
|
+
export const openaiSpeechModelOptionsSchema = lazySchema(() =>
|
|
12
12
|
zodSchema(
|
|
13
13
|
z.object({
|
|
14
14
|
instructions: z.string().nullish(),
|
|
@@ -17,6 +17,6 @@ export const openaiSpeechProviderOptionsSchema = lazySchema(() =>
|
|
|
17
17
|
),
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
export type
|
|
21
|
-
typeof
|
|
20
|
+
export type OpenAISpeechModelOptions = InferSchema<
|
|
21
|
+
typeof openaiSpeechModelOptionsSchema
|
|
22
22
|
>;
|
|
@@ -16,8 +16,8 @@ import { openaiFailedResponseHandler } from '../openai-error';
|
|
|
16
16
|
import { openaiTranscriptionResponseSchema } from './openai-transcription-api';
|
|
17
17
|
import {
|
|
18
18
|
OpenAITranscriptionModelId,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
openAITranscriptionModelOptions,
|
|
20
|
+
OpenAITranscriptionModelOptions,
|
|
21
21
|
} from './openai-transcription-options';
|
|
22
22
|
|
|
23
23
|
export type OpenAITranscriptionCallOptions = Omit<
|
|
@@ -25,7 +25,7 @@ export type OpenAITranscriptionCallOptions = Omit<
|
|
|
25
25
|
'providerOptions'
|
|
26
26
|
> & {
|
|
27
27
|
providerOptions?: {
|
|
28
|
-
openai?:
|
|
28
|
+
openai?: OpenAITranscriptionModelOptions;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -119,7 +119,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
|
|
|
119
119
|
const openAIOptions = await parseProviderOptions({
|
|
120
120
|
provider: 'openai',
|
|
121
121
|
providerOptions,
|
|
122
|
-
schema:
|
|
122
|
+
schema: openAITranscriptionModelOptions,
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
// Create form data with base fields
|
|
@@ -8,7 +8,7 @@ export type OpenAITranscriptionModelId =
|
|
|
8
8
|
| (string & {});
|
|
9
9
|
|
|
10
10
|
// https://platform.openai.com/docs/api-reference/audio/createTranscription
|
|
11
|
-
export const
|
|
11
|
+
export const openAITranscriptionModelOptions = lazySchema(() =>
|
|
12
12
|
zodSchema(
|
|
13
13
|
z.object({
|
|
14
14
|
/**
|
|
@@ -45,6 +45,6 @@ export const openAITranscriptionProviderOptions = lazySchema(() =>
|
|
|
45
45
|
),
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
export type
|
|
49
|
-
typeof
|
|
48
|
+
export type OpenAITranscriptionModelOptions = InferSchema<
|
|
49
|
+
typeof openAITranscriptionModelOptions
|
|
50
50
|
>;
|