Skip to content

Network

Network

Configure proxies and custom certificates.

OpenCode supports standard proxy environment variables and custom certificates for enterprise network environments.


Proxy

OpenCode respects standard proxy environment variables.

// 代理配置示例

# HTTPS 代理(推荐)
export HTTPS_PROXY=https://proxy.example.com:8080

# HTTP 代理(如果没有 HTTPS 可用)
export HTTP_PROXY=http://proxy.example.com:8080

# 绕过本地服务器的代理(必须设置)
export NO_PROXY=localhost,127.0.0.1

[!CAUTION] The TUI communicates with a local HTTP server. You must bypass the proxy for this connection to prevent routing loops.

You can configure the server’s port and hostname using CLI flags.


Authenticate

如果代理需要基本认证,请在 URL 中包含凭据:

export HTTPS_PROXY=http://username:password@proxy.example.com:8080

[!CAUTION] Avoid hardcoding passwords. Use environment variables or secure credential storage.

对于需要 NTLM 或 Kerberos 等高级认证的代理,请考虑使用支持该认证方法的 LLM Gateway。


Custom certificates

如果企业使用自定义 CA 进行 HTTPS 连接,请配置 OpenCode 信任它们:

# 自定义 CA 证书配置
export NODE_EXTRA_CA_CERTS=/path/to/ca-cert.pem

这适用于代理连接和直接 API 访问。


Enterprise network considerations

防火墙配置

确保以下域名在你的防火墙/代理中被允许:

  • opencode.ai - OpenCode 服务
  • anthropic.com - Anthropic API
  • api.openai.com - OpenAI API
  • api.together.ai - Together AI API
  • 其他 LLM provider 域名

离线安装

对于完全离线的环境,可以:

  1. GitHub releases 下载安装包
  2. 使用 npm 或 bun 本地安装
  3. 配置代理访问外部 API(如有必要)

VPN 配置

如果使用 VPN:

  1. 确保 VPN 不会干扰本地端口
  2. 将必要的域名添加到 VPN 的绕过列表中
  3. 检查 VPN 是否修改了 DNS 设置