中国站
帮助中心 > 人工智能 > 大模型服务 > 第三方工具调用 > Claude code

Claude code

Claude code

一、 Claude Code + MaaS

仅支持claude系列模型

Claude code

  1. #拉取镜像 Node.js 18 或更高版本
  2. npm install -g @anthropic-ai/claude-code
  3. #环境变量
  4. export ANTHROPIC_AUTH_TOKEN="{YOUR_API_KEY}"
  5. export ANTHROPIC_BASE_URL="https://api.yisu.com/{YOUR_ENDPOINT}"
  6. export ANTHROPIC_MODEL="MaaS_Cl_sonnet_4.5_20250929"
  7. #启动claude code
  8. claude #任意目录执行claude

二、 Claude Code + LiteLLM + MaaS

支持MaaS平台接入openAi格式的模型

1. postgres数据库
  1. docker pull postgres
  2. docker run --name my-postgres -e POSTGRES_PASSWORD=123456 -p 5432:5432 -d postgres
  3. docker exec -it my-postgres bash
  4. psql -U postgres
  5. CREATE DATABASE mydatabase;
2. LiteLLM
2.1 配置config.yaml,放入自定义文件夹中(第2步需用到该地址)
  1. model_list:
  2. - model_name: claude-3-7-sonnet-20250219 # 模型名称 调用llm接口需要传入的参数
  3. litellm_params:
  4. model: claude-3-7-sonnet-20250219 # 实际调用的模型名称
  5. api_base: https://api.yisu.com/{endpoint}/v1/messages
  6. api_key: xxx # 自动转为 x-api-key: Bearer xxx
  7. - model_name: gemini-2.5-flash
  8. litellm_params:
  9. model: gpt-3.5-turbo
  10. api_base: https://api.yisu.com/v1/ai/{endpoint}
  11. api_key: xxx
  12. headers:
  13. Authorization: Bearer xxx # api_base接口的认证方式
  14. general_settings:
  15. master_key: sk-1234
  16. database_url: postgresql://postgres:123456@{db_url}:5432/my_database #第一步配置的数据库
2.2 启动
  1. docker pull ghcr.io/berriai/litellm:main-latest
  2. docker run \
  3. -v $(pwd)/config.yaml:/app/config.yaml \
  4. -p 4000:4000 \
  5. ghcr.io/berriai/litellm:main-latest \
  6. --config /app/config.yaml --detailed_debug
2.3 模型调用
  1. # 查看config.yaml中配置了哪些模型
  2. curl http://127.0.0.1:4000/v1/models
  3. #给模型gemini-2.5-flash生成认证key
  4. curl 'http://0.0.0.0:4000/key/generate' \
  5. --header 'Authorization: Bearer sk-1234' \
  6. --header 'Content-Type: application/json' \
  7. --data-raw '{"models": ["gemini-2.5-flash"], "metadata": {"user": "ishaan@berri.ai"}}'
  8. #得到 {"key": "sk-wnm6JQ-f1U2Sixpa8L-0xg"}
  9. #调用模型接口
  10. curl --location --request POST 'http://127.0.0.1:4000/chat/completions' \
  11. --header 'Authorization: Bearer sk-wnm6JQ-f1U2Sixpa8L-0xg' \
  12. --header 'Content-Type: application/json' \
  13. --data-raw '{
  14. "model": "gemini-2.5-flash",
  15. "max_tokens": 2000,
  16. "stream": false,
  17. "messages": [
  18. {
  19. "role": "user",
  20. "content": "What is the weather like in San Francisco?"
  21. }
  22. ]
  23. }'
3. Claude code
3.1 claude code使用
  1. #拉取镜像 Node.js 18 或更高版本
  2. npm install -g @anthropic-ai/claude-code
  3. #环境变量
  4. export ANTHROPIC_BASE_URL=http://127.0.0.1:4000 #litellm的ip和端口
  5. export ANTHROPIC_MODEL=gemini-2.5-flash #调用哪个模型
  6. export ANTHROPIC_AUTH_TOKEN=sk-1234 #认证key
  7. #启动claude code
  8. claude #任意目录执行claude
3.2 claude code ui
  1. http://{claude code ip}:{claude code port}/ui/
  2. 用户名:admin
  3. 密码:sk-1234