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()