Claude Code 接入 Kimi-K2 模型

Claude Code 接入 Kimi-K2 模型

周四的文章 Claude Code 接入 Qwen3-Coder-Plus 之后…… 中,曾老师花了 31.3 元巨款测试了 Qwen3-Coder-Plus 模型,效果挺好的。

今天周末水一篇短文,说说 Claude-Code 如何使用 kimi-k2 模型。

退出登录,解决 ERR_BAD_REQUEST 问题

如果需要退出 Claude Code 登录,或者在退出登录后碰到了 ERR_BAD_REQUEST 问题,可以看周四的文章 Claude Code 接入 Qwen3-Coder-Plus 之后…… 参照解决。

8e82686f10814c8000e2d3212c405af9.png

Claude Code 接入月之暗面API

设置环境变量:

1export ANTHROPIC_BASE_URL="https://api.moonshot.cn/anthropic/"
2export ANTHROPIC_API_KEY="sk-***"
3export ANTHROPIC_MODEL=kimi-k2-0711-preview

启动 Claude Code 后确认使用新的 Api Key 就可以开始干活儿了:

e93dbf1946ef9c2f9e56cdcf155bdb58.png

对于模型的设置,也可以进入 Claude Code 之后使用 /model 命令来设置。

cd751e7a97eec61bee8ae328619335ec.png

花了多少 token(money)?

使用 /cost 命令可以看到当前的花费,kimi-k2 在 fabik 项目中,修了十几个 bug,并完成了所有单元测试。token 消耗大约是周四 Qwen3-Coder 消耗的 9 倍。

项目源码地址: https://github.com/zrong/fabik

Claude Code 按照标准给出的费用预估: 122.39 美元,4300万 token。

/cost ⎿ Total cost: $122.39 (costs may be inaccurate due to usage of unknown models) Total duration (API): 58m 59.2s Total duration (wall): 18h 18m 1.6s Total code changes: 1105 lines added, 261 lines removed Usage by model: claude-3-5-haiku: 293.5k input, 3.6k output, 0 cache read, 0 cache write kimi-k2-0711-preview: 40.3m input, 88.3k output, 0 cache read, 0 cache write

但实际上,月之暗面开发者后台显示的是 人民币 14.02元。

092e4a470d44fa839c778456a0ab3e48.png

如果说周四测试 Qwen3-Coder-Plus 的时候,还是 人民币对美刀油电同价 的感受,今天 Kimi -k2 就是 人民币对哈萨克斯坦坚戈 了。

2025年7月25日,1人民币 = 64.403834哈萨克斯坦坚戈。

接下来试试腾讯 Codebuddy,免费用 Claude-4-Sonnect。