diff --git a/open-sse/handlers/chatCore.ts b/open-sse/handlers/chatCore.ts index f940984f82..1919add060 100644 --- a/open-sse/handlers/chatCore.ts +++ b/open-sse/handlers/chatCore.ts @@ -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) => { const fn = tool.function as Record | undefined; - return fn?.name && String(fn.name).trim().length > 0; + const name = fn?.name ?? tool.name; + return name && String(name).trim().length > 0; }); }