From 57134d2af2adf4b53f23b4cac3dd4caff7511fef Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Fri, 30 Oct 2026 01:21:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=81=A5=E5=BA=B7=E6=8E=A2=E6=B5=8B?= =?UTF-8?q?=E5=AF=B9=20Anthropic=20=E6=B8=A0=E9=81=93=E8=A1=A5=E5=8F=91=20?= =?UTF-8?q?x-api-key=20=E4=B8=8E=20anthropic-version=20=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 官方 Anthropic API 只认 x-api-key,之前只发 Bearer 会让 Anthropic 渠道 持续探测失败被误进 cooldown、流量归零。两个认证头并存互不干扰。 --- server/internal/channel/health.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/internal/channel/health.go b/server/internal/channel/health.go index 648b45c..1cc71ac 100644 --- a/server/internal/channel/health.go +++ b/server/internal/channel/health.go @@ -86,6 +86,15 @@ func (h *HealthMonitor) probe(ch *store.Channel) { req, _ := http.NewRequest(http.MethodGet, url, nil) req.Header.Set("Authorization", "Bearer "+key) req.Header.Set("Accept", "application/json") + // Anthropic 官方 API 只认 x-api-key(Bearer 被忽略),探测必须带上才不会误判不健康。 + // 两个头同时发:官方 API 忽略 Bearer,OpenAI 兼容渠道忽略 x-api-key,互不干扰。 + for _, f := range ch.FormatsEffective() { + if f == store.FormatMessages { + req.Header.Set("x-api-key", key) + req.Header.Set("anthropic-version", "2023-06-01") + break + } + } resp, err := h.hc.Do(req) ok := err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 if resp != nil {