@ai-sdk/openai 3.0.60 → 3.0.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai",
3
- "version": "3.0.60",
3
+ "version": "3.0.62",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -701,11 +701,17 @@ export async function convertToOpenAIResponsesInput({
701
701
  return {
702
702
  type: 'input_image' as const,
703
703
  image_url: `data:${item.mediaType};base64,${item.data}`,
704
+ detail:
705
+ item.providerOptions?.[providerOptionsName]
706
+ ?.imageDetail,
704
707
  };
705
708
  case 'image-url':
706
709
  return {
707
710
  type: 'input_image' as const,
708
711
  image_url: item.url,
712
+ detail:
713
+ item.providerOptions?.[providerOptionsName]
714
+ ?.imageDetail,
709
715
  };
710
716
  case 'file-data':
711
717
  return {
@@ -764,6 +770,9 @@ export async function convertToOpenAIResponsesInput({
764
770
  return {
765
771
  type: 'input_image' as const,
766
772
  image_url: `data:${item.mediaType};base64,${item.data}`,
773
+ detail:
774
+ item.providerOptions?.[providerOptionsName]
775
+ ?.imageDetail,
767
776
  };
768
777
  }
769
778
 
@@ -771,6 +780,9 @@ export async function convertToOpenAIResponsesInput({
771
780
  return {
772
781
  type: 'input_image' as const,
773
782
  image_url: item.url,
783
+ detail:
784
+ item.providerOptions?.[providerOptionsName]
785
+ ?.imageDetail,
774
786
  };
775
787
  }
776
788
 
@@ -213,6 +213,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
213
213
  } = await prepareResponsesTools({
214
214
  tools,
215
215
  toolChoice,
216
+ allowedTools: openaiOptions?.allowedTools ?? undefined,
216
217
  toolNameMapping,
217
218
  customProviderToolNames,
218
219
  });
@@ -316,6 +316,23 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
316
316
  * and defaults `systemMessageMode` to `developer` unless overridden.
317
317
  */
318
318
  forceReasoning: z.boolean().optional(),
319
+
320
+ /**
321
+ * Restrict the callable tools to a subset while keeping the full tools
322
+ * list intact, so prompt caching is preserved across requests with
323
+ * different allowlists.
324
+ *
325
+ * When set, this overrides the request-level `toolChoice` and emits
326
+ * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
327
+ *
328
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
329
+ */
330
+ allowedTools: z
331
+ .object({
332
+ toolNames: z.array(z.string()).min(1),
333
+ mode: z.enum(['auto', 'required']).optional(),
334
+ })
335
+ .optional(),
319
336
  }),
320
337
  ),
321
338
  );
@@ -18,11 +18,16 @@ import type { OpenAIResponsesTool } from './openai-responses-api';
18
18
  export async function prepareResponsesTools({
19
19
  tools,
20
20
  toolChoice,
21
+ allowedTools,
21
22
  toolNameMapping,
22
23
  customProviderToolNames,
23
24
  }: {
24
25
  tools: LanguageModelV3CallOptions['tools'];
25
26
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
27
+ allowedTools?: {
28
+ toolNames: string[];
29
+ mode?: 'auto' | 'required';
30
+ };
26
31
  toolNameMapping?: ToolNameMapping;
27
32
  customProviderToolNames?: Set<string>;
28
33
  }): Promise<{
@@ -39,7 +44,12 @@ export async function prepareResponsesTools({
39
44
  | { type: 'code_interpreter' }
40
45
  | { type: 'mcp' }
41
46
  | { type: 'image_generation' }
42
- | { type: 'apply_patch' };
47
+ | { type: 'apply_patch' }
48
+ | {
49
+ type: 'allowed_tools';
50
+ mode: 'auto' | 'required';
51
+ tools: Array<{ type: 'function'; name: string }>;
52
+ };
43
53
  toolWarnings: SharedV3Warning[];
44
54
  }> {
45
55
  // when the tools array is empty, change it to undefined to prevent errors:
@@ -285,6 +295,21 @@ export async function prepareResponsesTools({
285
295
  }
286
296
  }
287
297
 
298
+ if (allowedTools != null) {
299
+ return {
300
+ tools: openaiTools,
301
+ toolChoice: {
302
+ type: 'allowed_tools',
303
+ mode: allowedTools.mode ?? 'auto',
304
+ tools: allowedTools.toolNames.map(name => ({
305
+ type: 'function',
306
+ name: toolNameMapping?.toProviderToolName(name) ?? name,
307
+ })),
308
+ },
309
+ toolWarnings,
310
+ };
311
+ }
312
+
288
313
  if (toolChoice == null) {
289
314
  return { tools: openaiTools, toolChoice: undefined, toolWarnings };
290
315
  }