【Bug已解决】openclaw API endpoint unreachable / Service temporarily unavailable — OpenClaw API 端点不可达解决方案 【Bug已解决】openclaw: API endpoint unreachable / Service temporarily unavailable — OpenClaw API 端点不可达解决方案1. 问题描述OpenClaw 无法连接到 API 端点或服务暂时不可用# API 端点不可达 $ openclaw task Error: API endpoint unreachable Cannot connect to https://api.anthropic.com. # 或服务不可用 $ openclaw --print task Error: 503 Service Unavailable Anthropic API is temporarily unavailable. # 或连接超时 $ openclaw task Error: ETIMEDOUT Connection to api.anthropic.com timed out. # 或 DNS 解析失败 $ openclaw task Error: ENOTFOUND getaddrinfo ENOTFOUND api.anthropic.com.这个问题在以下场景中特别常见网络连接问题DNS 解析失败API 服务维护安全策略阻止系统时间偏差SSL 证书问题2. 原因分析原因分类具体表现占比网络问题ECONNREFUSED约 30%DNS 失败ENOTFOUND约 25%服务维护503约 20%安全策略blocked约 10%系统时间TLS 握手失败约 10%SSL 问题cert约 5%3. 解决方案方案一检查网络连接最推荐# 步骤 1检查网络 ping -c 3 api.anthropic.com # 步骤 2检查 DNS nslookup api.anthropic.com # 或 dig api.anthropic.com # 步骤 3检查连通性 curl -s -o /dev/null -w %{http_code} https://api.anthropic.com # 步骤 4验证 openclaw --print hello方案二检查服务状态# 步骤 1检查 Anthropic 状态页 # https://status.anthropic.com # 步骤 2如果 503等待恢复 echo Service temporarily unavailable, waiting... sleep 60 openclaw --print hello # 步骤 3或使用备用端点 export OPENCLAW_API_URLhttps://api.anthropic.com/v1 openclaw --print hello # 步骤 4验证 openclaw --print hello方案三修复 DNS# 步骤 1检查 DNS nslookup api.anthropic.com # 步骤 2如果 DNS 失败使用公共 DNS export DNS_SERVER8.8.8.8 nslookup api.anthropic.com 8.8.8.8 # 步骤 3或添加到 hosts echo 104.18.6.192 api.anthropic.com | sudo tee -a /etc/hosts # 步骤 4验证 nslookup api.anthropic.com openclaw --print hello方案四检查安全策略# 步骤 1检查安全策略 # macOS sudo pfctl -s rules 2/dev/null | grep -i anthropic # 步骤 2检查 iptables (Linux) sudo iptables -L | grep -i anthropic # 步骤 3如果被阻止添加规则 sudo iptables -A OUTPUT -d api.anthropic.com -j ACCEPT # 步骤 4验证 curl -s https://api.anthropic.com openclaw --print hello方案五检查系统时间同步# 步骤 1检查系统时间 date # 与标准时间对比偏差超过 5 秒会影响 TLS 握手 # 步骤 2同步系统时间 # macOS sudo systemsetup -setusingnetworktime on # Linux sudo ntpdate ntp.org # 或 sudo chronyd -q server ntp.org iburst # 步骤 3验证时间同步 date curl -sI https://api.anthropic.com | head -1 # 步骤 4测试 openclaw --print hello方案六重试与退避# 步骤 1自动重试 for i in 1 2 3 4 5; do openclaw --print hello break echo Retry $i in $((i*10)) seconds... sleep $((i*10)) done # 步骤 2或使用 --retry openclaw --retry 3 --retry-delay 10 task # 步骤 3或在配置中设置 cat .openclaw/config.json EOF { retryCount: 3, retryDelay: 10 } EOF # 步骤 4验证 openclaw --print hello4. 各方案对比总结方案适用场景推荐指数难度方案一检查网络通用⭐⭐⭐⭐⭐低方案二检查状态503⭐⭐⭐⭐⭐低方案三修复 DNSENOTFOUND⭐⭐⭐⭐⭐低方案四安全策略blocked⭐⭐⭐⭐中方案五系统时间TLS 失败⭐⭐⭐⭐⭐低方案六重试临时⭐⭐⭐⭐⭐低5. 常见问题 FAQ5.1 如何检查网络连接ping api.anthropic.com curl -s -o /dev/null -w %{http_code} https://api.anthropic.com5.2 503 错误是什么Service Unavailable。API 服务器暂时不可用等待恢复。5.3 DNS 解析失败使用公共 DNS8.8.8.8或添加到 /etc/hosts。5.4 如何检查服务状态访问 https://status.anthropic.com。5.5 安全策略阻止连接检查 iptables/pfctl添加允许规则。5.6 系统时间偏差导致 TLS 握手失败TLS 证书验证依赖系统时间。如果系统时间偏差超过 5 分钟TLS 握手会失败导致 API 端点不可达。使用date检查时间sudo ntpdate ntp.org同步。5.7 如何自动重试for i in 1 2 3; do openclaw --print hello break; sleep 10; done5.8 ETIMEDOUT 是什么连接超时。网络延迟或服务器无响应。5.9 如何添加 hostsecho 104.18.6.192 api.anthropic.com | sudo tee -a /etc/hosts5.10 排查清单速查表□ 1. ping api.anthropic.com 检查网络 □ 2. nslookup 检查 DNS □ 3. curl -s -w http_code 检查连通 □ 4. status.anthropic.com 检查服务 □ 5. 503 等待 60s 重试 □ 6. 8.8.8.8 公共 DNS □ 7. /etc/hosts 添加 IP □ 8. date 检查系统时间同步 □ 9. iptables/pfctl 检查安全策略 □ 10. for 循环自动重试6. 总结根本原因API 不可达最常见原因是网络问题30%和 DNS 失败25%最佳实践使用ping和curl检查网络连通性503 处理检查 status.anthropic.com等待 60 秒后重试DNS 修复使用公共 DNS8.8.8.8或添加到 /etc/hosts最佳实践建议配置自动重试for i in 1 2 3; do openclaw break; sleep 10; done故障排查流程图flowchart TD A[API 不可达] -- B[ping api.anthropic.com] B -- C{网络通?} C --|否| D[检查 DNS] C --|是| E[curl 检查 HTTP] D -- F[nslookup] F -- G{DNS 解析?} G --|否| H[使用 8.8.8.8] G --|是| I[检查安全策略] H -- j[或 /etc/hosts 添加 IP] j -- E I -- K[iptables/pfctl] K -- L{被阻止?} L --|是| M[添加允许规则] L --|否| N[检查系统时间] M -- E N -- O[date 命令] O -- P{时间正确?} P --|否| Q[ntpdate 同步时间] P --|是| R[检查服务状态] Q -- E E -- S{HTTP 200?} S --|是| T[✅ 问题解决] S --|否, 503| U[服务不可用] S --|否, 其他| V[检查 SSL] U -- W[status.anthropic.com] W -- X[等待 60s 重试] X -- Y[for 循环自动重试] Y -- E V -- Z[更新 ca-certificates] Z -- E E -- AA{成功?} AA --|是| T AA --|否| AB[配置重试] AB -- AC[retryCount retryDelay] AC -- Y T -- AD[长期: 网络检查 DNS 重试] AD -- AE[✅ 长期方案]