Skip to content

Fix proxy handling for API-key upstream fetches#451

Merged
icebear0828 merged 1 commit into
devfrom
fix/api-key-upstream-proxy
May 12, 2026
Merged

Fix proxy handling for API-key upstream fetches#451
icebear0828 merged 1 commit into
devfrom
fix/api-key-upstream-proxy

Conversation

@SsuJojo
Copy link
Copy Markdown
Collaborator

@SsuJojo SsuJojo commented May 7, 2026

Summary

  • Add a shared undici fetch dispatcher helper that uses configured tls.proxy_url or HTTPS_PROXY/https_proxy
  • Apply the dispatcher to OpenAI-compatible/custom and Gemini API-key upstream fetch calls
  • Add unit coverage for dispatcher behavior and env fallback before config load

Test plan

  • npm test -- tests/unit/proxy/fetch-dispatcher.test.ts
  • npm run build

@icebear0828
Copy link
Copy Markdown
Owner

Review notes:

这个方向是对的,但目前覆盖还不完整,建议合并前补一下:

  1. Anthropic API-key upstream 还没有走代理。当前只改了 src/proxy/openai-upstream.ts 和 src/proxy/gemini-upstream.ts,src/proxy/anthropic-upstream.ts 仍然是裸 fetch,所以 anthropic/... 路由仍会直连。
  2. undici ProxyAgent 不支持 socks5://。项目现有代理探测/配置里有 SOCKS 场景,如果用户配置 socks5://127.0.0.1:1080,这里会直接抛 Invalid URL protocol。
  3. 现在只读 getConfig().tls.proxy_url,没有使用启动时 auto-detect 缓存的 getProxyUrl()。所以依赖自动探测 Clash/mihomo 的用户,在 API-key upstream 路径里仍然不会走代理。

建议统一接入现有代理解析语义:显式 proxy_url 优先,auto-detected global proxy 兜底,明确处理 null/direct,并补 Anthropic + auto-detect + SOCKS/不支持 SOCKS 的测试。

@icebear0828 icebear0828 merged commit c541edc into dev May 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants