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
624624You can pass them in the ` providerOptions ` argument:
625625
626626``` ts
627+ import { openai , type OpenAIChatLanguageModelOptions } from ' @ai-sdk/openai' ;
628+
627629const model = openai .chat (' gpt-5' );
628630
629631await generateText ({
@@ -635,7 +637,7 @@ await generateText({
635637 ' 50256' : - 100 ,
636638 },
637639 user: ' test-user' , // optional unique user identifier
638- },
640+ } satisfies OpenAIChatLanguageModelOptions ,
639641 },
640642});
641643```
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';
3030import { mapOpenAIFinishReason } from './map-openai-finish-reason' ;
3131import {
3232 OpenAIChatModelId ,
33- openaiProviderOptions ,
33+ openaiChatLanguageModelOptions ,
3434} from './openai-chat-options' ;
3535import { prepareChatTools } from './openai-chat-prepare-tools' ;
3636
@@ -83,7 +83,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV2 {
8383 ( await parseProviderOptions ( {
8484 provider : 'openai' ,
8585 providerOptions,
86- schema : openaiProviderOptions ,
86+ schema : openaiChatLanguageModelOptions ,
8787 } ) ) ?? { } ;
8888
8989 const structuredOutputs = openaiOptions . structuredOutputs ?? true ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export type OpenAIChatModelId =
3939 | 'gpt-5-chat-latest'
4040 | ( string & { } ) ;
4141
42- export const openaiProviderOptions = z . object ( {
42+ export const openaiChatLanguageModelOptions = z . object ( {
4343 /**
4444 * Modify the likelihood of specified tokens appearing in the completion.
4545 *
@@ -141,4 +141,6 @@ export const openaiProviderOptions = z.object({
141141 safetyIdentifier : z . string ( ) . optional ( ) ,
142142} ) ;
143143
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 11export { createOpenAI , openai } from './openai-provider' ;
22export type { OpenAIProvider , OpenAIProviderSettings } from './openai-provider' ;
33export type { OpenAIResponsesProviderOptions } from './responses/openai-responses-language-model' ;
4+ export type { OpenAIChatLanguageModelOptions } from './chat/openai-chat-options' ;
45export { VERSION } from './version' ;
You can’t perform that action at this time.
0 commit comments