@ai-sdk/openai 4.0.97 → 4.0.99

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.
@@ -1,17 +1,61 @@
1
1
  ---
2
2
  title: OpenAI
3
- description: Learn how to use the OpenAI provider for the AI SDK.
3
+ description: Learn how to use OpenAI with AI Gateway and the direct provider.
4
4
  ---
5
5
 
6
6
  # OpenAI Provider
7
7
 
8
8
  The [OpenAI](https://openai.com/) provider contains language model support for the OpenAI responses, chat, and completion APIs, as well as embedding model support for the OpenAI embeddings API.
9
+ You can use OpenAI models through [AI Gateway](/providers/ai-sdk-providers/ai-gateway) (recommended) or connect directly with `@ai-sdk/openai`.
9
10
 
10
- ## Setup
11
+ ```ts provider="openai" model="openai/gpt-6-astra"
12
+ import { generateText } from 'ai';
13
+ __PROVIDER_IMPORT__;
11
14
 
12
- The OpenAI provider is available in the `@ai-sdk/openai` module. You can install it with
15
+ const { text } = await generateText({
16
+ model: __MODEL__,
17
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
18
+ });
19
+
20
+ console.log(text);
21
+ ```
22
+
23
+ ## Using AI Gateway
24
+
25
+ The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install `ai`:
26
+
27
+ <InstallPackages packages="ai" />
28
+
29
+ Set an [AI Gateway API key](https://vercel.com/docs/ai-gateway/getting-started) in your environment:
30
+
31
+ ```bash
32
+ export AI_GATEWAY_API_KEY=your_api_key_here
33
+ ```
13
34
 
14
- <InstallPackages packages="@ai-sdk/openai" />
35
+ Vercel deployments can also use [OIDC authentication](/providers/ai-sdk-providers/ai-gateway#oidc-authentication-vercel-deployments).
36
+ See the [AI Gateway provider documentation](/providers/ai-sdk-providers/ai-gateway) for configuration and the [model catalog](https://vercel.com/ai-gateway/models) for available models.
37
+
38
+ Gateway feature and provider-option support depends on the model and the provider serving the request. See [Gateway provider options](https://vercel.com/docs/ai-gateway/models-and-providers/provider-options).
39
+
40
+ ## Using `@ai-sdk/openai`
41
+
42
+ For direct access to OpenAI, install `ai` and `@ai-sdk/openai`:
43
+
44
+ <InstallPackages packages="ai @ai-sdk/openai" />
45
+
46
+ Set your OpenAI API credential in the `OPENAI_API_KEY` environment variable:
47
+
48
+ ```bash
49
+ export OPENAI_API_KEY=your_api_key_here
50
+ ```
51
+
52
+ AI Gateway does not expose every API in `@ai-sdk/openai`. Use the direct provider for provider-specific APIs or custom connection settings.
53
+
54
+ <Note>
55
+ The following sections document the direct `@ai-sdk/openai` provider,
56
+ including its model factories and settings. Gateway model and feature
57
+ availability can differ.
58
+ </Note>
15
59
 
16
60
  ## Provider Instance
17
61
 
@@ -239,7 +283,7 @@ The following provider options are available:
239
283
  OpenAI structured outputs have several
240
284
  [limitations](https://openai.com/index/introducing-structured-outputs-in-the-api),
241
285
  in particular around the [supported
242
- schemas](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas),
286
+ schemas](https://developers.openai.com/api/docs/guides/structured-outputs#supported-schemas),
243
287
  and are therefore opt-in. For example, optional schema properties are not
244
288
  supported. You need to change Zod `.nullish()` and `.optional()` to
245
289
  `.nullable()`.
@@ -274,7 +318,7 @@ The following provider options are available:
274
318
  A cache key for manual prompt caching control. Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.
275
319
 
276
320
  - **promptCacheOptions** _object_
277
- Configures prompt caching for GPT-5.6 and later models. `mode` can be `'implicit'` or `'explicit'`, and `ttl` currently only supports `'30m'`. In explicit mode, only content blocks marked with a prompt cache breakpoint are cached.
321
+ Configures prompt caching for GPT-5.6 and later models. `mode` can be `'implicit'` or `'explicit'`. `ttl` sets the minimum cache lifetime: `'30m'` (default) or `'12h'`. 12-hour writes are billed at a higher rate, and `usage.raw.input_tokens_details.cache_write_tokens_details` splits cache writes into `ttl_30m_tokens` and `ttl_12h_tokens`. Set `prewarm` to `true` to write the prompt to the cache without generating output. In explicit mode, only content blocks marked with a prompt cache breakpoint are cached.
278
322
 
279
323
  - **promptCacheRetention** _'in_memory' | '24h'_
280
324
  The legacy retention policy for models before GPT-5.6. Set to `'24h'` to enable extended prompt caching on supported models. For GPT-5.6 and later models, use `promptCacheOptions.ttl` instead.
@@ -2814,7 +2858,7 @@ including `gpt-4o` and `gpt-4o-mini`.
2814
2858
  not need to be explicitly enabled.
2815
2859
  - You can use the response `usage` to access the number of prompt tokens that were a cache hit via `usage.inputTokenDetails.cacheReadTokens`.
2816
2860
  - For GPT-5.6 and later models, `usage.inputTokenDetails.cacheWriteTokens` reports tokens written to the cache.
2817
- - For GPT-5.6 and later models, `promptCacheOptions.ttl` sets a minimum cache lifetime of 30 minutes. Earlier models generally retain in-memory prefixes for 5-10 minutes of inactivity, up to one hour.
2861
+ - For GPT-5.6 and later models, `promptCacheOptions.ttl` sets a minimum cache lifetime of 30 minutes. Chat models only support `'30m'`. The 12-hour lifetime is available on [Responses models](#responses-models). Earlier models generally retain in-memory prefixes for 5-10 minutes of inactivity, up to one hour.
2818
2862
 
2819
2863
  ```ts highlight="9"
2820
2864
  import { openai } from '@ai-sdk/openai';
@@ -2847,7 +2891,7 @@ const { text, usage } = await generateText({
2847
2891
  console.log('Cached tokens:', usage.inputTokenDetails.cacheReadTokens);
2848
2892
  ```
2849
2893
 
2850
- GPT-5.6 and later models support explicit cache breakpoints on text, image, and file content blocks. Set a request-level cache key and mark the end of each reusable prefix with `promptCacheBreakpoint`:
2894
+ GPT-5.6 and later models support explicit cache breakpoints on text, image, and file content blocks. Set a request-level cache key and mark the end of each reusable prefix with `promptCacheBreakpoint`. With Responses models, a breakpoint can set its own `ttl` (for example `{ mode: 'explicit', ttl: '12h' }`) to override the request-level `promptCacheOptions.ttl`:
2851
2895
 
2852
2896
  ```ts highlight="9-12,20-28"
2853
2897
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai",
3
- "version": "4.0.97",
3
+ "version": "4.0.99",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,13 +35,14 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.30",
39
- "@ai-sdk/provider-utils": "5.0.63"
38
+ "@ai-sdk/provider": "4.0.31",
39
+ "@ai-sdk/provider-utils": "5.0.65"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
43
43
  "@types/node": "22.19.19",
44
44
  "@vercel/ai-tsconfig": "0.0.0",
45
+ "@vercel/ai-tsdown-config": "0.0.0",
45
46
  "tsdown": "^0.23.0",
46
47
  "typescript": "6.0.3",
47
48
  "zod": "3.25.76"
@@ -199,7 +199,7 @@ export const openaiChatChunkSchema = lazySchema(() =>
199
199
  })
200
200
  .nullish(),
201
201
  }),
202
- openaiErrorDataSchema,
202
+ openaiErrorDataSchema(),
203
203
  ]),
204
204
  ),
205
205
  );
@@ -70,7 +70,7 @@ export const openaiCompletionChunkSchema = lazySchema(() =>
70
70
  })
71
71
  .nullish(),
72
72
  }),
73
- openaiErrorDataSchema,
73
+ openaiErrorDataSchema(),
74
74
  ]),
75
75
  ),
76
76
  );
@@ -17,6 +17,7 @@ import {
17
17
  createBinaryStreamResponseHandler,
18
18
  createJsonResponseHandler,
19
19
  deleteFromApi,
20
+ encodePathSegment,
20
21
  getFromApi,
21
22
  parseProviderOptions,
22
23
  postFormDataToApi,
@@ -44,17 +45,6 @@ interface OpenAIFilesConfig {
44
45
 
45
46
  type OpenAIFilesResponse = InferSchema<typeof openaiFilesResponseSchema>;
46
47
 
47
- function encodePathSegment(value: string): string {
48
- const encodedValue = encodeURIComponent(value);
49
-
50
- // URL parsing normalizes both literal and percent-encoded dot segments.
51
- return encodedValue === '.'
52
- ? '%252E'
53
- : encodedValue === '..'
54
- ? '%252E%252E'
55
- : encodedValue;
56
- }
57
-
58
48
  export class OpenAIFiles implements FilesV4 {
59
49
  readonly specificationVersion = 'v4';
60
50
 
@@ -49,45 +49,46 @@ export function getMaxImagesPerCall(modelId: OpenAIImageModelId): number {
49
49
  );
50
50
  }
51
51
 
52
- const baseImageModelOptionsObject = z.object({
53
- /**
54
- * Quality of the generated image(s).
55
- *
56
- * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `xhigh`, `max`, `auto`.
57
- * `xhigh` and `max` are supported by GPT Image 2.5 models.
58
- */
59
- quality: z
60
- .enum(['standard', 'hd', 'low', 'medium', 'high', 'xhigh', 'max', 'auto'])
61
- .optional(),
62
-
63
- /**
64
- * Background behavior for the generated image(s).
65
- *
66
- * If `transparent`, the output format must support transparency
67
- * (i.e. `png` or `webp`).
68
- */
69
- background: z.enum(['transparent', 'opaque', 'auto']).optional(),
70
-
71
- /**
72
- * Format in which the generated image(s) are returned.
73
- */
74
- outputFormat: z.enum(['png', 'jpeg', 'webp']).optional(),
75
-
76
- /**
77
- * Compression level (0-100) for the generated image(s). Applies to the
78
- * `jpeg` and `webp` output formats.
79
- */
80
- outputCompression: z.number().int().min(0).max(100).optional(),
81
-
82
- /**
83
- * A unique identifier representing your end-user, which can help OpenAI
84
- * to monitor and detect abuse.
85
- */
86
- user: z.string().optional(),
87
- });
52
+ const baseImageModelOptionsObject = () =>
53
+ z.object({
54
+ /**
55
+ * Quality of the generated image(s).
56
+ *
57
+ * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `xhigh`, `max`, `auto`.
58
+ * `xhigh` and `max` are supported by GPT Image 2.5 models.
59
+ */
60
+ quality: z
61
+ .enum(['standard', 'hd', 'low', 'medium', 'high', 'xhigh', 'max', 'auto'])
62
+ .optional(),
63
+
64
+ /**
65
+ * Background behavior for the generated image(s).
66
+ *
67
+ * If `transparent`, the output format must support transparency
68
+ * (i.e. `png` or `webp`).
69
+ */
70
+ background: z.enum(['transparent', 'opaque', 'auto']).optional(),
71
+
72
+ /**
73
+ * Format in which the generated image(s) are returned.
74
+ */
75
+ outputFormat: z.enum(['png', 'jpeg', 'webp']).optional(),
76
+
77
+ /**
78
+ * Compression level (0-100) for the generated image(s). Applies to the
79
+ * `jpeg` and `webp` output formats.
80
+ */
81
+ outputCompression: z.number().int().min(0).max(100).optional(),
82
+
83
+ /**
84
+ * A unique identifier representing your end-user, which can help OpenAI
85
+ * to monitor and detect abuse.
86
+ */
87
+ user: z.string().optional(),
88
+ });
88
89
 
89
90
  export const openaiImageModelOptions = lazySchema(() =>
90
- zodSchema(baseImageModelOptionsObject),
91
+ zodSchema(baseImageModelOptionsObject()),
91
92
  );
92
93
 
93
94
  export type OpenAIImageModelOptions = InferSchema<
@@ -96,7 +97,7 @@ export type OpenAIImageModelOptions = InferSchema<
96
97
 
97
98
  export const openaiImageModelGenerationOptions = lazySchema(() =>
98
99
  zodSchema(
99
- baseImageModelOptionsObject.extend({
100
+ baseImageModelOptionsObject().extend({
100
101
  /**
101
102
  * Style of the generated image. `vivid` produces hyper-real and
102
103
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -119,7 +120,7 @@ export type OpenAIImageModelGenerationOptions = InferSchema<
119
120
 
120
121
  export const openaiImageModelEditOptions = lazySchema(() =>
121
122
  zodSchema(
122
- baseImageModelOptionsObject.extend({
123
+ baseImageModelOptionsObject().extend({
123
124
  /**
124
125
  * Fidelity of the output image(s) to the input image(s).
125
126
  */
@@ -4,6 +4,8 @@ import {
4
4
  type Experimental_RealtimeModelV4SessionConfig as RealtimeModelV4SessionConfig,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
+ lazySchema,
8
+ zodSchema,
7
9
  createJsonResponseHandler,
8
10
  postJsonToApi,
9
11
  } from '@ai-sdk/provider-utils';
@@ -20,10 +22,17 @@ import type { OpenAIRealtimeModelConfig } from '../realtime/openai-realtime-mode
20
22
 
21
23
  export type OpenAIRealtimeModelLiveConfig = OpenAIRealtimeModelConfig;
22
24
 
23
- const webRTCSessionSchema = z.object({
24
- session: z.object({ id: z.string().min(1) }),
25
- transport: z.object({ type: z.literal('webrtc'), sdp: z.string().min(1) }),
26
- });
25
+ const webRTCSessionSchema = lazySchema(() =>
26
+ zodSchema(
27
+ z.object({
28
+ session: z.object({ id: z.string().min(1) }),
29
+ transport: z.object({
30
+ type: z.literal('webrtc'),
31
+ sdp: z.string().min(1),
32
+ }),
33
+ }),
34
+ ),
35
+ );
27
36
 
28
37
  export class OpenAIRealtimeModelLive implements RealtimeModelV4 {
29
38
  readonly specificationVersion = 'v4' as const;
@@ -35,7 +35,7 @@ import {
35
35
  } from '@ai-sdk/provider-utils';
36
36
  import { z } from 'zod/v4';
37
37
  import {
38
- openaiErrorDataSchema,
38
+ openaiErrorDataSchemaValidator,
39
39
  openaiFailedResponseHandler,
40
40
  } from './openai-error';
41
41
  import type { OpenAIConfig } from './openai-config';
@@ -663,7 +663,7 @@ async function convertOpenAIErrorResponse({
663
663
  }): Promise<BatchV4Error> {
664
664
  const result = await safeValidateTypes({
665
665
  value: body,
666
- schema: openaiErrorDataSchema,
666
+ schema: openaiErrorDataSchemaValidator,
667
667
  });
668
668
 
669
669
  if (!result.success) {
@@ -6,6 +6,8 @@ import {
6
6
  type Experimental_DecisionModelV4Input as DecisionModelV4Input,
7
7
  } from '@ai-sdk/provider';
8
8
  import {
9
+ lazySchema,
10
+ zodSchema,
9
11
  combineHeaders,
10
12
  convertUint8ArrayToBase64,
11
13
  detectMediaType,
@@ -27,54 +29,63 @@ import { openaiDecisionModelOptions } from './openai-decision-model-options';
27
29
 
28
30
  export type OpenAIDecisionModelId = 'gpt-6-luna' | (string & {});
29
31
 
30
- const probability = z.number().min(0).max(1);
31
- const responseSchema = z.object({
32
- model: z.string().nullish(),
33
- usage: z
34
- .object({
35
- input_tokens: z.number().nullish(),
36
- input_tokens_details: z
32
+ const probability = () => z.number().min(0).max(1);
33
+ const responseSchema = lazySchema(() =>
34
+ zodSchema(
35
+ z.object({
36
+ model: z.string().nullish(),
37
+ usage: z
37
38
  .object({
38
- cached_tokens: z.number().nullish(),
39
- cache_write_tokens: z.number().nullish(),
39
+ input_tokens: z.number().nullish(),
40
+ input_tokens_details: z
41
+ .object({
42
+ cached_tokens: z.number().nullish(),
43
+ cache_write_tokens: z.number().nullish(),
44
+ })
45
+ .nullish(),
46
+ output_tokens: z.number().nullish(),
47
+ output_tokens_details: z
48
+ .object({
49
+ reasoning_tokens: z.number().nullish(),
50
+ })
51
+ .nullish(),
52
+ total_tokens: z.number().nullish(),
40
53
  })
41
54
  .nullish(),
42
- output_tokens: z.number().nullish(),
43
- output_tokens_details: z
44
- .object({
45
- reasoning_tokens: z.number().nullish(),
46
- })
47
- .nullish(),
48
- total_tokens: z.number().nullish(),
49
- })
50
- .nullish(),
51
- answers: z.array(
52
- z.discriminatedUnion('type', [
53
- z.object({ type: z.literal('refusal'), name: z.string().nullable() }),
54
- z.object({
55
- type: z.literal('predicate'),
56
- name: z.string(),
57
- probability,
58
- }),
59
- z.object({
60
- type: z.literal('choice'),
61
- name: z.string(),
62
- choice: z.string(),
63
- confidence: probability.nullish(),
64
- probabilities: z.array(z.object({ value: z.string(), probability })),
65
- }),
66
- z.object({
67
- type: z.literal('score'),
68
- name: z.string(),
69
- score: z.number(),
70
- confidence: probability.nullish(),
71
- probabilities: z.array(
72
- z.object({ value: z.number().int().nonnegative(), probability }),
73
- ),
74
- }),
75
- ]),
55
+ answers: z.array(
56
+ z.discriminatedUnion('type', [
57
+ z.object({ type: z.literal('refusal'), name: z.string().nullable() }),
58
+ z.object({
59
+ type: z.literal('predicate'),
60
+ name: z.string(),
61
+ probability: probability(),
62
+ }),
63
+ z.object({
64
+ type: z.literal('choice'),
65
+ name: z.string(),
66
+ choice: z.string(),
67
+ confidence: probability().nullish(),
68
+ probabilities: z.array(
69
+ z.object({ value: z.string(), probability: probability() }),
70
+ ),
71
+ }),
72
+ z.object({
73
+ type: z.literal('score'),
74
+ name: z.string(),
75
+ score: z.number(),
76
+ confidence: probability().nullish(),
77
+ probabilities: z.array(
78
+ z.object({
79
+ value: z.number().int().nonnegative(),
80
+ probability: probability(),
81
+ }),
82
+ ),
83
+ }),
84
+ ]),
85
+ ),
86
+ }),
76
87
  ),
77
- });
88
+ );
78
89
 
79
90
  export class DecisionOpenAIModel implements DecisionModelV4 {
80
91
  readonly specificationVersion = 'v4';
@@ -114,6 +125,8 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
114
125
  async doDecide({
115
126
  state,
116
127
  questions,
128
+ maxOutputTokens,
129
+ reasoning,
117
130
  headers,
118
131
  abortSignal,
119
132
  providerOptions,
@@ -302,12 +315,20 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
302
315
  },
303
316
  // The Decisions API reports probabilities and scores to two decimal places.
304
317
  rounding: { probabilityDecimals: 2, scoreDecimals: 2 },
305
- warnings: Object.keys(providerOptions?.openai ?? {})
306
- .filter(option => option !== 'safetyIdentifier')
307
- .map(option => ({
308
- type: 'unsupported',
309
- feature: `providerOptions.openai.${option}`,
310
- })),
318
+ warnings: [
319
+ ...(maxOutputTokens != null
320
+ ? [{ type: 'unsupported' as const, feature: 'maxOutputTokens' }]
321
+ : []),
322
+ ...(reasoning != null
323
+ ? [{ type: 'unsupported' as const, feature: 'reasoning' }]
324
+ : []),
325
+ ...Object.keys(providerOptions?.openai ?? {})
326
+ .filter(option => option !== 'safetyIdentifier')
327
+ .map(option => ({
328
+ type: 'unsupported' as const,
329
+ feature: `providerOptions.openai.${option}`,
330
+ })),
331
+ ],
311
332
  providerMetadata: {
312
333
  openai: {
313
334
  ...(response.usage == null ? {} : { usage: response.usage }),
@@ -1,22 +1,30 @@
1
1
  import { z } from 'zod/v4';
2
- import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
2
+ import {
3
+ lazySchema,
4
+ zodSchema,
5
+ createJsonErrorResponseHandler,
6
+ } from '@ai-sdk/provider-utils';
3
7
 
4
- export const openaiErrorDataSchema = z.object({
5
- error: z.object({
6
- message: z.string(),
8
+ export const openaiErrorDataSchema = () =>
9
+ z.object({
10
+ error: z.object({
11
+ message: z.string(),
7
12
 
8
- // The additional information below is handled loosely to support
9
- // OpenAI-compatible providers that have slightly different error
10
- // responses:
11
- type: z.string().nullish(),
12
- param: z.any().nullish(),
13
- code: z.union([z.string(), z.number()]).nullish(),
14
- }),
15
- });
13
+ // The additional information below is handled loosely to support
14
+ // OpenAI-compatible providers that have slightly different error
15
+ // responses:
16
+ type: z.string().nullish(),
17
+ param: z.any().nullish(),
18
+ code: z.union([z.string(), z.number()]).nullish(),
19
+ }),
20
+ });
21
+ export const openaiErrorDataSchemaValidator = lazySchema(() =>
22
+ zodSchema(openaiErrorDataSchema()),
23
+ );
16
24
 
17
- export type OpenAIErrorData = z.infer<typeof openaiErrorDataSchema>;
25
+ export type OpenAIErrorData = z.infer<ReturnType<typeof openaiErrorDataSchema>>;
18
26
 
19
27
  export const openaiFailedResponseHandler = createJsonErrorResponseHandler({
20
- errorSchema: openaiErrorDataSchema,
28
+ errorSchema: openaiErrorDataSchemaValidator,
21
29
  errorToMessage: data => data.error.message,
22
30
  });
@@ -9,6 +9,12 @@ export type OpenAIResponsesUsage = JSONObject & {
9
9
  | (JSONObject & {
10
10
  cached_tokens?: number | null;
11
11
  cache_write_tokens?: number | null;
12
+ cache_write_tokens_details?:
13
+ | (JSONObject & {
14
+ ttl_30m_tokens?: number | null;
15
+ ttl_12h_tokens?: number | null;
16
+ })
17
+ | null;
12
18
  orchestration_input_tokens?: number | null;
13
19
  orchestration_input_cached_tokens?: number | null;
14
20
  })
@@ -8,6 +8,9 @@ import {
8
8
  type SharedV4Warning,
9
9
  } from '@ai-sdk/provider';
10
10
  import {
11
+ lazySchema,
12
+ zodSchema,
13
+ type InferSchema,
11
14
  convertToBase64,
12
15
  getTopLevelMediaType,
13
16
  isNonNullable,
@@ -39,6 +42,7 @@ import type {
39
42
  OpenAIResponsesCustomToolCallOutput,
40
43
  OpenAIResponsesFunctionCallOutput,
41
44
  OpenAIResponsesInput,
45
+ OpenAIResponsesPromptCacheBreakpoint,
42
46
  OpenAIResponsesReasoning,
43
47
  OpenAIResponsesToolCaller,
44
48
  OpenAIResponsesWebSearchCall,
@@ -144,7 +148,7 @@ async function convertFunctionToolResultOutput({
144
148
  output: LanguageModelV4ToolResultOutput;
145
149
  toolName: string;
146
150
  outputSchemaToolNames: Set<string> | undefined;
147
- promptCacheBreakpoint?: OpenAIPromptCacheBreakpoint;
151
+ promptCacheBreakpoint?: OpenAIResponsesPromptCacheBreakpoint;
148
152
  providerOptionsName: string;
149
153
  warnings: Array<SharedV4Warning>;
150
154
  }): Promise<OpenAIResponsesFunctionCallOutput['output']> {
@@ -389,14 +393,12 @@ function collectCompleteParallelToolResultGroups({
389
393
  return completeGroups;
390
394
  }
391
395
 
392
- type OpenAIPromptCacheBreakpoint = { mode: 'explicit' };
393
-
394
396
  function getPromptCacheBreakpoint(
395
397
  providerOptions: SharedV4ProviderOptions | undefined,
396
398
  providerOptionsName: string,
397
- ): OpenAIPromptCacheBreakpoint | undefined {
399
+ ): OpenAIResponsesPromptCacheBreakpoint | undefined {
398
400
  return providerOptions?.[providerOptionsName]?.promptCacheBreakpoint as
399
- | OpenAIPromptCacheBreakpoint
401
+ | OpenAIResponsesPromptCacheBreakpoint
400
402
  | undefined;
401
403
  }
402
404
 
@@ -408,7 +410,7 @@ function getScalarToolResultPromptCacheBreakpoint({
408
410
  output: LanguageModelV4ToolResultOutput;
409
411
  toolResultProviderOptions: SharedV4ProviderOptions | undefined;
410
412
  providerOptionsName: string;
411
- }): OpenAIPromptCacheBreakpoint | undefined {
413
+ }): OpenAIResponsesPromptCacheBreakpoint | undefined {
412
414
  return output.type === 'content'
413
415
  ? undefined
414
416
  : (getPromptCacheBreakpoint(output.providerOptions, providerOptionsName) ??
@@ -1224,6 +1226,9 @@ export async function convertToOpenAIResponsesInput({
1224
1226
  input.push({
1225
1227
  type: 'shell_call_output',
1226
1228
  call_id: part.toolCallId,
1229
+ ...(parsedOutput.maxOutputLength != null && {
1230
+ max_output_length: parsedOutput.maxOutputLength,
1231
+ }),
1227
1232
  output: parsedOutput.output.map(item => ({
1228
1233
  stdout: item.stdout,
1229
1234
  stderr: item.stderr,
@@ -1565,6 +1570,9 @@ export async function convertToOpenAIResponsesInput({
1565
1570
  input.push({
1566
1571
  type: 'shell_call_output',
1567
1572
  call_id: part.toolCallId,
1573
+ ...(parsedOutput.maxOutputLength != null && {
1574
+ max_output_length: parsedOutput.maxOutputLength,
1575
+ }),
1568
1576
  output: parsedOutput.output.map(item => ({
1569
1577
  stdout: item.stdout,
1570
1578
  stderr: item.stderr,
@@ -1848,11 +1856,15 @@ export async function convertToOpenAIResponsesInput({
1848
1856
  return { input, warnings };
1849
1857
  }
1850
1858
 
1851
- const openaiResponsesReasoningProviderOptionsSchema = z.object({
1852
- itemId: z.string().nullish(),
1853
- reasoningEncryptedContent: z.string().nullish(),
1854
- });
1859
+ const openaiResponsesReasoningProviderOptionsSchema = lazySchema(() =>
1860
+ zodSchema(
1861
+ z.object({
1862
+ itemId: z.string().nullish(),
1863
+ reasoningEncryptedContent: z.string().nullish(),
1864
+ }),
1865
+ ),
1866
+ );
1855
1867
 
1856
- export type OpenAIResponsesReasoningProviderOptions = z.infer<
1868
+ export type OpenAIResponsesReasoningProviderOptions = InferSchema<
1857
1869
  typeof openaiResponsesReasoningProviderOptionsSchema
1858
1870
  >;