mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix(chat): handle Anthropic-format tools in empty-name filter (#346)
The filter introduced in #346 only checked OpenAI-format tool names (tool.function.name), silently dropping all tools when the request arrives in Anthropic Messages API format (tool.name without .function). This happens when LiteLLM proxies requests with anthropic/ model prefix — it translates to Anthropic format before forwarding, so OmniRoute receives Claude-format tools. The filter drops them all, causing Anthropic API to return 400: 'tool_choice.any may only be specified while providing tools'. Fix: check both formats with fn?.name ?? tool.name.
This commit is contained in:
@@ -217,14 +217,16 @@ export async function handleChatCore({
|
||||
return item;
|
||||
});
|
||||
}
|
||||
// ── #346: Strip tools with empty function.name ──
|
||||
// ── #346: Strip tools with empty name ──
|
||||
// Claude Code sometimes forwards tool definitions with empty names, causing
|
||||
// OpenAI-compatible upstream providers to reject with:
|
||||
// "Invalid 'input[N].name': empty string. Expected minimum length 1."
|
||||
// Handles both OpenAI format ({ function: { name } }) and Anthropic format ({ name }).
|
||||
if (Array.isArray(translatedBody.tools)) {
|
||||
translatedBody.tools = translatedBody.tools.filter((tool: Record<string, unknown>) => {
|
||||
const fn = tool.function as Record<string, unknown> | undefined;
|
||||
return fn?.name && String(fn.name).trim().length > 0;
|
||||
const name = fn?.name ?? tool.name;
|
||||
return name && String(name).trim().length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user