@ai-sdk/openai 4.0.71 → 4.0.73

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.
@@ -4,13 +4,13 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { InferSchema, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, FetchFunction, WebSocketConstructor, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } from '@ai-sdk/provider-utils';
5
5
  import { z } from 'zod/v4';
6
6
 
7
- type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | (string & {});
7
+ type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6-luna' | 'gpt-6-sol' | (string & {});
8
8
  declare const openaiLanguageModelChatOptions: _ai_sdk_provider_utils.LazySchema<{
9
9
  logitBias?: Record<number, number> | undefined;
10
10
  logprobs?: number | boolean | undefined;
11
11
  parallelToolCalls?: boolean | undefined;
12
12
  user?: string | undefined;
13
- reasoningEffort?: "low" | "medium" | "high" | "xhigh" | "max" | "none" | "minimal" | undefined;
13
+ reasoningEffort?: "none" | "low" | "medium" | "high" | "xhigh" | "max" | "minimal" | undefined;
14
14
  maxCompletionTokens?: number | undefined;
15
15
  store?: boolean | undefined;
16
16
  metadata?: Record<string, string> | undefined;
@@ -1849,7 +1849,7 @@ declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) =>
1849
1849
  }>;
1850
1850
  }, {}>;
1851
1851
 
1852
- type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
1852
+ type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini' | 'gpt-4o' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.1-codex-mini' | 'gpt-5.1-codex' | 'gpt-5.1-codex-max' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.2-codex' | 'gpt-5.3-chat-latest' | 'gpt-5.3-codex' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | 'gpt-6-astra' | 'gpt-6-luna' | 'gpt-6-sol' | 'gpt-5-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5-codex' | 'gpt-5-mini-2025-08-07' | 'gpt-5-mini' | 'gpt-5-nano-2025-08-07' | 'gpt-5-nano' | 'gpt-5-pro-2025-10-06' | 'gpt-5-pro' | 'gpt-5' | 'o1-2024-12-17' | 'o1' | 'o3-2025-04-16' | 'o3-mini-2025-01-31' | 'o3-mini' | 'o3' | 'o4-mini' | 'o4-mini-2025-04-16' | (string & {});
1853
1853
 
1854
1854
  declare const openaiResponsesSupportedUrls: Record<string, RegExp[]>;
1855
1855
  declare class OpenAIResponsesLanguageModel implements LanguageModelV4 {
@@ -1875,7 +1875,7 @@ declare class OpenAIResponsesLanguageModel implements LanguageModelV4 {
1875
1875
  webSearchToolName: string | undefined;
1876
1876
  args: {
1877
1877
  tools: OpenAIResponsesTool[] | undefined;
1878
- tool_choice: "auto" | "none" | "required" | {
1878
+ tool_choice: "none" | "auto" | "required" | {
1879
1879
  type: "file_search";
1880
1880
  } | {
1881
1881
  type: "web_search_preview";
@@ -43,6 +43,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
43
43
  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);
44
44
  const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
45
45
  const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
46
+ const isGpt6SolOrLuna = modelId === "gpt-6-sol" || modelId === "gpt-6-luna";
46
47
  const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
47
48
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
48
49
  const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
@@ -53,7 +54,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
53
54
  supportsPriorityProcessing,
54
55
  supportsConfigurationUpdate: isGpt6OrLaterModel,
55
56
  supportsAsyncToolCalling: isGpt6OrLaterModel,
56
- supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
57
+ supportedReasoningEfforts: isGpt6SolOrLuna ? ["none", "low", "medium", "high", "xhigh", "max"] : isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
57
58
  isReasoningModel,
58
59
  systemMessageMode,
59
60
  supportsNonReasoningParameters
@@ -643,6 +644,9 @@ var openaiChatResponseSchema = lazySchema(
643
644
  message: z2.object({
644
645
  role: z2.literal("assistant").nullish(),
645
646
  content: z2.string().nullish(),
647
+ audio: z2.object({
648
+ transcript: z2.string().nullish()
649
+ }).nullish(),
646
650
  tool_calls: z2.array(
647
651
  z2.object({
648
652
  id: z2.string().nullish(),
@@ -919,16 +923,26 @@ import {
919
923
  } from "@ai-sdk/provider";
920
924
  function normalizeOpenAIJsonSchema(schema) {
921
925
  let removedPropertyNames = false;
926
+ let removedLookaroundPattern = false;
922
927
  const normalizedSchema = normalizeSchema(schema);
928
+ const warnings = [];
929
+ if (removedPropertyNames) {
930
+ warnings.push({
931
+ type: "compatibility",
932
+ feature: "JSON Schema propertyNames",
933
+ details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
934
+ });
935
+ }
936
+ if (removedLookaroundPattern) {
937
+ warnings.push({
938
+ type: "compatibility",
939
+ feature: "JSON Schema pattern with regex lookaround",
940
+ details: "OpenAI does not support regex lookaround in JSON Schema patterns. The pattern was removed before sending the schema, so OpenAI will not enforce that constraint."
941
+ });
942
+ }
923
943
  return {
924
944
  schema: normalizedSchema,
925
- warnings: removedPropertyNames ? [
926
- {
927
- type: "compatibility",
928
- feature: "JSON Schema propertyNames",
929
- details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
930
- }
931
- ] : []
945
+ warnings
932
946
  };
933
947
  function normalizeSchema(schema2) {
934
948
  const propertyNames = schema2.propertyNames;
@@ -942,6 +956,10 @@ function normalizeOpenAIJsonSchema(schema) {
942
956
  }
943
957
  const normalizedSchema2 = { ...schema2 };
944
958
  delete normalizedSchema2.propertyNames;
959
+ if (normalizedSchema2.pattern != null && containsRegexLookaround(normalizedSchema2.pattern)) {
960
+ delete normalizedSchema2.pattern;
961
+ removedLookaroundPattern = true;
962
+ }
945
963
  if (normalizedSchema2.properties != null) {
946
964
  normalizedSchema2.properties = normalizeSchemaRecord(
947
965
  normalizedSchema2.properties
@@ -1020,6 +1038,39 @@ function normalizeOpenAIJsonSchema(schema) {
1020
1038
  return typeof definition === "boolean" ? definition : normalizeSchema(definition);
1021
1039
  }
1022
1040
  }
1041
+ function containsRegexLookaround(pattern) {
1042
+ let escaped = false;
1043
+ let inCharacterClass = false;
1044
+ for (let index = 0; index < pattern.length; index++) {
1045
+ const character = pattern[index];
1046
+ if (escaped) {
1047
+ escaped = false;
1048
+ continue;
1049
+ }
1050
+ if (character === "\\") {
1051
+ escaped = true;
1052
+ continue;
1053
+ }
1054
+ if (character === "[") {
1055
+ inCharacterClass = true;
1056
+ continue;
1057
+ }
1058
+ if (character === "]") {
1059
+ inCharacterClass = false;
1060
+ continue;
1061
+ }
1062
+ if (!inCharacterClass && character === "(" && pattern[index + 1] === "?") {
1063
+ const lookaroundPrefix = pattern[index + 2];
1064
+ if (lookaroundPrefix === "=" || lookaroundPrefix === "!") {
1065
+ return true;
1066
+ }
1067
+ if (lookaroundPrefix === "<" && (pattern[index + 3] === "=" || pattern[index + 3] === "!")) {
1068
+ return true;
1069
+ }
1070
+ }
1071
+ }
1072
+ return false;
1073
+ }
1023
1074
 
1024
1075
  // src/chat/openai-chat-prepare-tools.ts
1025
1076
  function prepareChatTools({
@@ -1316,7 +1367,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1316
1367
  };
1317
1368
  }
1318
1369
  async doGenerate(options) {
1319
- var _a2, _b, _c, _d, _e, _f, _g;
1370
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
1320
1371
  const { args: body, warnings } = await this.getArgs(options);
1321
1372
  const {
1322
1373
  responseHeaders,
@@ -1344,11 +1395,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1344
1395
  });
1345
1396
  }
1346
1397
  const content = [];
1347
- const text = choice.message.content;
1398
+ const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : (_c = choice.message.audio) == null ? void 0 : _c.transcript;
1348
1399
  if (text != null && text.length > 0) {
1349
1400
  content.push({ type: "text", text });
1350
1401
  }
1351
- for (const toolCall of (_c = choice.message.tool_calls) != null ? _c : []) {
1402
+ for (const toolCall of (_d = choice.message.tool_calls) != null ? _d : []) {
1352
1403
  content.push({
1353
1404
  type: "tool-call",
1354
1405
  toolCallId: toolCall.id || generateId(),
@@ -1356,7 +1407,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1356
1407
  input: toolCall.function.arguments
1357
1408
  });
1358
1409
  }
1359
- for (const annotation of (_d = choice.message.annotations) != null ? _d : []) {
1410
+ for (const annotation of (_e = choice.message.annotations) != null ? _e : []) {
1360
1411
  content.push({
1361
1412
  type: "source",
1362
1413
  sourceType: "url",
@@ -1365,7 +1416,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1365
1416
  title: annotation.url_citation.title
1366
1417
  });
1367
1418
  }
1368
- const completionTokenDetails = (_e = response.usage) == null ? void 0 : _e.completion_tokens_details;
1419
+ const completionTokenDetails = (_f = response.usage) == null ? void 0 : _f.completion_tokens_details;
1369
1420
  const providerMetadata = { openai: {} };
1370
1421
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
1371
1422
  providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
@@ -1373,14 +1424,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1373
1424
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1374
1425
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1375
1426
  }
1376
- if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) {
1427
+ if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1377
1428
  providerMetadata.openai.logprobs = choice.logprobs.content;
1378
1429
  }
1379
1430
  return {
1380
1431
  content,
1381
1432
  finishReason: {
1382
1433
  unified: mapOpenAIFinishReason(choice.finish_reason),
1383
- raw: (_g = choice.finish_reason) != null ? _g : void 0
1434
+ raw: (_h = choice.finish_reason) != null ? _h : void 0
1384
1435
  },
1385
1436
  usage: convertOpenAIChatUsage(response.usage),
1386
1437
  request: { body },
@@ -3160,7 +3211,7 @@ var openaiSpeechModelOptionsSchema = lazySchema11(
3160
3211
  () => zodSchema11(
3161
3212
  z12.object({
3162
3213
  instructions: z12.string().nullish(),
3163
- speed: z12.number().min(0.25).max(4).default(1).nullish()
3214
+ speed: z12.number().min(0.25).max(4).nullish()
3164
3215
  })
3165
3216
  )
3166
3217
  );
@@ -3193,6 +3244,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3193
3244
  language,
3194
3245
  providerOptions
3195
3246
  }) {
3247
+ var _a2, _b;
3196
3248
  const warnings = [];
3197
3249
  const openAIOptions = await parseProviderOptions6({
3198
3250
  provider: "openai",
@@ -3219,7 +3271,10 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
3219
3271
  }
3220
3272
  }
3221
3273
  if (openAIOptions) {
3222
- const speechModelOptions = {};
3274
+ const speechModelOptions = {
3275
+ speed: (_a2 = openAIOptions.speed) != null ? _a2 : void 0,
3276
+ instructions: (_b = openAIOptions.instructions) != null ? _b : void 0
3277
+ };
3223
3278
  for (const key in speechModelOptions) {
3224
3279
  const value = speechModelOptions[key];
3225
3280
  if (value !== void 0) {
@@ -6086,7 +6141,9 @@ var openaiResponsesReasoningModelIds = [
6086
6141
  "gpt-5.6-luna",
6087
6142
  "gpt-5.6-sol",
6088
6143
  "gpt-5.6-terra",
6089
- "gpt-6-astra"
6144
+ "gpt-6-astra",
6145
+ "gpt-6-luna",
6146
+ "gpt-6-sol"
6090
6147
  ];
6091
6148
  var openaiResponsesModelIds = [
6092
6149
  "gpt-4.1",