@ai-sdk/openai 4.0.59 → 4.0.60
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 +6 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +81 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +15 -9
- package/dist/internal/index.js +80 -6
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +66 -1
- package/package.json +1 -1
- package/src/chat/openai-chat-language-model.ts +29 -1
- package/src/openai-language-model-capabilities.ts +8 -0
- package/src/responses/openai-responses-api.ts +8 -0
- package/src/responses/openai-responses-language-model-options.ts +12 -0
- package/src/responses/openai-responses-language-model.ts +73 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<
|
|
|
10
10
|
logprobs?: number | boolean | undefined;
|
|
11
11
|
parallelToolCalls?: boolean | undefined;
|
|
12
12
|
user?: string | undefined;
|
|
13
|
-
reasoningEffort?: "
|
|
13
|
+
reasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max" | "none" | "minimal" | undefined;
|
|
14
14
|
maxCompletionTokens?: number | undefined;
|
|
15
15
|
store?: boolean | undefined;
|
|
16
16
|
metadata?: Record<string, string> | undefined;
|
|
@@ -160,7 +160,7 @@ declare const modelMaxImagesPerCall: Record<OpenAIImageModelId, number>;
|
|
|
160
160
|
declare function hasDefaultResponseFormat(modelId: string): boolean;
|
|
161
161
|
declare function getMaxImagesPerCall(modelId: OpenAIImageModelId): number;
|
|
162
162
|
declare const openaiImageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
163
|
-
quality?: "
|
|
163
|
+
quality?: "low" | "medium" | "high" | "auto" | "standard" | "hd" | undefined;
|
|
164
164
|
background?: "auto" | "transparent" | "opaque" | undefined;
|
|
165
165
|
outputFormat?: "png" | "jpeg" | "webp" | undefined;
|
|
166
166
|
outputCompression?: number | undefined;
|
|
@@ -168,17 +168,17 @@ declare const openaiImageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
|
168
168
|
}>;
|
|
169
169
|
type OpenAIImageModelOptions = InferSchema<typeof openaiImageModelOptions>;
|
|
170
170
|
declare const openaiImageModelGenerationOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
171
|
-
quality?: "
|
|
171
|
+
quality?: "low" | "medium" | "high" | "auto" | "standard" | "hd" | undefined;
|
|
172
172
|
background?: "auto" | "transparent" | "opaque" | undefined;
|
|
173
173
|
outputFormat?: "png" | "jpeg" | "webp" | undefined;
|
|
174
174
|
outputCompression?: number | undefined;
|
|
175
175
|
user?: string | undefined;
|
|
176
176
|
style?: "vivid" | "natural" | undefined;
|
|
177
|
-
moderation?: "
|
|
177
|
+
moderation?: "low" | "auto" | undefined;
|
|
178
178
|
}>;
|
|
179
179
|
type OpenAIImageModelGenerationOptions = InferSchema<typeof openaiImageModelGenerationOptions>;
|
|
180
180
|
declare const openaiImageModelEditOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
181
|
-
quality?: "
|
|
181
|
+
quality?: "low" | "medium" | "high" | "auto" | "standard" | "hd" | undefined;
|
|
182
182
|
background?: "auto" | "transparent" | "opaque" | undefined;
|
|
183
183
|
outputFormat?: "png" | "jpeg" | "webp" | undefined;
|
|
184
184
|
outputCompression?: number | undefined;
|
|
@@ -225,7 +225,7 @@ declare const openAITranscriptionModelOptions: _ai_sdk_provider_utils.LazySchema
|
|
|
225
225
|
silenceDurationMs?: number | undefined;
|
|
226
226
|
} | undefined;
|
|
227
227
|
streaming?: {
|
|
228
|
-
delay?: "
|
|
228
|
+
delay?: "low" | "medium" | "high" | "xhigh" | "minimal" | undefined;
|
|
229
229
|
include?: string[] | undefined;
|
|
230
230
|
} | undefined;
|
|
231
231
|
}>;
|
|
@@ -418,7 +418,7 @@ declare const openaiResponsesLocalShellCallSchema: z.ZodObject<{
|
|
|
418
418
|
}, z.core.$strip>;
|
|
419
419
|
}, z.core.$strip>;
|
|
420
420
|
type OpenAIResponsesInput = Array<OpenAIResponsesInputItem>;
|
|
421
|
-
type OpenAIResponsesInputItem = OpenAIResponsesSystemMessage | OpenAIResponsesUserMessage | OpenAIResponsesAssistantMessage | OpenAIResponsesFunctionCall | OpenAIResponsesFunctionCallOutput | OpenAIResponsesProgram | OpenAIResponsesProgramOutput | OpenAIResponsesCustomToolCall | OpenAIResponsesCustomToolCallOutput | OpenAIResponsesMcpApprovalResponse | OpenAIResponsesComputerCall | OpenAIResponsesComputerCallOutput | OpenAIResponsesLocalShellCall | OpenAIResponsesLocalShellCallOutput | OpenAIResponsesShellCall | OpenAIResponsesShellCallOutput | OpenAIResponsesApplyPatchCall | OpenAIResponsesApplyPatchCallOutput | OpenAIResponsesToolSearchCall | OpenAIResponsesToolSearchOutput | OpenAIResponsesReasoning | OpenAIResponsesItemReference | OpenAIResponsesCompactionItem | OpenAIResponsesCompactionTrigger;
|
|
421
|
+
type OpenAIResponsesInputItem = OpenAIResponsesSystemMessage | OpenAIResponsesUserMessage | OpenAIResponsesAssistantMessage | OpenAIResponsesFunctionCall | OpenAIResponsesFunctionCallOutput | OpenAIResponsesProgram | OpenAIResponsesProgramOutput | OpenAIResponsesCustomToolCall | OpenAIResponsesCustomToolCallOutput | OpenAIResponsesMcpApprovalResponse | OpenAIResponsesComputerCall | OpenAIResponsesComputerCallOutput | OpenAIResponsesLocalShellCall | OpenAIResponsesLocalShellCallOutput | OpenAIResponsesShellCall | OpenAIResponsesShellCallOutput | OpenAIResponsesApplyPatchCall | OpenAIResponsesApplyPatchCallOutput | OpenAIResponsesToolSearchCall | OpenAIResponsesToolSearchOutput | OpenAIResponsesReasoning | OpenAIResponsesItemReference | OpenAIResponsesCompactionItem | OpenAIResponsesConfigurationUpdate | OpenAIResponsesCompactionTrigger;
|
|
422
422
|
type OpenAIResponsesIncludeValue = 'web_search_call.action.sources' | 'web_search_call.results' | 'code_interpreter_call.outputs' | 'computer_call_output.output.image_url' | 'file_search_call.results' | 'message.input_image.image_url' | 'message.output_text.logprobs' | 'reasoning.encrypted_content';
|
|
423
423
|
type OpenAIResponsesIncludeOptions = Array<OpenAIResponsesIncludeValue> | undefined | null;
|
|
424
424
|
type OpenAIResponsesSystemMessage = {
|
|
@@ -660,6 +660,12 @@ type OpenAIResponsesCompactionItem = {
|
|
|
660
660
|
id: string;
|
|
661
661
|
encrypted_content: string;
|
|
662
662
|
};
|
|
663
|
+
type OpenAIResponsesConfigurationUpdate = {
|
|
664
|
+
type: 'configuration_update';
|
|
665
|
+
reasoning: {
|
|
666
|
+
effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
667
|
+
};
|
|
668
|
+
};
|
|
663
669
|
type OpenAIResponsesCompactionTrigger = {
|
|
664
670
|
type: 'compaction_trigger';
|
|
665
671
|
};
|
|
@@ -2277,11 +2283,11 @@ declare const imageGenerationArgsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
2277
2283
|
imageUrl?: string | undefined;
|
|
2278
2284
|
} | undefined;
|
|
2279
2285
|
model?: string | undefined;
|
|
2280
|
-
moderation?: "
|
|
2286
|
+
moderation?: "low" | "auto" | undefined;
|
|
2281
2287
|
outputCompression?: number | undefined;
|
|
2282
2288
|
outputFormat?: "png" | "jpeg" | "webp" | undefined;
|
|
2283
2289
|
partialImages?: number | undefined;
|
|
2284
|
-
quality?: "
|
|
2290
|
+
quality?: "low" | "medium" | "high" | "auto" | undefined;
|
|
2285
2291
|
size?: string | undefined;
|
|
2286
2292
|
}>;
|
|
2287
2293
|
declare const imageGenerationOutputSchema: _ai_sdk_provider_utils.LazySchema<{
|
package/dist/internal/index.js
CHANGED
|
@@ -39,14 +39,17 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
39
39
|
const gptVersion = getGptVersion(modelId);
|
|
40
40
|
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
|
|
41
41
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
42
|
+
const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
|
|
42
43
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
43
44
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
44
45
|
const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
45
|
-
const supportsNonReasoningParameters = gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
|
|
46
|
+
const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
|
|
46
47
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
47
48
|
return {
|
|
48
49
|
supportsFlexProcessing,
|
|
49
50
|
supportsPriorityProcessing,
|
|
51
|
+
supportsConfigurationUpdate: isGpt6OrLaterModel,
|
|
52
|
+
supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
|
|
50
53
|
isReasoningModel,
|
|
51
54
|
systemMessageMode,
|
|
52
55
|
supportsNonReasoningParameters
|
|
@@ -1011,7 +1014,17 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1011
1014
|
schema: openaiLanguageModelChatOptions
|
|
1012
1015
|
})) != null ? _a2 : {};
|
|
1013
1016
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
1014
|
-
|
|
1017
|
+
let resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
|
|
1018
|
+
if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
|
|
1019
|
+
resolvedReasoningEffort
|
|
1020
|
+
)) {
|
|
1021
|
+
warnings.push({
|
|
1022
|
+
type: "unsupported",
|
|
1023
|
+
feature: "reasoningEffort",
|
|
1024
|
+
details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
|
|
1025
|
+
});
|
|
1026
|
+
resolvedReasoningEffort = void 0;
|
|
1027
|
+
}
|
|
1015
1028
|
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
1016
1029
|
if (topK != null) {
|
|
1017
1030
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
@@ -1066,6 +1079,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1066
1079
|
// messages:
|
|
1067
1080
|
messages
|
|
1068
1081
|
};
|
|
1082
|
+
if (modelCapabilities.supportedReasoningEfforts != null && baseArgs.prompt_cache_retention != null) {
|
|
1083
|
+
baseArgs.prompt_cache_retention = void 0;
|
|
1084
|
+
warnings.push({
|
|
1085
|
+
type: "unsupported",
|
|
1086
|
+
feature: "promptCacheRetention",
|
|
1087
|
+
details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1069
1090
|
if (isReasoningModel) {
|
|
1070
1091
|
if (resolvedReasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
1071
1092
|
if (baseArgs.temperature != null) {
|
|
@@ -6009,6 +6030,15 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema19(
|
|
|
6009
6030
|
* Supported values vary by model.
|
|
6010
6031
|
*/
|
|
6011
6032
|
reasoningEffort: z21.string().nullish(),
|
|
6033
|
+
/**
|
|
6034
|
+
* Updates the reasoning effort for GPT-6 and later models starting with this response
|
|
6035
|
+
* without changing the request-level reasoning effort. This preserves the
|
|
6036
|
+
* request prefix for prompt caching.
|
|
6037
|
+
*
|
|
6038
|
+
* Only supported by GPT-6 and later models in standard, single-agent mode. Cannot be
|
|
6039
|
+
* combined with automatic compaction or automatic truncation.
|
|
6040
|
+
*/
|
|
6041
|
+
reasoningEffortUpdate: z21.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
6012
6042
|
/**
|
|
6013
6043
|
* Controls how much model work GPT-5.6 performs before returning a final answer.
|
|
6014
6044
|
* `standard` is the default. `pro` increases quality, latency, and token usage.
|
|
@@ -7089,7 +7119,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7089
7119
|
toolChoice,
|
|
7090
7120
|
responseFormat
|
|
7091
7121
|
}) {
|
|
7092
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
7122
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
7093
7123
|
const warnings = [];
|
|
7094
7124
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
7095
7125
|
if (topK != null) {
|
|
@@ -7120,7 +7150,17 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7120
7150
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
7121
7151
|
});
|
|
7122
7152
|
}
|
|
7123
|
-
|
|
7153
|
+
let resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
7154
|
+
if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
|
|
7155
|
+
resolvedReasoningEffort
|
|
7156
|
+
)) {
|
|
7157
|
+
warnings.push({
|
|
7158
|
+
type: "unsupported",
|
|
7159
|
+
feature: "reasoningEffort",
|
|
7160
|
+
details: `${this.modelId} only supports the following reasoning efforts: ${modelCapabilities.supportedReasoningEfforts.join(", ")}`
|
|
7161
|
+
});
|
|
7162
|
+
resolvedReasoningEffort = void 0;
|
|
7163
|
+
}
|
|
7124
7164
|
const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
7125
7165
|
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
7126
7166
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
@@ -7180,6 +7220,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7180
7220
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
7181
7221
|
});
|
|
7182
7222
|
warnings.push(...inputWarnings);
|
|
7223
|
+
const reasoningEffortUpdate = openaiOptions == null ? void 0 : openaiOptions.reasoningEffortUpdate;
|
|
7224
|
+
const configurationUpdateIsSupported = reasoningEffortUpdate == null || modelCapabilities.supportsConfigurationUpdate && (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) !== "pro" && (openaiOptions == null ? void 0 : openaiOptions.contextManagement) == null && (openaiOptions == null ? void 0 : openaiOptions.truncation) !== "auto";
|
|
7225
|
+
if (reasoningEffortUpdate != null && !configurationUpdateIsSupported) {
|
|
7226
|
+
warnings.push({
|
|
7227
|
+
type: "unsupported",
|
|
7228
|
+
feature: "reasoningEffortUpdate",
|
|
7229
|
+
details: !modelCapabilities.supportsConfigurationUpdate ? "reasoningEffortUpdate is only supported by GPT-6 and later models" : "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation"
|
|
7230
|
+
});
|
|
7231
|
+
} else if (reasoningEffortUpdate != null) {
|
|
7232
|
+
input.unshift({
|
|
7233
|
+
type: "configuration_update",
|
|
7234
|
+
reasoning: { effort: reasoningEffortUpdate }
|
|
7235
|
+
});
|
|
7236
|
+
}
|
|
7183
7237
|
if (openaiOptions == null ? void 0 : openaiOptions.compactionTrigger) {
|
|
7184
7238
|
input.push({ type: "compaction_trigger" });
|
|
7185
7239
|
}
|
|
@@ -7280,6 +7334,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7280
7334
|
}
|
|
7281
7335
|
}
|
|
7282
7336
|
};
|
|
7337
|
+
if (modelCapabilities.supportsConfigurationUpdate && baseArgs.prompt_cache_retention != null) {
|
|
7338
|
+
baseArgs.prompt_cache_retention = void 0;
|
|
7339
|
+
warnings.push({
|
|
7340
|
+
type: "unsupported",
|
|
7341
|
+
feature: "promptCacheRetention",
|
|
7342
|
+
details: "promptCacheRetention is not supported by GPT-6 and later models; use promptCacheOptions instead"
|
|
7343
|
+
});
|
|
7344
|
+
}
|
|
7283
7345
|
if (isReasoningModel) {
|
|
7284
7346
|
if (!(resolvedReasoningEffort === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
7285
7347
|
if (baseArgs.temperature != null) {
|
|
@@ -7298,6 +7360,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7298
7360
|
details: "topP is not supported for reasoning models"
|
|
7299
7361
|
});
|
|
7300
7362
|
}
|
|
7363
|
+
if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || ((_j = baseArgs.include) == null ? void 0 : _j.includes("message.output_text.logprobs")))) {
|
|
7364
|
+
baseArgs.top_logprobs = void 0;
|
|
7365
|
+
const filteredInclude = (_k = baseArgs.include) == null ? void 0 : _k.filter(
|
|
7366
|
+
(value) => value !== "message.output_text.logprobs"
|
|
7367
|
+
);
|
|
7368
|
+
baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
|
|
7369
|
+
warnings.push({
|
|
7370
|
+
type: "unsupported",
|
|
7371
|
+
feature: "logprobs",
|
|
7372
|
+
details: "logprobs is not supported for reasoning models"
|
|
7373
|
+
});
|
|
7374
|
+
}
|
|
7301
7375
|
}
|
|
7302
7376
|
} else {
|
|
7303
7377
|
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
|
|
@@ -7345,9 +7419,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7345
7419
|
});
|
|
7346
7420
|
delete baseArgs.service_tier;
|
|
7347
7421
|
}
|
|
7348
|
-
const shellToolEnvType = (
|
|
7422
|
+
const shellToolEnvType = (_n = (_m = (_l = tools == null ? void 0 : tools.find(
|
|
7349
7423
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
7350
|
-
)) == null ? void 0 :
|
|
7424
|
+
)) == null ? void 0 : _l.args) == null ? void 0 : _m.environment) == null ? void 0 : _n.type;
|
|
7351
7425
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
7352
7426
|
return {
|
|
7353
7427
|
webSearchToolName,
|