Skip to content

[Bug] OpenCode Go Anthropic endpoint returns 401 Missing API key (x-api-key not sent) #5

Description

@496577liuyang-hue

环境

  • ModelLink: 2.0.0(Windows x64,当前最新 release)
  • 上游:OpenCode Go
  • API 地址:https://opencode.ai/zen/go
  • 模型:qwen3.6-plus(官方标注使用 Anthropic Messages:/v1/messages

复现步骤

  1. 新增自定义服务商。
  2. API 地址填写 https://opencode.ai/zen/go
  3. 填写有效的 OpenCode Go API key。
  4. 模型填写 qwen3.6-plus
  5. 点击“测试连接”。

实际结果

返回 HTTP 401:

Missing API key.

同一个 key 在 OpenCode 官方客户端可正常使用。

根因定位

test_provider 会请求 {target_url}/v1/messages,但认证只发送:

Authorization: Bearer <provider_api_key>

OpenCode Go 的 Anthropic Messages 入口要求 x-api-key。因此虽然 UI 已填写 key,上游仍返回 Missing API key.

实际代理转发也存在同一问题:proxy_fallback 使用服务商 key 设置 Bearer,但 x-api-key 只从 Claude Desktop 的入站请求透传;与此同时 gateway.rs 自动写入的是 inferenceGatewayApiKey: "proxy"inferenceGatewayAuthScheme: "bearer",所以服务商的真实 key 不会作为 x-api-key 发给上游。

相关源码:

  • gui-tauri/src-tauri/src/commands.rstest_provider
  • gui-tauri/src-tauri/src/proxy.rsproxy_fallback
  • gui-tauri/src-tauri/src/gateway.rs:Claude Desktop gateway 配置

期望结果

ModelLink 能连接 OpenCode Go 的 Anthropic-compatible 模型,例如 qwen3.6-plusqwen3.7-plusminimax-m3

建议修复

  1. test_provider/v1/messages 同时发送:
Authorization: Bearer <provider_api_key>
x-api-key: <provider_api_key>
  1. proxy_fallbackx-api-key 应来自当前服务商的 resolved.api_key,而不是透传 Claude Desktop 到本地代理使用的客户端 key;可同时保留 Bearer,以兼容现有服务商。
  2. 更完整的方案是在服务商配置中增加认证方式(Bearer / x-api-key / both)。

注意:报告未包含任何真实 API key。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions