From f8c842b474c968ec53c4b7292c5b3c29c46de033 Mon Sep 17 00:00:00 2001 From: Cosmo Date: Fri, 1 May 2026 12:21:15 +0000 Subject: [PATCH] fix: use undici ProxyAgent for Anthropic API (native fetch ignores agent) --- app/api/voice/chat/route.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/api/voice/chat/route.ts b/app/api/voice/chat/route.ts index a4a7ead..45a32a6 100644 --- a/app/api/voice/chat/route.ts +++ b/app/api/voice/chat/route.ts @@ -2,7 +2,7 @@ export const dynamic = 'force-dynamic' export const runtime = 'nodejs' import { NextResponse } from 'next/server' -import { HttpsProxyAgent } from 'https-proxy-agent' +import { fetch as undiciFetch, ProxyAgent } from 'undici' import { voiceBus } from '@/lib/voice-bus' import { systemPrompt } from '@/lib/voice-prompts' @@ -110,10 +110,11 @@ async function claudeRequest(system: string, messages: any[], tools?: any[]): Pr } if (ANTHROPIC_PROXY) { - fetchOptions.agent = new HttpsProxyAgent(ANTHROPIC_PROXY) + fetchOptions.dispatcher = new ProxyAgent(ANTHROPIC_PROXY) } - const res = await fetch('https://api.anthropic.com/v1/messages', fetchOptions) + const fetchFn = ANTHROPIC_PROXY ? undiciFetch : fetch + const res = await fetchFn('https://api.anthropic.com/v1/messages', fetchOptions) if (!res.ok) { const err = await res.text()