@ai-sdk/openai 4.0.101 → 4.0.103
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 +20 -0
- package/README.md +3 -40
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +87 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +11 -6
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +6 -0
- package/package.json +3 -3
- package/src/completion/convert-to-openai-completion-prompt.ts +1 -1
- package/src/internal/index.ts +1 -0
- package/src/responses/openai-responses-language-model.ts +15 -0
- package/src/responses/openai-responses-prepare-tools.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.103
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 02dbab1: add azure.tools.toolSearch and support azure provider options on responses function tools
|
|
8
|
+
- 27a53b4: Fix string interpolation in Amazon Bedrock unsupported provider tool warnings and OpenAI / OpenAI-compatible completion errors for unexpected system messages.
|
|
9
|
+
- Updated dependencies [e64ed82]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.69
|
|
11
|
+
|
|
12
|
+
## 4.0.102
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 5475347: Fix non-streaming Responses API structured output failing when multiple assistant messages contain JSON. Providers can supply separate structured-output text for parsing, allowing OpenAI and Azure Responses models to select the last `final_answer` while preserving all generated content, annotations, conversation history, and token usage.
|
|
17
|
+
- e729d58: chore(docs): update `README.md` for consistent format and to avoid duplication
|
|
18
|
+
- Updated dependencies [5475347]
|
|
19
|
+
- Updated dependencies [e729d58]
|
|
20
|
+
- @ai-sdk/provider@4.0.34
|
|
21
|
+
- @ai-sdk/provider-utils@5.0.68
|
|
22
|
+
|
|
3
23
|
## 4.0.101
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -7,10 +7,8 @@ contains language model support for the OpenAI chat and completion APIs and embe
|
|
|
7
7
|
|
|
8
8
|
## Setup
|
|
9
9
|
|
|
10
|
-
The OpenAI provider is available in the `@ai-sdk/openai` module. You can install it with
|
|
11
|
-
|
|
12
10
|
```bash
|
|
13
|
-
npm i @ai-sdk/openai
|
|
11
|
+
npm i ai @ai-sdk/openai
|
|
14
12
|
```
|
|
15
13
|
|
|
16
14
|
## Skill for Coding Agents
|
|
@@ -21,15 +19,7 @@ If you use coding agents such as Claude Code or Cursor, we highly recommend addi
|
|
|
21
19
|
npx skills add vercel/ai
|
|
22
20
|
```
|
|
23
21
|
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
You can import the default provider instance `openai` from `@ai-sdk/openai`:
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
import { openai } from '@ai-sdk/openai';
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Example
|
|
22
|
+
## Usage
|
|
33
23
|
|
|
34
24
|
```ts
|
|
35
25
|
import { openai } from '@ai-sdk/openai';
|
|
@@ -41,31 +31,4 @@ const { text } = await generateText({
|
|
|
41
31
|
});
|
|
42
32
|
```
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Experimental realtime models
|
|
47
|
-
|
|
48
|
-
Use the same factory for OpenAI Realtime and Live models:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
openai.experimental_realtime('gpt-realtime');
|
|
52
|
-
openai.experimental_realtime('gpt-live-1');
|
|
53
|
-
openai.experimental_realtime('not-yet-released', { api: 'live' });
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Live supports browser WSS sessions through an application-owned relay and
|
|
57
|
-
`experimental_useRealtime`, with client delegation: your application owns the
|
|
58
|
-
agent and tools. Optional browser-direct WebRTC is also available. Start with the
|
|
59
|
-
[OpenAI provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/openai#realtime-models)
|
|
60
|
-
for connection settings, startup options, and event mapping.
|
|
61
|
-
|
|
62
|
-
The [`experimental_useRealtime` reference](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-realtime#continuous-conversations)
|
|
63
|
-
covers the JSON/PCM16 relay runtime, capture/playback controls, and application-handled
|
|
64
|
-
client delegation, plus `api.session` WebRTC setup and server-owned data-channel
|
|
65
|
-
permissions. Microphone capture requires browser permission; the application handles
|
|
66
|
-
client delegation and submits context on either transport. The
|
|
67
|
-
[Realtime guide](https://ai-sdk.dev/docs/ai-sdk-core/realtime) covers legacy token-based,
|
|
68
|
-
turn-based sessions.
|
|
69
|
-
|
|
70
|
-
Runtime and provider authors can consult the repository's
|
|
71
|
-
[realtime integration notes](../../architecture/realtime-provider-integration.md).
|
|
34
|
+
See the [OpenAI Provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/openai) for more information.
|
package/dist/index.js
CHANGED
|
@@ -1592,7 +1592,7 @@ function convertToOpenAICompletionPrompt({ prompt, user = "user", assistant = "a
|
|
|
1592
1592
|
}
|
|
1593
1593
|
for (const { role, content } of prompt) switch (role) {
|
|
1594
1594
|
case "system": throw new InvalidPromptError({
|
|
1595
|
-
message:
|
|
1595
|
+
message: `Unexpected system message in prompt: ${content}`,
|
|
1596
1596
|
prompt
|
|
1597
1597
|
});
|
|
1598
1598
|
case "user": {
|
|
@@ -5685,7 +5685,7 @@ function mapOpenAIResponsesCitations(annotations, providerOptionsName) {
|
|
|
5685
5685
|
}
|
|
5686
5686
|
//#endregion
|
|
5687
5687
|
//#region src/responses/openai-responses-prepare-tools.ts
|
|
5688
|
-
async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolNameMapping, customProviderToolNames, outputSchemaToolNames, supportsAsyncToolCalling = true }) {
|
|
5688
|
+
async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolNameMapping, customProviderToolNames, outputSchemaToolNames, supportsAsyncToolCalling = true, providerOptionsName = "openai" }) {
|
|
5689
5689
|
tools = tools?.length ? tools : void 0;
|
|
5690
5690
|
const toolWarnings = [];
|
|
5691
5691
|
if (tools == null) return {
|
|
@@ -5707,7 +5707,7 @@ async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolName
|
|
|
5707
5707
|
};
|
|
5708
5708
|
for (const tool of tools) switch (tool.type) {
|
|
5709
5709
|
case "function": {
|
|
5710
|
-
const openaiOptions = tool.providerOptions?.openai;
|
|
5710
|
+
const openaiOptions = tool.providerOptions?.[providerOptionsName] ?? tool.providerOptions?.openai;
|
|
5711
5711
|
if (openaiOptions?.outputSchema != null) outputSchemaToolNames?.add(tool.name);
|
|
5712
5712
|
if (openaiOptions?.omitFromRequestTools === true) {
|
|
5713
5713
|
recordAllowedTool(tool.name, {
|
|
@@ -6323,7 +6323,8 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6323
6323
|
toolNameMapping,
|
|
6324
6324
|
customProviderToolNames,
|
|
6325
6325
|
outputSchemaToolNames,
|
|
6326
|
-
supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
|
|
6326
|
+
supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling,
|
|
6327
|
+
providerOptionsName
|
|
6327
6328
|
});
|
|
6328
6329
|
const configurationUpdateUnsupportedReason = getConfigurationUpdateUnsupportedReason({
|
|
6329
6330
|
modelCapabilities,
|
|
@@ -6584,6 +6585,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6584
6585
|
const retrievedFileIds = /* @__PURE__ */ new Set();
|
|
6585
6586
|
let hasFunctionCall = false;
|
|
6586
6587
|
const hostedToolSearchCallIds = [];
|
|
6588
|
+
let structuredOutputText;
|
|
6587
6589
|
for (const part of response.output) switch (part.type) {
|
|
6588
6590
|
case "reasoning":
|
|
6589
6591
|
if (part.summary.length === 0) part.summary.push({
|
|
@@ -6684,6 +6686,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6684
6686
|
});
|
|
6685
6687
|
break;
|
|
6686
6688
|
case "message":
|
|
6689
|
+
if (options.responseFormat?.type === "json" && part.phase === "final_answer") structuredOutputText = part.content.map((contentPart) => contentPart.text).join("");
|
|
6687
6690
|
for (const contentPart of part.content) {
|
|
6688
6691
|
if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) logprobs.push(contentPart.logprobs);
|
|
6689
6692
|
const providerMetadata = {
|
|
@@ -6970,6 +6973,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6970
6973
|
const usage = response.usage;
|
|
6971
6974
|
return {
|
|
6972
6975
|
content,
|
|
6976
|
+
...structuredOutputText !== void 0 && { structuredOutputText },
|
|
6973
6977
|
finishReason: {
|
|
6974
6978
|
unified: mapOpenAIResponseFinishReason({
|
|
6975
6979
|
finishReason: response.incomplete_details?.reason,
|
|
@@ -10248,7 +10252,7 @@ var OpenAISkills = class {
|
|
|
10248
10252
|
};
|
|
10249
10253
|
//#endregion
|
|
10250
10254
|
//#region src/version.ts
|
|
10251
|
-
const VERSION = "4.0.
|
|
10255
|
+
const VERSION = "4.0.103";
|
|
10252
10256
|
//#endregion
|
|
10253
10257
|
//#region src/openai-provider.ts
|
|
10254
10258
|
/**
|