diff --git a/open-sse/translator/formats/claude.js b/open-sse/translator/formats/claude.js index 3e93e4d5..4c8454b8 100644 --- a/open-sse/translator/formats/claude.js +++ b/open-sse/translator/formats/claude.js @@ -257,9 +257,22 @@ export function prepareClaudeRequest(body, provider = null, apiKey = null, conne // 3. Tools: filter built-in tools for non-Anthropic providers, then handle cache_control if (body.tools && Array.isArray(body.tools)) { - // Strip built-in tools (e.g. web_search_20250305) for providers that don't support them + // Strip built-in tools (e.g. web_search_20250305) and normalize to Anthropic-native shape + // (drop `type` field, fold `function.{name,description,parameters}`) for non-Anthropic providers if (provider !== "claude") { - body.tools = body.tools.filter(tool => !tool.type || tool.type === "function"); + body.tools = body.tools + .filter(tool => !tool.type || tool.type === "function") + .map(tool => { + if (tool.function) { + return { + name: tool.function.name, + description: tool.function.description, + input_schema: tool.function.parameters, + }; + } + const { type, ...rest } = tool; + return rest; + }); } body.tools = body.tools.map((tool, i) => {