@ai-sdk/openai 2.0.0-alpha.10 → 2.0.0-alpha.12

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.
@@ -56,6 +56,13 @@ declare const openaiProviderOptions: z.ZodObject<{
56
56
  * @default true
57
57
  */
58
58
  structuredOutputs: z.ZodOptional<z.ZodBoolean>;
59
+ /**
60
+ * Service tier for the request. Set to 'flex' for 50% cheaper processing
61
+ * at the cost of increased latency. Only available for o3 and o4-mini models.
62
+ *
63
+ * @default 'auto'
64
+ */
65
+ serviceTier: z.ZodOptional<z.ZodEnum<["auto", "flex"]>>;
59
66
  }, "strip", z.ZodTypeAny, {
60
67
  user?: string | undefined;
61
68
  logitBias?: Record<number, number> | undefined;
@@ -67,6 +74,7 @@ declare const openaiProviderOptions: z.ZodObject<{
67
74
  metadata?: Record<string, string> | undefined;
68
75
  prediction?: Record<string, any> | undefined;
69
76
  structuredOutputs?: boolean | undefined;
77
+ serviceTier?: "auto" | "flex" | undefined;
70
78
  }, {
71
79
  user?: string | undefined;
72
80
  logitBias?: Record<number, number> | undefined;
@@ -78,6 +86,7 @@ declare const openaiProviderOptions: z.ZodObject<{
78
86
  metadata?: Record<string, string> | undefined;
79
87
  prediction?: Record<string, any> | undefined;
80
88
  structuredOutputs?: boolean | undefined;
89
+ serviceTier?: "auto" | "flex" | undefined;
81
90
  }>;
82
91
  type OpenAIProviderOptions = z.infer<typeof openaiProviderOptions>;
83
92
 
@@ -353,12 +362,14 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
353
362
  strictSchemas: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
354
363
  instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
355
364
  reasoningSummary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
365
+ serviceTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<["auto", "flex"]>>>;
356
366
  }, "strip", z.ZodTypeAny, {
357
367
  user?: string | null | undefined;
358
368
  parallelToolCalls?: boolean | null | undefined;
359
369
  reasoningEffort?: string | null | undefined;
360
370
  store?: boolean | null | undefined;
361
371
  metadata?: any;
372
+ serviceTier?: "auto" | "flex" | null | undefined;
362
373
  instructions?: string | null | undefined;
363
374
  previousResponseId?: string | null | undefined;
364
375
  strictSchemas?: boolean | null | undefined;
@@ -369,6 +380,7 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
369
380
  reasoningEffort?: string | null | undefined;
370
381
  store?: boolean | null | undefined;
371
382
  metadata?: any;
383
+ serviceTier?: "auto" | "flex" | null | undefined;
372
384
  instructions?: string | null | undefined;
373
385
  previousResponseId?: string | null | undefined;
374
386
  strictSchemas?: boolean | null | undefined;
@@ -56,6 +56,13 @@ declare const openaiProviderOptions: z.ZodObject<{
56
56
  * @default true
57
57
  */
58
58
  structuredOutputs: z.ZodOptional<z.ZodBoolean>;
59
+ /**
60
+ * Service tier for the request. Set to 'flex' for 50% cheaper processing
61
+ * at the cost of increased latency. Only available for o3 and o4-mini models.
62
+ *
63
+ * @default 'auto'
64
+ */
65
+ serviceTier: z.ZodOptional<z.ZodEnum<["auto", "flex"]>>;
59
66
  }, "strip", z.ZodTypeAny, {
60
67
  user?: string | undefined;
61
68
  logitBias?: Record<number, number> | undefined;
@@ -67,6 +74,7 @@ declare const openaiProviderOptions: z.ZodObject<{
67
74
  metadata?: Record<string, string> | undefined;
68
75
  prediction?: Record<string, any> | undefined;
69
76
  structuredOutputs?: boolean | undefined;
77
+ serviceTier?: "auto" | "flex" | undefined;
70
78
  }, {
71
79
  user?: string | undefined;
72
80
  logitBias?: Record<number, number> | undefined;
@@ -78,6 +86,7 @@ declare const openaiProviderOptions: z.ZodObject<{
78
86
  metadata?: Record<string, string> | undefined;
79
87
  prediction?: Record<string, any> | undefined;
80
88
  structuredOutputs?: boolean | undefined;
89
+ serviceTier?: "auto" | "flex" | undefined;
81
90
  }>;
82
91
  type OpenAIProviderOptions = z.infer<typeof openaiProviderOptions>;
83
92
 
@@ -353,12 +362,14 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
353
362
  strictSchemas: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
354
363
  instructions: z.ZodOptional<z.ZodNullable<z.ZodString>>;
355
364
  reasoningSummary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
365
+ serviceTier: z.ZodOptional<z.ZodNullable<z.ZodEnum<["auto", "flex"]>>>;
356
366
  }, "strip", z.ZodTypeAny, {
357
367
  user?: string | null | undefined;
358
368
  parallelToolCalls?: boolean | null | undefined;
359
369
  reasoningEffort?: string | null | undefined;
360
370
  store?: boolean | null | undefined;
361
371
  metadata?: any;
372
+ serviceTier?: "auto" | "flex" | null | undefined;
362
373
  instructions?: string | null | undefined;
363
374
  previousResponseId?: string | null | undefined;
364
375
  strictSchemas?: boolean | null | undefined;
@@ -369,6 +380,7 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
369
380
  reasoningEffort?: string | null | undefined;
370
381
  store?: boolean | null | undefined;
371
382
  metadata?: any;
383
+ serviceTier?: "auto" | "flex" | null | undefined;
372
384
  instructions?: string | null | undefined;
373
385
  previousResponseId?: string | null | undefined;
374
386
  strictSchemas?: boolean | null | undefined;
@@ -290,7 +290,14 @@ var openaiProviderOptions = import_zod.z.object({
290
290
  *
291
291
  * @default true
292
292
  */
293
- structuredOutputs: import_zod.z.boolean().optional()
293
+ structuredOutputs: import_zod.z.boolean().optional(),
294
+ /**
295
+ * Service tier for the request. Set to 'flex' for 50% cheaper processing
296
+ * at the cost of increased latency. Only available for o3 and o4-mini models.
297
+ *
298
+ * @default 'auto'
299
+ */
300
+ serviceTier: import_zod.z.enum(["auto", "flex"]).optional()
294
301
  });
295
302
 
296
303
  // src/openai-error.ts
@@ -461,6 +468,7 @@ var OpenAIChatLanguageModel = class {
461
468
  metadata: openaiOptions.metadata,
462
469
  prediction: openaiOptions.prediction,
463
470
  reasoning_effort: openaiOptions.reasoningEffort,
471
+ service_tier: openaiOptions.serviceTier,
464
472
  // messages:
465
473
  messages
466
474
  };
@@ -534,6 +542,14 @@ var OpenAIChatLanguageModel = class {
534
542
  });
535
543
  }
536
544
  }
545
+ if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
546
+ warnings.push({
547
+ type: "unsupported-setting",
548
+ setting: "serviceTier",
549
+ details: "flex processing is only available for o3 and o4-mini models"
550
+ });
551
+ baseArgs.service_tier = void 0;
552
+ }
537
553
  const {
538
554
  tools: openaiTools,
539
555
  toolChoice: openaiToolChoice,
@@ -660,6 +676,9 @@ var OpenAIChatLanguageModel = class {
660
676
  },
661
677
  transform(chunk, controller) {
662
678
  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;
679
+ if (options.includeRawChunks) {
680
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
681
+ }
663
682
  if (!chunk.success) {
664
683
  finishReason = "error";
665
684
  controller.enqueue({ type: "error", error: chunk.error });
@@ -905,6 +924,9 @@ var openaiChatChunkSchema = import_zod3.z.union([
905
924
  function isReasoningModel(modelId) {
906
925
  return modelId.startsWith("o");
907
926
  }
927
+ function supportsFlexProcessing(modelId) {
928
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
929
+ }
908
930
  function getSystemMessageMode(modelId) {
909
931
  var _a, _b;
910
932
  if (!isReasoningModel(modelId)) {
@@ -1236,6 +1258,9 @@ var OpenAICompletionLanguageModel = class {
1236
1258
  controller.enqueue({ type: "stream-start", warnings });
1237
1259
  },
1238
1260
  transform(chunk, controller) {
1261
+ if (options.includeRawChunks) {
1262
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1263
+ }
1239
1264
  if (!chunk.success) {
1240
1265
  finishReason = "error";
1241
1266
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2098,6 +2123,7 @@ var OpenAIResponsesLanguageModel = class {
2098
2123
  store: openaiOptions == null ? void 0 : openaiOptions.store,
2099
2124
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2100
2125
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2126
+ service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2101
2127
  // model-specific settings:
2102
2128
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2103
2129
  reasoning: {
@@ -2131,6 +2157,14 @@ var OpenAIResponsesLanguageModel = class {
2131
2157
  });
2132
2158
  }
2133
2159
  }
2160
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2161
+ warnings.push({
2162
+ type: "unsupported-setting",
2163
+ setting: "serviceTier",
2164
+ details: "flex processing is only available for o3 and o4-mini models"
2165
+ });
2166
+ delete baseArgs.service_tier;
2167
+ }
2134
2168
  const {
2135
2169
  tools: openaiTools,
2136
2170
  toolChoice: openaiToolChoice,
@@ -2318,6 +2352,7 @@ var OpenAIResponsesLanguageModel = class {
2318
2352
  let responseId = null;
2319
2353
  const ongoingToolCalls = {};
2320
2354
  let hasToolCalls = false;
2355
+ let lastReasoningSummaryIndex = null;
2321
2356
  return {
2322
2357
  stream: response.pipeThrough(
2323
2358
  new TransformStream({
@@ -2326,6 +2361,9 @@ var OpenAIResponsesLanguageModel = class {
2326
2361
  },
2327
2362
  transform(chunk, controller) {
2328
2363
  var _a, _b, _c, _d, _e, _f, _g, _h;
2364
+ if (options.includeRawChunks) {
2365
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2366
+ }
2329
2367
  if (!chunk.success) {
2330
2368
  finishReason = "error";
2331
2369
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2371,10 +2409,16 @@ var OpenAIResponsesLanguageModel = class {
2371
2409
  text: value.delta
2372
2410
  });
2373
2411
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2412
+ if (lastReasoningSummaryIndex !== null && value.summary_index !== lastReasoningSummaryIndex) {
2413
+ controller.enqueue({ type: "reasoning-part-finish" });
2414
+ }
2415
+ lastReasoningSummaryIndex = value.summary_index;
2374
2416
  controller.enqueue({
2375
2417
  type: "reasoning",
2376
2418
  text: value.delta
2377
2419
  });
2420
+ } else if (isResponseReasoningSummaryPartDoneChunk(value)) {
2421
+ controller.enqueue({ type: "reasoning-part-finish" });
2378
2422
  } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2379
2423
  ongoingToolCalls[value.output_index] = void 0;
2380
2424
  hasToolCalls = true;
@@ -2503,6 +2547,13 @@ var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
2503
2547
  summary_index: import_zod12.z.number(),
2504
2548
  delta: import_zod12.z.string()
2505
2549
  });
2550
+ var responseReasoningSummaryPartDoneSchema = import_zod12.z.object({
2551
+ type: import_zod12.z.literal("response.reasoning_summary_part.done"),
2552
+ item_id: import_zod12.z.string(),
2553
+ output_index: import_zod12.z.number(),
2554
+ summary_index: import_zod12.z.number(),
2555
+ part: import_zod12.z.unknown().nullish()
2556
+ });
2506
2557
  var openaiResponsesChunkSchema = import_zod12.z.union([
2507
2558
  textDeltaChunkSchema,
2508
2559
  responseFinishedChunkSchema,
@@ -2512,6 +2563,7 @@ var openaiResponsesChunkSchema = import_zod12.z.union([
2512
2563
  responseOutputItemAddedSchema,
2513
2564
  responseAnnotationAddedSchema,
2514
2565
  responseReasoningSummaryTextDeltaSchema,
2566
+ responseReasoningSummaryPartDoneSchema,
2515
2567
  import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
2516
2568
  // fallback for unknown chunks
2517
2569
  ]);
@@ -2539,6 +2591,9 @@ function isResponseAnnotationAddedChunk(chunk) {
2539
2591
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2540
2592
  return chunk.type === "response.reasoning_summary_text.delta";
2541
2593
  }
2594
+ function isResponseReasoningSummaryPartDoneChunk(chunk) {
2595
+ return chunk.type === "response.reasoning_summary_part.done";
2596
+ }
2542
2597
  function getResponsesModelConfig(modelId) {
2543
2598
  if (modelId.startsWith("o")) {
2544
2599
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
@@ -2560,6 +2615,9 @@ function getResponsesModelConfig(modelId) {
2560
2615
  requiredAutoTruncation: false
2561
2616
  };
2562
2617
  }
2618
+ function supportsFlexProcessing2(modelId) {
2619
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
2620
+ }
2563
2621
  var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
2564
2622
  metadata: import_zod12.z.any().nullish(),
2565
2623
  parallelToolCalls: import_zod12.z.boolean().nullish(),
@@ -2569,7 +2627,8 @@ var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
2569
2627
  reasoningEffort: import_zod12.z.string().nullish(),
2570
2628
  strictSchemas: import_zod12.z.boolean().nullish(),
2571
2629
  instructions: import_zod12.z.string().nullish(),
2572
- reasoningSummary: import_zod12.z.string().nullish()
2630
+ reasoningSummary: import_zod12.z.string().nullish(),
2631
+ serviceTier: import_zod12.z.enum(["auto", "flex"]).nullish()
2573
2632
  });
2574
2633
  // Annotate the CommonJS export names for ESM import in node:
2575
2634
  0 && (module.exports = {