@ai-sdk/openai 4.0.0-beta.12 → 4.0.0-beta.15
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 +23 -0
- package/dist/index.d.mts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -28
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +24 -2
- package/dist/internal/index.d.ts +24 -2
- package/dist/internal/index.js +65 -27
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +67 -27
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +2 -0
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model.ts +10 -2
- package/src/chat/openai-chat-options.ts +4 -0
- package/src/openai-language-model-capabilities.ts +2 -2
- package/src/responses/openai-responses-api.ts +25 -0
- package/src/responses/openai-responses-language-model.ts +29 -4
- package/src/responses/openai-responses-options.ts +8 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createEventSourceResponseHandler,
|
|
8
8
|
createJsonResponseHandler,
|
|
9
9
|
generateId,
|
|
10
|
+
isCustomReasoning,
|
|
10
11
|
isParsableJson,
|
|
11
12
|
parseProviderOptions,
|
|
12
13
|
postJsonToApi
|
|
@@ -34,7 +35,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
34
35
|
// src/openai-language-model-capabilities.ts
|
|
35
36
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
36
37
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
37
|
-
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5
|
|
38
|
+
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") && !modelId.startsWith("gpt-5.4-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
38
39
|
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
39
40
|
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4");
|
|
40
41
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
@@ -654,9 +655,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
654
655
|
seed,
|
|
655
656
|
tools,
|
|
656
657
|
toolChoice,
|
|
658
|
+
reasoning,
|
|
657
659
|
providerOptions
|
|
658
660
|
}) {
|
|
659
|
-
var _a, _b, _c, _d, _e;
|
|
661
|
+
var _a, _b, _c, _d, _e, _f;
|
|
660
662
|
const warnings = [];
|
|
661
663
|
const openaiOptions = (_a = await parseProviderOptions({
|
|
662
664
|
provider: "openai",
|
|
@@ -664,18 +666,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
664
666
|
schema: openaiLanguageModelChatOptions
|
|
665
667
|
})) != null ? _a : {};
|
|
666
668
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
667
|
-
const
|
|
669
|
+
const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
|
|
670
|
+
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
668
671
|
if (topK != null) {
|
|
669
672
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
670
673
|
}
|
|
671
674
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
672
675
|
{
|
|
673
676
|
prompt,
|
|
674
|
-
systemMessageMode: (
|
|
677
|
+
systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
|
|
675
678
|
}
|
|
676
679
|
);
|
|
677
680
|
warnings.push(...messageWarnings);
|
|
678
|
-
const strictJsonSchema = (
|
|
681
|
+
const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
679
682
|
const baseArgs = {
|
|
680
683
|
// model id:
|
|
681
684
|
model: this.modelId,
|
|
@@ -696,7 +699,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
696
699
|
json_schema: {
|
|
697
700
|
schema: responseFormat.schema,
|
|
698
701
|
strict: strictJsonSchema,
|
|
699
|
-
name: (
|
|
702
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
700
703
|
description: responseFormat.description
|
|
701
704
|
}
|
|
702
705
|
} : { type: "json_object" } : void 0,
|
|
@@ -709,7 +712,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
709
712
|
store: openaiOptions.store,
|
|
710
713
|
metadata: openaiOptions.metadata,
|
|
711
714
|
prediction: openaiOptions.prediction,
|
|
712
|
-
reasoning_effort:
|
|
715
|
+
reasoning_effort: resolvedReasoningEffort,
|
|
713
716
|
service_tier: openaiOptions.serviceTier,
|
|
714
717
|
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
715
718
|
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
@@ -718,7 +721,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
718
721
|
messages
|
|
719
722
|
};
|
|
720
723
|
if (isReasoningModel) {
|
|
721
|
-
if (
|
|
724
|
+
if (resolvedReasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
722
725
|
if (baseArgs.temperature != null) {
|
|
723
726
|
baseArgs.temperature = void 0;
|
|
724
727
|
warnings.push({
|
|
@@ -2338,6 +2341,7 @@ import {
|
|
|
2338
2341
|
createJsonResponseHandler as createJsonResponseHandler6,
|
|
2339
2342
|
createToolNameMapping,
|
|
2340
2343
|
generateId as generateId2,
|
|
2344
|
+
isCustomReasoning as isCustomReasoning2,
|
|
2341
2345
|
parseProviderOptions as parseProviderOptions7,
|
|
2342
2346
|
postJsonToApi as postJsonToApi6
|
|
2343
2347
|
} from "@ai-sdk/provider-utils";
|
|
@@ -3289,6 +3293,23 @@ var openaiResponsesChunkSchema = lazySchema15(
|
|
|
3289
3293
|
service_tier: z17.string().nullish()
|
|
3290
3294
|
})
|
|
3291
3295
|
}),
|
|
3296
|
+
z17.object({
|
|
3297
|
+
type: z17.literal("response.failed"),
|
|
3298
|
+
response: z17.object({
|
|
3299
|
+
error: z17.object({
|
|
3300
|
+
code: z17.string().nullish(),
|
|
3301
|
+
message: z17.string()
|
|
3302
|
+
}).nullish(),
|
|
3303
|
+
incomplete_details: z17.object({ reason: z17.string() }).nullish(),
|
|
3304
|
+
usage: z17.object({
|
|
3305
|
+
input_tokens: z17.number(),
|
|
3306
|
+
input_tokens_details: z17.object({ cached_tokens: z17.number().nullish() }).nullish(),
|
|
3307
|
+
output_tokens: z17.number(),
|
|
3308
|
+
output_tokens_details: z17.object({ reasoning_tokens: z17.number().nullish() }).nullish()
|
|
3309
|
+
}).nullish(),
|
|
3310
|
+
service_tier: z17.string().nullish()
|
|
3311
|
+
})
|
|
3312
|
+
}),
|
|
3292
3313
|
z17.object({
|
|
3293
3314
|
type: z17.literal("response.created"),
|
|
3294
3315
|
response: z17.object({
|
|
@@ -4121,6 +4142,10 @@ var openaiResponsesReasoningModelIds = [
|
|
|
4121
4142
|
"gpt-5.3-codex",
|
|
4122
4143
|
"gpt-5.4",
|
|
4123
4144
|
"gpt-5.4-2026-03-05",
|
|
4145
|
+
"gpt-5.4-mini",
|
|
4146
|
+
"gpt-5.4-mini-2026-03-17",
|
|
4147
|
+
"gpt-5.4-nano",
|
|
4148
|
+
"gpt-5.4-nano-2026-03-17",
|
|
4124
4149
|
"gpt-5.4-pro",
|
|
4125
4150
|
"gpt-5.4-pro-2026-03-05"
|
|
4126
4151
|
];
|
|
@@ -4972,12 +4997,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4972
4997
|
frequencyPenalty,
|
|
4973
4998
|
seed,
|
|
4974
4999
|
prompt,
|
|
5000
|
+
reasoning,
|
|
4975
5001
|
providerOptions,
|
|
4976
5002
|
tools,
|
|
4977
5003
|
toolChoice,
|
|
4978
5004
|
responseFormat
|
|
4979
5005
|
}) {
|
|
4980
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5006
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4981
5007
|
const warnings = [];
|
|
4982
5008
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
4983
5009
|
if (topK != null) {
|
|
@@ -5008,7 +5034,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5008
5034
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5009
5035
|
});
|
|
5010
5036
|
}
|
|
5011
|
-
const
|
|
5037
|
+
const resolvedReasoningEffort = (_a = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
5038
|
+
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
5012
5039
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
5013
5040
|
warnings.push({
|
|
5014
5041
|
type: "unsupported",
|
|
@@ -5045,10 +5072,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5045
5072
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
5046
5073
|
prompt,
|
|
5047
5074
|
toolNameMapping,
|
|
5048
|
-
systemMessageMode: (
|
|
5075
|
+
systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
5049
5076
|
providerOptionsName,
|
|
5050
5077
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
5051
|
-
store: (
|
|
5078
|
+
store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
|
|
5052
5079
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
5053
5080
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
5054
5081
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
@@ -5056,7 +5083,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5056
5083
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
5057
5084
|
});
|
|
5058
5085
|
warnings.push(...inputWarnings);
|
|
5059
|
-
const strictJsonSchema = (
|
|
5086
|
+
const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
5060
5087
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
5061
5088
|
function addInclude(key) {
|
|
5062
5089
|
if (include == null) {
|
|
@@ -5072,9 +5099,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5072
5099
|
if (topLogprobs) {
|
|
5073
5100
|
addInclude("message.output_text.logprobs");
|
|
5074
5101
|
}
|
|
5075
|
-
const webSearchToolName = (
|
|
5102
|
+
const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
|
|
5076
5103
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
5077
|
-
)) == null ? void 0 :
|
|
5104
|
+
)) == null ? void 0 : _f.name;
|
|
5078
5105
|
if (webSearchToolName) {
|
|
5079
5106
|
addInclude("web_search_call.action.sources");
|
|
5080
5107
|
}
|
|
@@ -5097,7 +5124,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5097
5124
|
format: responseFormat.schema != null ? {
|
|
5098
5125
|
type: "json_schema",
|
|
5099
5126
|
strict: strictJsonSchema,
|
|
5100
|
-
name: (
|
|
5127
|
+
name: (_g = responseFormat.name) != null ? _g : "response",
|
|
5101
5128
|
description: responseFormat.description,
|
|
5102
5129
|
schema: responseFormat.schema
|
|
5103
5130
|
} : { type: "json_object" }
|
|
@@ -5131,10 +5158,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5131
5158
|
}))
|
|
5132
5159
|
},
|
|
5133
5160
|
// model-specific settings:
|
|
5134
|
-
...isReasoningModel && (
|
|
5161
|
+
...isReasoningModel && (resolvedReasoningEffort != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
5135
5162
|
reasoning: {
|
|
5136
|
-
...
|
|
5137
|
-
effort:
|
|
5163
|
+
...resolvedReasoningEffort != null && {
|
|
5164
|
+
effort: resolvedReasoningEffort
|
|
5138
5165
|
},
|
|
5139
5166
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
5140
5167
|
summary: openaiOptions.reasoningSummary
|
|
@@ -5143,7 +5170,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5143
5170
|
}
|
|
5144
5171
|
};
|
|
5145
5172
|
if (isReasoningModel) {
|
|
5146
|
-
if (!(
|
|
5173
|
+
if (!(resolvedReasoningEffort === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
5147
5174
|
if (baseArgs.temperature != null) {
|
|
5148
5175
|
baseArgs.temperature = void 0;
|
|
5149
5176
|
warnings.push({
|
|
@@ -5193,9 +5220,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5193
5220
|
});
|
|
5194
5221
|
delete baseArgs.service_tier;
|
|
5195
5222
|
}
|
|
5196
|
-
const shellToolEnvType = (
|
|
5223
|
+
const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
|
|
5197
5224
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
5198
|
-
)) == null ? void 0 :
|
|
5225
|
+
)) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
|
|
5199
5226
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
5200
5227
|
return {
|
|
5201
5228
|
webSearchToolName,
|
|
@@ -5751,7 +5778,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5751
5778
|
controller.enqueue({ type: "stream-start", warnings });
|
|
5752
5779
|
},
|
|
5753
5780
|
transform(chunk, controller) {
|
|
5754
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
|
|
5781
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
|
|
5755
5782
|
if (options.includeRawChunks) {
|
|
5756
5783
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
5757
5784
|
}
|
|
@@ -6488,13 +6515,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6488
6515
|
if (typeof value.response.service_tier === "string") {
|
|
6489
6516
|
serviceTier = value.response.service_tier;
|
|
6490
6517
|
}
|
|
6518
|
+
} else if (isResponseFailedChunk(value)) {
|
|
6519
|
+
const incompleteReason = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason;
|
|
6520
|
+
finishReason = {
|
|
6521
|
+
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
6522
|
+
finishReason: incompleteReason,
|
|
6523
|
+
hasFunctionCall
|
|
6524
|
+
}) : "error",
|
|
6525
|
+
raw: incompleteReason != null ? incompleteReason : "error"
|
|
6526
|
+
};
|
|
6527
|
+
usage = (_z = value.response.usage) != null ? _z : void 0;
|
|
6491
6528
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
6492
6529
|
ongoingAnnotations.push(value.annotation);
|
|
6493
6530
|
if (value.annotation.type === "url_citation") {
|
|
6494
6531
|
controller.enqueue({
|
|
6495
6532
|
type: "source",
|
|
6496
6533
|
sourceType: "url",
|
|
6497
|
-
id: (
|
|
6534
|
+
id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
|
|
6498
6535
|
url: value.annotation.url,
|
|
6499
6536
|
title: value.annotation.title
|
|
6500
6537
|
});
|
|
@@ -6502,7 +6539,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6502
6539
|
controller.enqueue({
|
|
6503
6540
|
type: "source",
|
|
6504
6541
|
sourceType: "document",
|
|
6505
|
-
id: (
|
|
6542
|
+
id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId2(),
|
|
6506
6543
|
mediaType: "text/plain",
|
|
6507
6544
|
title: value.annotation.filename,
|
|
6508
6545
|
filename: value.annotation.filename,
|
|
@@ -6518,7 +6555,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6518
6555
|
controller.enqueue({
|
|
6519
6556
|
type: "source",
|
|
6520
6557
|
sourceType: "document",
|
|
6521
|
-
id: (
|
|
6558
|
+
id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
|
|
6522
6559
|
mediaType: "text/plain",
|
|
6523
6560
|
title: value.annotation.filename,
|
|
6524
6561
|
filename: value.annotation.filename,
|
|
@@ -6534,7 +6571,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6534
6571
|
controller.enqueue({
|
|
6535
6572
|
type: "source",
|
|
6536
6573
|
sourceType: "document",
|
|
6537
|
-
id: (
|
|
6574
|
+
id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
|
|
6538
6575
|
mediaType: "application/octet-stream",
|
|
6539
6576
|
title: value.annotation.file_id,
|
|
6540
6577
|
filename: value.annotation.file_id,
|
|
@@ -6582,6 +6619,9 @@ function isResponseOutputItemDoneChunk(chunk) {
|
|
|
6582
6619
|
function isResponseFinishedChunk(chunk) {
|
|
6583
6620
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
6584
6621
|
}
|
|
6622
|
+
function isResponseFailedChunk(chunk) {
|
|
6623
|
+
return chunk.type === "response.failed";
|
|
6624
|
+
}
|
|
6585
6625
|
function isResponseCreatedChunk(chunk) {
|
|
6586
6626
|
return chunk.type === "response.created";
|
|
6587
6627
|
}
|