File tree Expand file tree Collapse file tree 6 files changed +63
-5
lines changed
content/providers/01-ai-sdk-providers
examples/ai-core/src/generate-text Expand file tree Collapse file tree 6 files changed +63
-5
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @ai-sdk/openai ' : patch
3
+ ---
4
+
5
+ feat(provider/openai): ` OpenAIChatLanguageModelOptions ` type
6
+
7
+ ``` ts
8
+ import { openai , type OpenAIChatLanguageModelOptions } from ' @ai-sdk/openai' ;
9
+ import { generateText } from ' ai' ;
10
+
11
+ await generateText ({
12
+ model: openai .chat (' gpt-4o' ),
13
+ prompt: ' Invent a new holiday and describe its traditions.' ,
14
+ providerOptions: {
15
+ openai: {
16
+ user: ' user-123' ,
17
+ } satisfies OpenAIChatLanguageModelOptions ,
18
+ },
19
+ });
20
+ ```
Original file line number Diff line number Diff line change @@ -624,6 +624,8 @@ OpenAI chat models support also some model specific provider options that are no
624
624
You can pass them in the ` providerOptions ` argument:
625
625
626
626
``` ts
627
+ import { openai , type OpenAIChatLanguageModelOptions } from ' @ai-sdk/openai' ;
628
+
627
629
const model = openai .chat (' gpt-5' );
628
630
629
631
await generateText ({
@@ -635,7 +637,7 @@ await generateText({
635
637
' 50256' : - 100 ,
636
638
},
637
639
user: ' test-user' , // optional unique user identifier
638
- },
640
+ } satisfies OpenAIChatLanguageModelOptions ,
639
641
},
640
642
});
641
643
```
Original file line number Diff line number Diff line change
1
+ import { openai , type OpenAIChatLanguageModelOptions } from '@ai-sdk/openai' ;
2
+ import { generateText } from 'ai' ;
3
+ import 'dotenv/config' ;
4
+
5
+ async function main ( ) {
6
+ const { text, usage } = await generateText ( {
7
+ model : openai . chat ( 'gpt-4o' ) ,
8
+ prompt : 'Invent a new holiday and describe its traditions.' ,
9
+ providerOptions : {
10
+ openai : {
11
+ logitBias : { } ,
12
+ logprobs : 1 ,
13
+ user : '<user_id>' ,
14
+ maxCompletionTokens : 100 ,
15
+ store : false ,
16
+ structuredOutputs : false ,
17
+ serviceTier : 'auto' ,
18
+ strictJsonSchema : false ,
19
+ textVerbosity : 'medium' ,
20
+ promptCacheKey : '<prompt_cache_key>' ,
21
+ safetyIdentifier : '<safety_identifier>' ,
22
+ // @ts -expect-error
23
+ invalidOption : null ,
24
+ } satisfies OpenAIChatLanguageModelOptions ,
25
+ } ,
26
+ } ) ;
27
+
28
+ console . log ( text ) ;
29
+ console . log ( ) ;
30
+ console . log ( 'Usage:' , usage ) ;
31
+ }
32
+
33
+ main ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import { getResponseMetadata } from './get-response-metadata';
30
30
import { mapOpenAIFinishReason } from './map-openai-finish-reason' ;
31
31
import {
32
32
OpenAIChatModelId ,
33
- openaiProviderOptions ,
33
+ openaiChatLanguageModelOptions ,
34
34
} from './openai-chat-options' ;
35
35
import { prepareChatTools } from './openai-chat-prepare-tools' ;
36
36
@@ -83,7 +83,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV2 {
83
83
( await parseProviderOptions ( {
84
84
provider : 'openai' ,
85
85
providerOptions,
86
- schema : openaiProviderOptions ,
86
+ schema : openaiChatLanguageModelOptions ,
87
87
} ) ) ?? { } ;
88
88
89
89
const structuredOutputs = openaiOptions . structuredOutputs ?? true ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export type OpenAIChatModelId =
39
39
| 'gpt-5-chat-latest'
40
40
| ( string & { } ) ;
41
41
42
- export const openaiProviderOptions = z . object ( {
42
+ export const openaiChatLanguageModelOptions = z . object ( {
43
43
/**
44
44
* Modify the likelihood of specified tokens appearing in the completion.
45
45
*
@@ -141,4 +141,6 @@ export const openaiProviderOptions = z.object({
141
141
safetyIdentifier : z . string ( ) . optional ( ) ,
142
142
} ) ;
143
143
144
- export type OpenAIProviderOptions = z . infer < typeof openaiProviderOptions > ;
144
+ export type OpenAIChatLanguageModelOptions = z . infer <
145
+ typeof openaiChatLanguageModelOptions
146
+ > ;
Original file line number Diff line number Diff line change 1
1
export { createOpenAI , openai } from './openai-provider' ;
2
2
export type { OpenAIProvider , OpenAIProviderSettings } from './openai-provider' ;
3
3
export type { OpenAIResponsesProviderOptions } from './responses/openai-responses-language-model' ;
4
+ export type { OpenAIChatLanguageModelOptions } from './chat/openai-chat-options' ;
4
5
export { VERSION } from './version' ;
You can’t perform that action at this time.
0 commit comments