OpenAI Responses drops tool-call names constructor and toString
Description
Valid tool names matching Object.prototype properties are changed when the OpenAI Responses provider serializes tool-call history.
At the unmodified checkout, lookup keeps its name, but constructor and toString lose the name property entirely. __proto__ becomes "name": {}. The shared createToolNameMapping helper returns inherited functions/objects instead of the original string when no alias exists. A provider-defined tool aliased to __proto__ also fails to map.
Found through source inspection, then reproduced using built local workspace packages and the public OpenAI provider API. This is not a report of a production incident. The request was intercepted before network I/O; no live OpenAI response or API rejection is claimed.
Expected: unmapped tool names are preserved as strings, and explicit provider aliases work for these names too.
Reproduction
From a checkout at d55f3cfc456d1b7bc7db3a4b70fbf602ddc8647d, install the workspace dependencies and build the local packages:
pnpm install --filter @ai-sdk/provider-utils... --filter @ai-sdk/openai... --filter ai... --frozen-lockfile
pnpm exec turbo build --filter=@ai-sdk/openai... --filter=ai... --filter=!konsistent-provider
Save the following as a temporary repro.mjs outside the checkout and pipe it to node --input-type=module from packages/openai so the import resolves the local package:
import { createOpenAI } from '@ai-sdk/openai';
console.log(import.meta.resolve('@ai-sdk/openai'));
for (const name of ['lookup', 'constructor', 'toString', '__proto__']) {
const provider = createOpenAI({
apiKey: 'local-reproduction-not-a-real-key',
fetch: async (_url, options) => {
const body = JSON.parse(options.body);
const call = body.input.find(item => item.type === 'function_call');
console.log(JSON.stringify({ toolName: name, serializedCall: call }));
throw new Error('Captured locally; no external request sent.');
},
});
try {
await provider.responses('gpt-4.1').doGenerate({
prompt: [{
role: 'assistant',
content: [{ type: 'tool-call', toolCallId: 'call-1', toolName: name, input: '{}' }],
}],
tools: [{ type: 'function', name, inputSchema: { type: 'object', properties: {} } }],
});
} catch (error) {
console.log(error.message);
}
}
The printed package URL points to this checkout's packages/openai/dist/index.js. Relevant baseline output:
{"toolName":"lookup","serializedCall":{"type":"function_call","call_id":"call-1","name":"lookup","arguments":"{}"}}
{"toolName":"constructor","serializedCall":{"type":"function_call","call_id":"call-1","arguments":"{}"}}
{"toolName":"toString","serializedCall":{"type":"function_call","call_id":"call-1","arguments":"{}"}}
{"toolName":"__proto__","serializedCall":{"type":"function_call","call_id":"call-1","name":{},"arguments":"{}"}}
A scoped Map-based fix, patch changeset and regression cases are prepared locally. The added cases fail on unchanged code.
AI SDK Version
Upstream main d55f3cfc456d1b7bc7db3a4b70fbf602ddc8647d: @ai-sdk/[email protected], @ai-sdk/[email protected], [email protected]. Windows, Node.js 24.21.0, pnpm 12.14.0.
Prepared with Codex assistance.
Identify issue type
Identified as Bug
Confidence: High
Rationale
The issue demonstrates incorrect serialization of valid tool names in existing SDK behavior, with concrete reproduction steps and captured output.
Evidence
- Local reproduction shows OpenAI Responses serialization omits the name for tool calls named constructor and toString, and serializes proto as an object.
- The shared createToolNameMapping helper returns inherited properties instead of preserving unmapped tool-name strings; explicit aliases to proto also fail.
Identify bug discovery
Discovery source: discovery:audit (high confidence).
The author explicitly identifies source inspection as the original discovery method, followed by local reproduction, and rules out a production incident.
- “Found through source inspection, then reproduced using built local workspace packages and the public OpenAI provider API.”
- “This is not a report of a production incident.”
- The report traces the bug to createToolNameMapping returning inherited functions or objects when no alias exists.
- The reproduction intercepted requests before network I/O; no live OpenAI response or API rejection is claimed.