Skip to content

Commit 58d701f

Browse files
Backport: docs: fix openai provider section of migration guide (#9592)
This is an automated backport of #9590 to the release-v5.0 branch. Co-authored-by: Nico Albanese <49612682+nicoalbanese@users.noreply.github.com>
1 parent 7a6b549 commit 58d701f

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

content/docs/08-migration-guides/26-migration-guide-5-0.mdx

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,33 +3049,105 @@ return createUIMessageStreamResponse({ stream });
30493049

30503050
### OpenAI
30513051

3052-
#### Structured Outputs
3052+
#### Default Provider Instance Uses Responses API
30533053

3054-
The `structuredOutputs` parameter has been replaced with the `strictJsonSchema` provider option. It is now disabled by default.
3054+
In AI SDK 5, the default OpenAI provider instance uses the Responses API, while AI SDK 4 used the Chat Completions API. The Chat Completions API remains fully supported and you can use it with `openai.chat(...)`.
30553055

30563056
```tsx filename="AI SDK 4.0"
30573057
import { openai } from '@ai-sdk/openai';
30583058

3059+
const defaultModel = openai('gpt-4.1-mini'); // Chat Completions API
3060+
```
3061+
3062+
```tsx filename="AI SDK 5.0"
3063+
import { openai } from '@ai-sdk/openai';
3064+
3065+
const defaultModel = openai('gpt-4.1-mini'); // Responses API
3066+
3067+
// Specify a specific API when needed:
3068+
const chatCompletionsModel = openai.chat('gpt-4.1-mini');
3069+
const responsesModel = openai.responses('gpt-4.1-mini');
3070+
```
3071+
3072+
<Note>
3073+
The Responses and Chat Completions APIs have different behavior and defaults.
3074+
If you depend on the Chat Completions API, switch your model instance to
3075+
`openai.chat(...)` and audit your configuration.
3076+
</Note>
3077+
3078+
#### Strict Schemas (`strictSchemas`) with Responses API
3079+
3080+
In AI SDK 4.0, you could set the `strictSchemas` option on Responses models (which defaulted to `true`). This option has been renamed to `strictJsonSchema` in AI SDK 5.0 and now defaults to `false`.
3081+
3082+
```tsx filename="AI SDK 4.0"
3083+
import { z } from 'zod';
3084+
import { generateObject } from 'ai';
3085+
import { openai, type OpenAIResponsesProviderOptions } from '@ai-sdk/openai';
3086+
30593087
const result = await generateObject({
3060-
model: openai('gpt-4.1-2024-08-06', { structuredOutputs: true }),
3061-
schema: z.object({ name: z.string() }),
3088+
model: openai.responses('gpt-4.1'),
3089+
schema: z.object({
3090+
// ...
3091+
}),
3092+
providerOptions: {
3093+
openai: {
3094+
strictSchemas: true, // default behaviour in AI SDK 4
3095+
} satisfies OpenAIResponsesProviderOptions,
3096+
},
30623097
});
30633098
```
30643099

30653100
```tsx filename="AI SDK 5.0"
3101+
import { z } from 'zod';
3102+
import { generateObject } from 'ai';
30663103
import { openai, type OpenAIResponsesProviderOptions } from '@ai-sdk/openai';
30673104

30683105
const result = await generateObject({
3069-
model: openai('gpt-4.1-2024-08-06'),
3070-
schema: z.object({ name: z.string() }),
3106+
model: openai('gpt-4.1-2024'), // uses Responses API
3107+
schema: z.object({
3108+
// ...
3109+
}),
30713110
providerOptions: {
30723111
openai: {
3073-
strictJsonSchema: true, // renamed and opt-in via provider options
3112+
strictJsonSchema: true, // defaults to false, opt back in to the AI SDK 4 strict behaviour
30743113
} satisfies OpenAIResponsesProviderOptions,
30753114
},
30763115
});
30773116
```
30783117

3118+
If you call `openai.chat(...)` to use the Chat Completions API directly, you can type it with `OpenAIChatLanguageModelOptions`. AI SDK 5 adds the same `strictJsonSchema` option there as well.
3119+
3120+
#### Structured Outputs
3121+
3122+
The `structuredOutputs` option is now configured using provider options rather than as a setting on the model instance.
3123+
3124+
```tsx filename="AI SDK 4.0"
3125+
import { z } from 'zod';
3126+
import { generateObject } from 'ai';
3127+
import { openai } from '@ai-sdk/openai';
3128+
3129+
const result = await generateObject({
3130+
model: openai('gpt-4.1', { structuredOutputs: true }), // use Chat Completions API
3131+
schema: z.object({ name: z.string() }),
3132+
});
3133+
```
3134+
3135+
```tsx filename="AI SDK 5.0 (Chat Completions API)"
3136+
import { z } from 'zod';
3137+
import { generateObject } from 'ai';
3138+
import { openai, type OpenAIChatLanguageModelOptions } from '@ai-sdk/openai';
3139+
3140+
const result = await generateObject({
3141+
model: openai.chat('gpt-4.1'), // use Chat Completions API
3142+
schema: z.object({ name: z.string() }),
3143+
providerOptions: {
3144+
openai: {
3145+
structuredOutputs: true,
3146+
} satisfies OpenAIChatLanguageModelOptions,
3147+
},
3148+
});
3149+
```
3150+
30793151
#### Compatibility Option Removal
30803152

30813153
The `compatibility` option has been removed; strict compatibility mode is now the default.

0 commit comments

Comments
 (0)