模型API服务
Kimi K2 × Claude Code 接入指南

Kimi K2 × Claude Code 接入指南

由于 Claude Code 在使用时不兼容 OpenAI 格式的请求,所以需要一个代理应用做转发,这里以 claude-code-proxy (opens in a new tab) 举例。


环境准备

  • Ubuntu 24.04 操作系统

安装 ClaudeCode

# 确保已经安装了 npm
npm install -g @anthropic-ai/claude-code

安装 ClaudeCodeProxy

克隆项目到本地:

git clone https://github.com/fuergaosi233/claude-code-proxy
cd claude-code-proxy

安装依赖:

# 安装 uv(已经安装可以忽略):
curl -LsSf https://astral.sh/uv/install.sh | sh
 
# 安装依赖
uv sync

修改配置

cp .env.example .env
 
# 编辑配置文件
vim .env

需要修改的配置,以 moonshotai/Kimi-K2-Instruct 模型为例:

设置项描述
OPENAL_API_KEYAPI Key管理 (opens in a new tab)
ANTHROPIC_API_KEY需要注释掉这一行
OPENAL_BASE_URLhttps://api.modeliverse.cn/v1 (opens in a new tab)
BIG_MODELmoonshotai/Kimi-K2-instruct
MIDDLE_MODELmoonshotai/Kimi-K2-instruct
SMALL_MODELmoonshotai/Kimi-K2-instruct

启动代理

  1. 临时启动
uv run start_proxy.py

2. Docker 后台运行 ClaudeCodeProxy 提供了 Dockerfile,能够以容器的方式后台运行代理服务:

# 编译镜像(确保安装了docker)
docker build -t claude-code-proxy:latest .
 
# 启动
docker run -d --name claude-code-proxy -p 8082:8082 claude-code-proxy

运行 Claude

启动代理成功后,执行下面的命令:

# ANTHROPIC_BASE_URL 转发到本地代理,ANTHROPIC_AUTH_TOKEN 绕过登录认证
ANTHROPIC_BASE_URL=http://localhost:8082 ANTHROPIC_AUTH_TOKEN="any-value" claude

Copyright © 2025 沪ICP备12020087号-61