Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .changeset/small-buses-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
'@ai-sdk/provider-utils': major
'@ai-sdk/openai': major
---

### `@ai-sdk/openai`: remove redundant `name` argument from `openai.tools.customTool()`

`openai.tools.customTool()` no longer accepts a `name` field. the tool name is now derived from the sdk tool key (the object key in the `tools` object).

migration: remove the `name` property from `customTool()` calls. the object key is now used as the tool name sent to the openai api.

before:

```ts
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: '...',
}),
}
```

after:

```ts
tools: {
write_sql: openai.tools.customTool({
description: '...',
}),
}
```

### `@ai-sdk/provider-utils`: `createToolNameMapping()` no longer accepts the `resolveProviderToolName` parameter

before: tool name can be set dynamically

```ts
const toolNameMapping = createToolNameMapping({
tools,
providerToolNames: {
'openai.code_interpreter': 'code_interpreter',
'openai.file_search': 'file_search',
'openai.image_generation': 'image_generation',
'openai.local_shell': 'local_shell',
'openai.shell': 'shell',
'openai.web_search': 'web_search',
'openai.web_search_preview': 'web_search_preview',
'openai.mcp': 'mcp',
'openai.apply_patch': 'apply_patch',
},
resolveProviderToolName: tool =>
tool.id === 'openai.custom'
? (tool.args as { name?: string }).name
: undefined,
});
```

after: tool name is static based on `tools` keys

```
const toolNameMapping = createToolNameMapping({
tools,
providerToolNames: {
'openai.code_interpreter': 'code_interpreter',
'openai.file_search': 'file_search',
'openai.image_generation': 'image_generation',
'openai.local_shell': 'local_shell',
'openai.shell': 'shell',
'openai.web_search': 'web_search',
'openai.web_search_preview': 'web_search_preview',
'openai.mcp': 'mcp',
'openai.apply_patch': 'apply_patch',
}
});
```
3 changes: 0 additions & 3 deletions content/providers/01-ai-sdk-providers/03-openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ const result = await generateText({
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand Down Expand Up @@ -1144,7 +1143,6 @@ const result = streamText({
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand All @@ -1167,7 +1165,6 @@ for await (const chunk of result.fullStream) {

The custom tool can be configured with:

- **name** _string_ (required) - The name of the custom tool. Used to identify the tool in tool calls.
- **description** _string_ (optional) - A description of what the tool does, to help the model understand when to use it.
- **format** _object_ (optional) - The output format constraint. Omit for unconstrained text output.
- **type** _'grammar' | 'text'_ - The format type. Use `'grammar'` for constrained output or `'text'` for explicit unconstrained text.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run(async () => {
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run(async () => {
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ run(async () => {
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ run(async () => {
model: openai.responses('gpt-5.2-codex'),
tools: {
write_sql: openai.tools.customTool({
name: 'write_sql',
description: 'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
Expand Down
1 change: 0 additions & 1 deletion packages/openai/src/openai-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const openaiTools = {
* Lark syntax). The model returns a `custom_tool_call` output item whose
* `input` field is a string matching the specified grammar.
*
* @param name - The name of the custom tool.
* @param description - An optional description of the tool.
* @param format - The output format constraint (grammar type, syntax, and definition).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3942,46 +3942,6 @@ describe('convertToOpenAIResponsesInput', () => {
`);
});

it('should convert aliased tool name to provider custom tool name', async () => {
const result = await convertToOpenAIResponsesInput({
toolNameMapping: {
toProviderToolName: name =>
name === 'alias_name' ? 'write_sql' : name,
toCustomToolName: name =>
name === 'write_sql' ? 'alias_name' : name,
},
prompt: [
{
role: 'assistant',
content: [
{
type: 'tool-call',
toolCallId: 'call_custom_004',
toolName: 'alias_name',
input: 'SELECT 1',
},
],
},
],
systemMessageMode: 'system',
providerOptionsName: 'openai',
store: true,
customProviderToolNames,
});

expect(result.input).toMatchInlineSnapshot(`
[
{
"call_id": "call_custom_004",
"id": undefined,
"input": "SELECT 1",
"name": "write_sql",
"type": "custom_tool_call",
},
]
`);
});

it('should convert custom tool result content output', async () => {
const result = await convertToOpenAIResponsesInput({
toolNameMapping: testToolNameMapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4098,7 +4098,6 @@ describe('OpenAIResponsesLanguageModel', () => {
id: 'openai.custom',
name: 'write_sql',
args: {
name: 'write_sql',
description:
'Write a SQL SELECT query to answer the user question.',
format: {
Expand Down Expand Up @@ -4169,45 +4168,6 @@ describe('OpenAIResponsesLanguageModel', () => {
}
`);
});

it('should map aliased custom tool names in toolChoice and response parsing', async () => {
prepareJsonFixtureResponse('openai-custom-tool.1');

const aliasedResult = await createModel('gpt-5.2-codex').doGenerate({
prompt: TEST_PROMPT,
toolChoice: { type: 'tool', toolName: 'alias_name' },
tools: [
{
type: 'provider',
id: 'openai.custom',
name: 'alias_name',
args: {
name: 'write_sql',
description:
'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
syntax: 'regex',
definition: 'SELECT .+',
},
},
},
],
});

expect(
(await server.calls.at(-1)!.requestBodyJson).tool_choice,
).toStrictEqual({
type: 'custom',
name: 'write_sql',
});

const toolCall = aliasedResult.content.find(
part => part.type === 'tool-call',
);
expect(toolCall).toBeDefined();
expect((toolCall as { toolName: string }).toolName).toBe('alias_name');
});
});

it('should handle computer use tool calls', async () => {
Expand Down Expand Up @@ -5766,7 +5726,6 @@ describe('OpenAIResponsesLanguageModel', () => {
id: 'openai.custom',
name: 'write_sql',
args: {
name: 'write_sql',
description:
'Write a SQL SELECT query to answer the user question.',
format: {
Expand Down Expand Up @@ -5867,47 +5826,6 @@ describe('OpenAIResponsesLanguageModel', () => {
]
`);
});

it('should map aliased custom tool names while streaming', async () => {
prepareChunksFixtureResponse('openai-custom-tool.1');

const { stream } = await createModel('gpt-5.2-codex').doStream({
tools: [
{
type: 'provider',
id: 'openai.custom',
name: 'alias_name',
args: {
name: 'write_sql',
description:
'Write a SQL SELECT query to answer the user question.',
format: {
type: 'grammar',
syntax: 'regex',
definition: 'SELECT .+',
},
},
},
],
toolChoice: { type: 'tool', toolName: 'alias_name' },
prompt: TEST_PROMPT,
includeRawChunks: false,
});

expect(
(await server.calls.at(-1)!.requestBodyJson).tool_choice,
).toStrictEqual({
type: 'custom',
name: 'write_sql',
});

const parts = await convertReadableStreamToArray(stream);
const streamToolCall = parts.find(part => part.type === 'tool-call');
expect(streamToolCall).toBeDefined();
expect((streamToolCall as { toolName: string }).toolName).toBe(
'alias_name',
);
});
});

describe('web search tool', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
'openai.apply_patch': 'apply_patch',
'openai.tool_search': 'tool_search',
},
resolveProviderToolName: tool =>
tool.id === 'openai.custom'
? (tool.args as { name?: string }).name
: undefined,
});

const customProviderToolNames = new Set<string>();
Expand Down
Loading
Loading