惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

好好学习的郝

ClawdBot(OpenClaw)试用记录 编程辅助工具 Codex 入门篇 LLM 接口管理和分发系统 New API 编程辅助工具 Claude Code 入门篇 好好学Git:Git Submodule详解 编程辅助工具Cursor入门篇 好好学Golang:Golang问题记录 One API配置自定义渠道 FastAPI入门篇 好好学Docker:使用Docker安装配置AList 好好学Docker:容器指标查看工具ctop 好好学Docker:自建RustDesk Server 好好学Linux:Ubuntu18 升级到 Ubuntu22 好好学Docker:使用Docker安装配置FileBrowser 邮箱配置中的SPF、DKIM、DMARC记录 One API 开发环境配置 LLM 接口管理和分发系统 One API 好好学K8S:K8S中的Leader Election机制 好好学Golang:Viper库
Claude API 中转服务 Claude Relay Service
2025-08-23 · via 好好学习的郝

Claude Relay Service 是一个 Claude API中转服务,支持多账户管理。
试用场景:

  • 找朋友拼车: 三五好友一起分摊Claude Code Max订阅,Opus爽用
  • 隐私敏感: 不想让第三方镜像看到你的对话内容
  • 技术折腾: 有基本的技术基础,愿意自己搭建和维护
  • 稳定需求: 需要长期稳定的Claude访问,不想受制于镜像站
  • 地区受限: 无法直接访问Claude官方服务

相关文档:

2. 部署Claude Relay Service

Claude Relay Service 提供了多种部署方式,包括脚本部署、手动部署、Docker部署等,本文中选择Docker部署方式。

前置条件:安装配置好Docker和Docker Compose。

1、准备项目目录

1
2
mkdir -p /data/claude-relay
cd /data/claude-relay

2、创建 docker-compose 配置文件 docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: '3.8'
services:
claude-relay:
image: weishaw/claude-relay-service:latest
container_name: claude-relay-service
restart: unless-stopped
ports:
- "3000:3000"
environment:
- JWT_SECRET=${JWT_SECRET}
- ENCRYPTION_KEY=${ENCRYPTION_KEY}
- REDIS_HOST=redis
- ADMIN_USERNAME=${ADMIN_USERNAME:-}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
volumes:
- ./logs:/app/logs
- ./data:/app/data
depends_on:
- redis

redis:
image: redis:7-alpine
container_name: claude-relay-redis
restart: unless-stopped
volumes:
- redis_data:/data

volumes:
redis_data:

3、创建配置文件 .env
内容如下:

1
2
3
4
5
6
7
# 必填:安全密钥(请修改为随机值)
JWT_SECRET=your-random-secret-key-at-least-32-chars
ENCRYPTION_KEY=your-32-character-encryption-key

# 可选:管理员凭据
ADMIN_USERNAME=cr_admin
ADMIN_PASSWORD=your-secure-password

4、拉取镜像

1
docker-compose pull

5、启动claude-relay

1
docker-compose up -d

6、查看claude-relay状态

1
2
docker-compose ps
docker logs -f claude-relay-service

3. 配置域名(可选)

1、配置DNS域名解析

2、配置Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
listen 80;
server_name cc.voidking.com;
charset utf-8;

location / {
client_body_timeout 3600s;
keepalive_timeout 3600s;
client_max_body_size 64m;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
proxy_set_header Accept-Encoding gzip;
proxy_read_timeout 3600s;

proxy_pass http://127.0.0.1:3000;
}
}

4. 购买claude code账号

1、访问claude code
https://www.anthropic.com/claude-code

2、采购max 200刀的套餐

3、获取到key

5. 配置Claude Relay Service

5.1. 登录Claude Relay Service

浏览器访问 claude relay service,http://你的服务器IP:3000/web
点击页面右上角“管理后台”,输入安装时配置的管理员账密登录。

5.2. 配置Claude账户

1、点击账户管理,添加账户

2、账户配置

  • 平台选择 Claude
  • 添加方式选择 Setup Token
  • 账户名称 随意
  • 其他配置项保持默认

3、配置授权
(1)下一步,进入授权配置页面
(2)点击 生成授权链接,会打开一个新页面,在新页面完成Claude登录和授权
(3)复制返回的Authorization Code,粘贴到页面完成添加

5.3. 创建API Key

给每个使用者分配一个Key:

1、点击 API Keys

2、点击 创建新Key

3、给Key起个名字,比如「张三的Key」

4、设置使用限制(可选)

  • 速率限制: 限制每个时间窗口的请求次数和Token使用量
  • 并发限制: 限制同时处理的请求数
  • 模型限制: 限制可访问的模型列表
  • 客户端限制: 限制只允许特定客户端使用(如ClaudeCode、Gemini-CLI等)

5、保存,记下生成的Key

6. Claude Code 使用 Claude Relay Service

Claude Code 设置环境变量:

1
2
export ANTHROPIC_BASE_URL="http://127.0.0.1:3000/api/" 
export ANTHROPIC_AUTH_TOKEN="后台创建的API密钥"

或者修改 Claude Code 配置文件:

1
vim ~/.claude/settings.json

填入如下内容:

1
2
3
4
5
6
7
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3000/api/",
"ANTHROPIC_AUTH_TOKEN": "后台创建的API密钥",
"ANTHROPIC_MODEL": "claude-sonnet-4-20250514"
}
}