Anthropic adapter drops `additionalProperties: false`, and typed `modelOptions.tool_choice` sends the Responses shape to Chat Completions #2141
Send to my agentTanStack AI version#
@tanstack/ai0.58.0,@tanstack/ai-openai0.23.1,@tanstack/ai-anthropic0.18.11 (commitaaff1128). Both code paths below are unchanged on mainat4a9ddc73, except that a new core toolChoice` option exists.
Framework/Library version#
Node 22, no UI framework (server-side chat()), openai 6.41.0, @anthropic-ai/sdk 0.97.1
Describe the bug and the steps to reproduce it#
We found two places where a constraint the application sets through the public API is changed before the request is sent. We found this while testing how SDKs carry tool-call constraints to the provider.
Anthropic:
additionalProperties: falseis removed.convertCustomToolToAdapterFormat(packages/ai-anthropic/src/tools/custom-tool.ts:39-43) buildsinput_schemaas{type: 'object', properties, required}only. Any other top-level keyword in the tool'sinputSchemais lost, includingadditionalProperties: false.Steps: declare a tool with
inputSchema{type: 'object', properties: {...}, required: [...], additionalProperties: false}, callchat()withcreateAnthropicChat(...)and abaseURLthat points at a local server that logs requests, and look attools[].input_schema. Captured: keystype,properties,requiredonly.OpenAI Chat Completions: the typed
modelOptions.tool_choicefunction variant is{type: 'function', name}(packages/openai-base/src/tools/tool-choice.ts), which is the Responses API shape. The Chat Completions adapter spreadsmodelOptionsinto the body unchanged (chat-completions-text.ts:1246-1258), so the request carries"tool_choice": {"type": "function", "name": "lookup_order"}. Chat Completions expects{"type": "function", "function": {"name": "lookup_order"}}. On currentmainthe newchat({ toolChoice })option maps correctly, but amodelOptions.tool_choicestill wins, and its type still only allows the Responses shape.
Expected: (1) input_schema keeps additionalProperties: false. (2) A typed modelOptions.tool_choice produces the Chat Completions shape, or the Chat Completions options type only allows that shape.
Actual: (1) the keyword is gone. In our test the model's call with an extra argument ran (server tool) or was handed back (client tool) when inputSchema was plain JSON Schema. (2) The named-tool choice is in the wrong shape. In our test the server answered with a different tool (issue_refund), which ran.
Your Minimal, Reproducible Example
(link to be added) The core of it:
import { chat, toolDefinition } from '@tanstack/ai'
import { createAnthropicChat } from '@tanstack/ai-anthropic'
import { createOpenaiChatCompletions } from '@tanstack/ai-openai'
const schema = {
type: 'object',
properties: { order_id: { type: 'string', pattern: '^ORD-[0-9]{6}$' } },
required: ['order_id'],
additionalProperties: false,
}
const lookupOrder = toolDefinition({ name: 'lookup_order', description: 'Look up an order', inputSchema: schema })
// 1. Anthropic: captured input_schema has no additionalProperties
for await (const _ of chat({
adapter: createAnthropicChat('claude-sonnet-4-5', 'sk-dummy', { baseURL: 'http://127.0.0.1:8080' }),
messages: [{ role: 'user', content: 'Check order ORD-123456' }],
tools: [lookupOrder],
})) {}
// 2. Chat Completions: captured tool_choice is {"type":"function","name":"lookup_order"}
for await (const _ of chat({
adapter: createOpenaiChatCompletions('gpt-4o', 'sk-dummy', { baseURL: 'http://127.0.0.1:8080/v1' }),
messages: [{ role: 'user', content: 'Check order ORD-123456' }],
tools: [lookupOrder],
modelOptions: { tool_choice: { type: 'function', name: 'lookup_order' } },
})) {}
Impact: an application that closes its tool schema or forces a specific tool through the documented options does not get that constraint at the provider, and nothing reports it.
Suggested fix: (1) spread the original inputSchema into input_schema and then set type, properties and required. (2) Type the Chat Completions tool_choice with the Chat Completions function shape, or convert the Responses shape in the Chat Completions adapter.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)#
### Screenshots or Videos (Optional)
_No response_
### Do you intend to try to help solve this bug with your own PR?
None
### Terms & Code of Conduct
- [x] I agree to follow this project's Code of Conduct
- [x] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
Sign in to join this conversation.