Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(responses): tolerate non-function tool types from Codex CLI (#187)

Tashfeen5d32fa684361
diff --git a/server/src/routes/responses.ts b/server/src/routes/responses.ts
index eb37adda..81c66ce1 100644
--- a/server/src/routes/responses.ts
+++ b/server/src/routes/responses.ts
@@ -82,9 +82,14 @@ const inputItemSchema = z.union([
messageItemSchema,
]);
+// Accept ANY tool type, not just 'function'. Codex (Responses API) sends
+// built-in tools like `web_search` / `local_shell` alongside function tools;
+// a strict z.literal('function') rejected the whole request. We validate
+// loosely here and drop non-function tools at conversion (toChatTools), since
+// chat-completions providers only accept type:'function'.
const responsesToolSchema = z.object({
- type: z.literal('function'),
- name: z.string(),
+ type: z.string(),
+ name: z.string().optional(),
description: z.string().nullable().optional(),
parameters: z.record(z.string(), z.unknown()).nullable().optional(),
strict: z.boolean().nullable().optional(),
@@ -180,7 +185,13 @@ export function toChatMessages(req: ResponsesRequest): ChatMessage[] {
export function toChatTools(tools?: ResponsesRequest['tools']): ChatToolDefinition[] | undefined {
if (!tools?.length) return undefined;
- return tools.map((t) => ({
+ // Forward only function tools — chat-completions upstreams reject other
+ // Responses-API tool types (web_search, local_shell, etc.). Codex sends those
+ // extras alongside its function tools (shell/exec, apply_patch); dropping them
+ // keeps the request valid without losing the tools that actually do the work.
+ const fns = tools.filter((t): t is typeof t & { name: string } => t.type === 'function' && typeof t.name === 'string');
+ if (!fns.length) return undefined;
+ return fns.map((t) => ({
type: 'function',
function: {
name: t.name,