Skip to content

fix(proxy): bypass Kimi Coding Plan User-Agent whitelist for non-whitelisted agents#3671

Open
pgao-cn wants to merge 1 commit into
farion1231:mainfrom
pgao-cn:main
Open

fix(proxy): bypass Kimi Coding Plan User-Agent whitelist for non-whitelisted agents#3671
pgao-cn wants to merge 1 commit into
farion1231:mainfrom
pgao-cn:main

Conversation

@pgao-cn

@pgao-cn pgao-cn commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Fixes #3559
Related to #2890

Kimi Coding Plan (api.kimi.com/coding/v1) enforces a strict User-Agent whitelist. Non-whitelisted agents (Codex, OpenCode, Gemini, Hermes, OpenClaw) receive HTTP 403:

"Kimi For Coding is currently only available for Coding Agents such as Kimi CLI, Claude Code, Roo Code, Kilo Code, etc."

This PR automatically injects a whitelisted User-Agent (claude-cli/{version}) for all requests to Kimi endpoints when the original agent is not on the whitelist.

Changes

  • Added get_agent_version() in forwarder.rs to dynamically detect the local Claude Code version
  • Injected claude-cli/{version} User-Agent for Kimi Coding Plan (api.kimi.com) and Kimi Open Platform (api.moonshot.cn) endpoints
  • Applied injection to: Codex, OpenCode, Gemini, Hermes, OpenClaw
  • Preserved original claude-cli/{version} for Claude Code (already whitelisted)

Verification

Verified via curl against https://api.kimi.com/coding/v1/chat/completions:

User-Agent Result
claude-cli/2.1.161 ✅ HTTP 200
claude-code/0.1.0 ✅ HTTP 200
codex-cli/0.136.0 ❌ HTTP 403
kimi-cli/1.0 ❌ HTTP 403

Integration tested:

  • Codex CLI → Kimi Coding Plan: now works (was 403)
  • Claude Code → Kimi Coding Plan: still works (already whitelisted)

Checklist

  • cargo fmt passes
  • cargo clippy passes
  • Updated i18n files (N/A - no user-facing text changed)

…elisted agents

Kimi Coding Plan (api.kimi.com/coding/v1) enforces a strict User-Agent
whitelist. Verified via curl testing:

- ✅ whitelisted: claude-cli/*, claude-code/*, Kilo-Code/*
- ❌ rejected: codex-cli/*, kimi-cli/*, openclaw/*

This fix injects a whitelisted User-Agent (claude-cli/{version}) for
all requests to Kimi endpoints when the original agent (Codex, OpenCode,
Gemini, Hermes, OpenClaw) is not on the whitelist.

Claude Code retains its original claude-cli/{version} UA since it is
already whitelisted.

Fixes 403 Forbidden: 'Kimi For Coding is currently only available for
Coding Agents such as Kimi CLI, Claude Code, Roo Code, Kilo Code, etc.'
@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@youngxhui

Copy link
Copy Markdown

期待合入 支持 kimi code plan

@Ardssass

Ardssass commented Jun 5, 2026

Copy link
Copy Markdown

Would it also be possible to add a feature to Claude Code that allows modifying the User-Agent? The reason I ask is that some relay services only accept Codex's User-Agent when running GPT models, and only accept Claude CLI's User-Agent when using Claude models. This means that every time I switch models, I have to switch to a different CLI as well, and I lose all my conversation history in the process. It would be really helpful if Claude Code could support custom User-Agents.

@pgao-cn

pgao-cn commented Jun 7, 2026

Copy link
Copy Markdown
Author

Hi @farion1231, this PR has passed all CI checks and Codex review without any major issues. Could you please take a look when you have a moment? Thanks! 🙏

@kavalla-ws

Copy link
Copy Markdown

Hope to speed up the progress

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常感谢您的贡献,我和 Kimi 的开发人员交流过后,讨论的结果是用这种伪装请求头的方式来使用 Coding Plan 的话,可能会对他们的风控政策造成干扰,所以我觉得还是等待官方对 Codex 放行比较好,您觉得呢?

@kavalla-ws

Copy link
Copy Markdown

非常感谢您的贡献,我和 Kimi 的开发人员交流过后,讨论的结果是用这种伪装请求头的方式来使用 Coding Plan 的话,可能会对他们的风控政策造成干扰,所以我觉得还是等待官方对 Codex 放行比较好,您觉得呢?

等不及了

@realweng

realweng commented Jun 9, 2026

Copy link
Copy Markdown

非常感谢您的贡献,我和 Kimi 的开发人员交流过后,讨论的结果是用这种伪装请求头的方式来使用 Coding Plan 的话,可能会对他们的风控政策造成干扰,所以我觉得还是等待官方对 Codex 放行比较好,您觉得呢?

期待合并,不理解 kimi 的风控逻辑,为了防中转站使用 kimi for coding 就只从 UA 识别一刀切了其他 Agent 使用的可能吗,就没有更好的方式了吗,而且这种伪造 UA 的方式是 work 的

@Ardssass

Copy link
Copy Markdown

我使用某些api中转站时也有自定义请求头的需求, 不应该只因为 kimi 的风控政策影响其它中转站的使用
还是希望能添加自定义请求头的功能, 谢谢

farion1231 added a commit that referenced this pull request Jun 11, 2026
…ettings

Polish the provider-level User-Agent override UI on the Claude and Codex forms.

- Add a shared CustomUserAgentField (label + input + preset dropdown + live
  validation) so both forms stay in sync.
- Provide curated UA presets (Claude Code / Kilo Code families that pass
  coding-plan UA whitelists per #3671); the first is Claude Code's real
  `claude-cli/x (external, cli)` format. Whitelists gate on the name prefix,
  not the version, so static values stay valid across upgrades.
- Expose presets via a dropdown to the right of the input (z-[200] so it
  renders above the dialog layers) instead of inline chips.
- Move the field into the existing advanced/reasoning collapsibles.
- userAgent.ts mirrors the backend byte rule (reject only control chars;
  non-ASCII is allowed) for a non-blocking inline hint.
- i18n for all four locales (zh/en/ja/zh-TW).
@youngxhui

Copy link
Copy Markdown

新版本已经支持了自定义请求头了 Kimi 可以接入了

@Wcdaren

Wcdaren commented Jun 16, 2026

Copy link
Copy Markdown

新版本已经支持了自定义请求头了 Kimi 可以接入了

我使用内置的那个选项还是会报错 unexpected status 404 Not Found: The requested resource was not found, url: https://api.kimi.com/coding/v1/responses 你们会这样吗

@farion1231

farion1231 commented Jun 16, 2026 via email

Copy link
Copy Markdown
Owner

@Wcdaren

Wcdaren commented Jun 16, 2026

Copy link
Copy Markdown

已经是开启的了 ,
我刚刚删除了原本的codex 然后使用brew 重新安装一遍codex就好了... 有点神奇
感觉可能和codex的版本有关 我之前的版本是 0.133.0

@Wcdaren

Wcdaren commented Jun 16, 2026

Copy link
Copy Markdown

这个报错应该是没有开启路由接管吧?直接请求了 kimi 的 response 接口,这个接口是不存在的 Rick Gao @.> 于2026年6月16日周二 16:37写道:

Wcdaren left a comment (farion1231/cc-switch#3671) <#3671 (comment)> 新版本已经支持了自定义请求头了 Kimi 可以接入了 我使用内置的那个选项还是会报错 unexpected status 404 Not Found: The requested resource was not found, url: https://api.kimi.com/coding/v1/responses 你们会这样吗 — Reply to this email directly, view it on GitHub <#3671?email_source=notifications&email_token=AKW3RFGOQHRONSSTF7QZDJD5AEBODA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZRGY2TMNBUGUY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4716564451>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKW3RFBK4GFZZJA7FW4JCED5AEBODAVCNFSNUABGKJSXA33TNF2G64TZHMYTAMZRHEYTENZSGQ5US43TOVSTWNBVHAZDSNRTGUYDHILWAI . You are receiving this because you were mentioned.Message ID: @.
>

感谢大大 哈哈哈 终于可以使用我的kimi了

gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
…ettings

Polish the provider-level User-Agent override UI on the Claude and Codex forms.

- Add a shared CustomUserAgentField (label + input + preset dropdown + live
  validation) so both forms stay in sync.
- Provide curated UA presets (Claude Code / Kilo Code families that pass
  coding-plan UA whitelists per farion1231#3671); the first is Claude Code's real
  `claude-cli/x (external, cli)` format. Whitelists gate on the name prefix,
  not the version, so static values stay valid across upgrades.
- Expose presets via a dropdown to the right of the input (z-[200] so it
  renders above the dialog layers) instead of inline chips.
- Move the field into the existing advanced/reasoning collapsibles.
- userAgent.ts mirrors the backend byte rule (reject only control chars;
  non-ASCII is allowed) for a non-blocking inline hint.
- i18n for all four locales (zh/en/ja/zh-TW).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex 不能支持kimi-for-coding模型

7 participants