From 4affb6b8c56ad19dbba469183757b09fda020e94 Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Fri, 22 May 2026 18:32:56 +0800 Subject: [PATCH] feat: filter unsupported tools from Responses API requests When using Codex Desktop with `requires_openai_auth = true` and a third-party proxy (e.g. Copilot proxy), the client automatically includes `image_generation` in the tools array. Since the Copilot backend does not support this tool type, requests fail with "unsupported_value" errors. This adds a configurable filter in `handleResponses()` that strips unsupported tool types before forwarding upstream. Currently filters `image_generation`; additional types can be added to the `FILTERED_TOOL_TYPES` set. Co-Authored-By: Claude Opus 4 (1M context) --- src/routes/responses/handler.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/routes/responses/handler.ts b/src/routes/responses/handler.ts index 22fc539..6a9f5fd 100644 --- a/src/routes/responses/handler.ts +++ b/src/routes/responses/handler.ts @@ -39,6 +39,16 @@ export async function handleResponses(c: Context) { contentLength: c.req.header('content-length') ?? undefined, }) + // Filter out unsupported tools (e.g. image_generation) before forwarding + const FILTERED_TOOL_TYPES = new Set(['image_generation']) + if (payload.tools?.length) { + const before = payload.tools.length + payload.tools = payload.tools.filter(t => !FILTERED_TOOL_TYPES.has(t.type)) + if (payload.tools.length !== before) { + consola.debug(`Filtered ${before - payload.tools.length} unsupported tool(s): ${[...FILTERED_TOOL_TYPES].join(', ')}`) + } + } + if (responsesHasExternalImageUrls(payload)) { throwOpenAIInvalidRequestError(OPENAI_EXTERNAL_IMAGE_URLS_UNSUPPORTED_MESSAGE) }