fix: use undici ProxyAgent for Anthropic API (native fetch ignores agent)
All checks were successful
Deploy / deploy (push) Successful in 1m30s
All checks were successful
Deploy / deploy (push) Successful in 1m30s
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user