Skip to content

[Bug]: kimi-coding provider uses wrong endpoint + User-Agent for sk-kimi-* keys, breaking all API calls including vision #43617

Closed as not planned

Description

@runxinZH

Bug Description

Environment

  • Hermes version: v0.16.0
  • Provider: kimi-coding
  • Model: kimi-k2.6
  • API key type: sk-kimi-* (Kimi Code / Coding Agent key)

Problem

When using a sk-kimi-* key with provider: kimi-coding, all API calls fail with 401 Invalid Authentication.
Consequently, vision tasks also break because the requests never reach the model.

This happens even though the same sk-kimi-* key works fine in other Coding Agents (e.g. OpenClaw, Claude Code, Roo Code).

Root cause

The bundled kimi-coding provider profile currently points to:

base_url="https://api.moonshot.ai/v1"
default_headers={"User-Agent": "hermes-agent/1.0"}

However, sk-kimi-* keys are Kimi Code keys and are only accepted by the api.kimi.com/coding endpoint.
Furthermore, that endpoint requires User-Agent: claude-code/0.1.0 (or another recognised Coding Agent UA) to pass authorisation.

Verified combinations:

┌─────────────────────────────────────────┬───────────────────┬────────┐
│ Endpoint                                │ User-Agent        │ Result │
├─────────────────────────────────────────┼───────────────────┼────────┤
│ api.moonshot.ai/v1/chat/completions     │ hermes-agent/1.0  │ 401 ❌ │
│ api.kimi.com/coding/v1/chat/completions │ hermes-agent/1.0  │ 403 ❌ │
│ api.kimi.com/coding/v1/chat/completions │ claude-code/0.1.0 │ 200 ✅ │
│ api.kimi.com/coding/v1/messages         │ claude-code/0.1.0 │ 200 ✅ │
└─────────────────────────────────────────┴───────────────────┴────────┘

Note: api.kimi.com/coding supports both OpenAI and Anthropic wire protocols; the protocol choice is not the issue. The issue is the wrong endpoint and missing Coding-Agent User-Agent.

Suggested fix
─────────────
Update plugins/model-providers/kimi-coding/__init__.py:

base_url="https://api.kimi.com/coding",
default_headers={"User-Agent": "claude-code/0.1.0"},

And apply the same change to kimi-coding-cn.

Related
───────
The _endpoint_speaks_anthropic_messages() helper in agent/auxiliary_client.py explicitly avoids forcing Anthropic wrapping for api.kimi.com/coding because kimi-k2.6 supports vision via OpenAI wire. This is correct — the fix should keep the OpenAI wire and only change the endpoint + User-Agent.

Workaround (for users)
──────────────────────
Until this is merged, override in config.yaml:

model:
  provider: kimi-coding
  base_url: https://api.kimi.com/coding

# Also update auxiliary.vision if configured
auxiliary:
  vision:
    provider: custom
    base_url: https://api.kimi.com/coding
    model: kimi-k2.6

And patch the User-Agent in the provider profile or via a local proxy.

### Steps to Reproduce

1.run hermes agent
2.send a img to analyzing

### Expected Behavior

smoothly understanding image

### Actual Behavior

output a 401/ 403 error

### Affected Component

Configuration (config.yaml, .env, hermes setup)

### Messaging Platform (if gateway-related)

_No response_

### Debug Report

```shell
Debug report uploaded:
Report       https://paste.rs/x5Dlz
agent.log    https://paste.rs/Klveu
gateway.log  https://paste.rs/sbwPK

Operating System

macOS 26.5

Python Version

No response

Hermes Version

0.16.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    P2Medium — degraded but workaround exists
    on Jun 10, 2026
  2. liuhao1024 commented on Jun 11, 2026

    @liuhao1024

    This is fixed by #43629 — switches the kimi-coding provider's base URL to api.kimi.com/coding to match the correct API endpoint.

  3. AIalliAI commented on Jun 12, 2026

    @AIalliAI

    Triaged this against the v2026.6.5 release (the v0.16.0 you report running) and current main. The 401 you hit may well be real on your machine, but the proposed root cause doesn't match what ships in v0.16.0, and the suggested profile edit would regress other users.

    1. v0.16.0 already routes sk-kimi-* keys to api.kimi.com/coding. hermes_cli/auth.py at the v2026.6.5 tag has _resolve_kimi_base_url() (L518) with KIMI_CODE_BASE_URL = "https://api.kimi.com/coding" (L515): any key starting with sk-kimi- is auto-redirected to the coding endpoint unless KIMI_BASE_URL explicitly overrides. It's applied at both credential-resolution call sites and in agent/credential_pool.py. The interactive setup flow (_model_flow_kimi in hermes_cli/model_setup_flows.py) prints "Detected Kimi Coding Plan key → api.kimi.com/coding" and even clears stale KIMI_BASE_URL overrides. The api.moonshot.ai/v1 default in the provider profile is intentional — it's the endpoint for legacy platform.moonshot.ai keys, per the comment right above the registry entry (auth.py L253).

    2. The User-Agent is host-keyed, not profile-keyed. Requests to api.kimi.com get User-Agent: claude-code/0.1.0 regardless of profile defaults — run_agent.py (base_url_host_matches(base_url, "api.kimi.com") → sets the header), agent/anthropic_adapter.py, agent/agent_init.py, and the auxiliary client all do this in v2026.6.5. A correctly-routed request never reaches api.kimi.com carrying hermes-agent/1.0.

    3. The "Related" note inverts what the code does. _endpoint_speaks_anthropic_messages() returns True for api.kimi.com/coding — it forces Anthropic Messages transport there; its docstring says the /coding route "only speaks Claude-Code's native Anthropic shape". It does not "avoid forcing Anthropic wrapping" for that endpoint.

    4. Vision on kimi-coding doesn't 401 — it's deny-listed. kimi-coding/kimi-coding-cn are in _PROVIDERS_WITHOUT_VISION (agent/auxiliary_client.py), so auxiliary.vision: auto skips Kimi and falls through to the aggregator chain — that's the #17076 fix. Whether the /coding endpoint now accepts image input is exactly what the existing kimi-vision cluster is litigating (#6611 canonical; open PRs #18999/#23658 propose lifting the deny-list) — fresh capability evidence is most useful there.

    5. The proposed fix regresses other users. Hardcoding base_url="https://api.kimi.com/coding" in the profile (what #43629 does) breaks every legacy platform.moonshot.ai key — api.moonshot.ai/v1 is their only working endpoint — and pointing kimi-coding-cn at the global api.kimi.com defeats the CN variant (api.moonshot.cn) entirely. sk-kimi-* keys gain nothing, since they're already redirected.

    To pin down your actual 401 — both paste.rs debug links are 404 now; could you re-upload? Also useful:

    • hermes --version (pre-v2026.6.5 builds predate the auto-redirect),
    • whether KIMI_BASE_URL is set in your env/.env (an explicit override wins over auto-detection),
    • whether the key lives in a credential-pool entry with a pinned base_url from an older install,
    • hermes doctor output (it prints the resolved Kimi endpoint).

    If one of those shows the redirect being bypassed on a clean v0.16.0, that's a real bug worth fixing at the resolution layer — but not by repointing the profile defaults.

  4. kevin-lucifer commented on Jun 12, 2026

    @kevin-lucifer

    补充:vision 路由问题

    额外发现

    在排查 Kimi Code Plan 的 vision 支持时,我们发现除了 #43617 提到的端点问题,还有 vision 路由 需要修复:

    当前问题

    即使 #43617 修复了主模型的端点,auxiliary vision 仍然需要手动配置 workaround:

    期望行为

    当主 provider 是 且用户配置了 Code Plan API key,vision 应该自动使用正确的 OpenAI 兼容端点,无需手动配置 。

    根因分析

    1. 已移除 (感谢 fix: remove kimi-coding from _PROVIDERS_WITHOUT_VISION — vision now supported upstream #18990)
    2. 已修复 检测(最新代码)
    3. 但 credential pool 中的 仍然是 (Anthropic 格式)
    4. 需要类似 [Bug]: kimi-coding provider uses wrong endpoint + User-Agent for sk-kimi-* keys, breaking all API calls including vision #43617 的修复,为 vision 任务自动切换到

    建议修复

    在 的 或 中:

    或者更通用的方案:为 provider 添加 vision 专用的端点配置。

    相关

    cc @Teknium

  5. AIalliAI commented on Jun 12, 2026

    @AIalliAI

    @kevin-lucifer — a few claims in the supplement don't match the current state of main (checked just now at 46d758b):

    1. The deny-list removal has not happened. kimi-coding and kimi-coding-cn are both still in _PROVIDERS_WITHOUT_VISION (agent/auxiliary_client.py:342 on main). #18990 is an open issue requesting that removal, and #18999 / #23658 are the open PRs that would implement it — none of them has merged. So "已移除(感谢 #18990)" is premature; the removal is still pending capability evidence in the #6611 cluster.

    2. Because the deny-list is intact, there is no vision request to mis-route today. With auxiliary.vision: auto, kimi-coding is deliberately skipped and vision falls through to the aggregator chain (the #17076 fix). The "vision should auto-use the OpenAI-compatible endpoint" routing question only becomes live if/when the deny-list is lifted — which is exactly what #18999/#23658 (and the capability dispute in #6611/#26938) need to settle first. Fresh curl evidence that api.kimi.com/coding accepts image input would be most useful posted there.

    3. Several inline code spans in your comment rendered empty (the credential-pool value, the proposed fix location, the suggested config key), so the "credential pool 中的 … 仍然是 …(Anthropic 格式)" claim can't be evaluated as posted. Could you re-post with the literal paths and values? For reference: base-URL resolution for sk-kimi-* keys already pins https://api.kimi.com/coding via _resolve_kimi_base_url() (hermes_cli/auth.py) at both credential-resolution call sites and in agent/credential_pool.py, and the claude-code/0.1.0 User-Agent is host-keyed to api.kimi.com — see my comment above for the line-level cites.

    4. #45040 was closed in favor of consolidating the Kimi vision discussion into the existing cluster (#6611 canonical, with #18999/#23658/#24681/#26938) — that's the right home for the auto-detection design, rather than this endpoint-routing issue, whose root-cause claim doesn't hold on v0.16.0 (see above).

  6. kevin-lucifer commented on Jun 18, 2026

    @kevin-lucifer

    @AIalliAI 感谢之前的审阅。我们又做了端到端验证,现在 Kimi Code Plan 的视觉可以跑通了,问题根因和之前讨论的不完全一样。把证据和补丁贴一下:

    跑通的配置

    model:
      provider: kimi-coding
      base_url: https://api.kimi.com/coding
      model: kimi-for-coding
    
    auxiliary:
      vision:
        provider: kimi-coding
        model: kimi-for-coding
        base_url: https://api.kimi.com/coding/v1
        api_key: ''      # 留空,从 KIMI_API_KEY 环境变量读取

    .env 里只有一行 KIMI_API_KEY=sk-kimi-...。

    之前失败的原因

    不是端点选错,也不是 /coding/v1 不接受 vision,而是 auxiliary vision 没有拿到 API key。

    当 auxiliary.vision 同时配置了 provider: kimi-coding 和 base_url: https://api.kimi.com/coding/v1 但 api_key 留空时,Hermes 内部把它降级成 provider: custom,进入 custom 分支。custom 分支只检查 explicit_api_key 或 OPENAI_API_KEY,找不到就 fallback 成 no-key-required,导致请求带 Authorization: Bearer no-key-required,Kimi 返回 401:

    Error code: 401 - {'error': {'message': 'The API Key appears to be invalid or may have expired...'}}
    

    修复内容

    在 resolve_provider_client() 的 custom 分支里,当没有显式 key 时,从 endpoint hostname 反推 provider(api.kimi.com/coding/v1 → kimi-coding),然后走 resolve_api_key_provider_credentials() 从 KIMI_API_KEY 读取 key。这样既保留用户显式指定端点的灵活性,又不需要在 config.yaml 里重复写 key。

    另外把 kimi / moonshot / kimi-cn / moonshot-cn 这些 alias 也纳入 native vision 的 skip 列表,避免主模型端点 /coding 被误当作支持 vision。

    验证结果

    provider, client, model = resolve_vision_provider_client()
    # provider: 'kimi-coding'
    # client.base_url: 'https://api.kimi.com/coding/v1/'
    # client.default_headers['User-Agent']: 'claude-code/0.1.0'
    # api_key: 从 KIMI_API_KEY 正确解析
    
    resp = await async_call_llm(task='vision', messages=[...image...])
    # 返回完整图片描述,content 正常,无需 fallback 到 reasoning_content

    vision_analyze_tool('file:///tmp/small_test.jpg', ...) 也成功返回分析。

    PR

    补丁已提交到 #48509,改动文件只有 agent/auxiliary_client.py、agent/image_routing.py 和对应测试,没有包含任何明文 API key。

  7. teknium1 commented on Jul 14, 2026

    @teknium1
    Collaborator

    Thanks for the detailed report. This is already implemented on current main; automated hermes-sweeper review confirmed both the original routing/header fix and the later auxiliary-endpoint scenario.

    • hermes_cli/auth.py:523 routes sk-kimi-* keys to https://api.kimi.com/coding; the legacy Moonshot URL remains only for legacy keys.
    • run_agent.py:4441 and agent/auxiliary_client.py:4927 apply User-Agent: claude-code/0.1.0 for api.kimi.com.
    • The explicit auxiliary-provider path now preserves kimi-coding rather than flattening it to custom (agent/auxiliary_client.py:5969), so its normal KIMI_API_KEY resolution and Kimi transport handling remain active. This was added by a8841e2a6877f7b5e7b4b6ab0122ef2fde229fe2.
    • Existing regression coverage includes tests/agent/test_auxiliary_transport_autodetect.py:228 and tests/hermes_cli/test_api_key_providers.py:885.

    The original Kimi Code routing support is present in ancestor commit 4447e7d71afaa9840e02469c6296c7e2604b3ea5.

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

    P2Medium — degraded but workaround existscomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointprovider/kimiKimi / Moonshotsweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions