Claude Max API Proxy Setup
Overview
Replace per-token Claude API billing ($15-75/M tokens) with a flat-rate proxy through your Claude Max ($200/mo) or Pro ($20/mo) subscription. The claude-max-api-proxy package exposes your authenticated Claude Code CLI session as an OpenAI-compatible HTTP endpoint on localhost:3456.
How it works: The proxy uses your already-authenticated claude CLI session to forward requests. No API keys are stored or transmitted by the proxy — it relies on your local CLI login. Any OpenAI-compatible client (OpenClaw, LangChain, custom scripts) connects to localhost:3456.
Source code: github.com/atalovesyou/claude-max-api-proxy — review the source before installing.
When to Use
- - Agent API costs exceed $20/month and you have a Claude Max or Pro subscription
- You want to run Claude Opus 4.6, Sonnet 4.6, or Haiku 4.5 without per-token charges
- You're configuring OpenClaw, LangChain, or any OpenAI-compatible client to use Claude
Do not use when:
- - You don't have a Claude Max or Pro subscription (get one first at claude.ai)
- You need concurrent request throughput >5 (Max plan has rate limits)
- You're on a shared server where others could access port 3456
Security Notes
- - The proxy binds to localhost only by default — it is not accessible from other machines
- It uses your authenticated
claude CLI session, meaning anyone with access to port 3456 on your machine can make requests against your subscription - Never expose port 3456 to the public internet — use firewall rules to restrict access
- Review the package source before installing
Setup Process
1. Prerequisites Check
CODEBLOCK0
If claude is not authenticated, run claude login and complete the browser flow.
2. Install and Start
CODEBLOCK1
3. Configure Your Client
For OpenClaw (~/.openclaw/openclaw.json):
CODEBLOCK2
For any OpenAI-compatible client:
- - Base URL: INLINECODE8
- API key: any non-empty string (proxy ignores it)
- Model IDs:
claude-opus-4, claude-sonnet-4, INLINECODE11
4. Run as Persistent Service (Optional)
CODEBLOCK3
5. Verify
CODEBLOCK4
Model ID Reference
| Proxy Model ID | CLI Alias | Best For |
|---|
| INLINECODE12 | opus | Complex reasoning, research, long-form |
| INLINECODE13 |
sonnet | Fast + capable, most tasks |
|
claude-haiku-4 | haiku | Simple tasks, high speed |
Common Mistakes
| Mistake | Fix |
|---|
| INLINECODE15 | INLINECODE16 |
| Proxy returns auth errors |
Run
claude login and complete browser auth |
| Rate limit errors with Max plan | Add
"maxConcurrency": 1 to agent config; Max has limits |
| Config not taking effect | Restart your agent/client after changing config |
| Proxy dies on reboot | Set up systemd service (Step 4 above) |
Cost Comparison
| Setup | Monthly Cost |
|---|
| Claude Opus 4.6 API (active agent) | $200-500+ |
| Claude Max + this proxy |
$200 flat |
| Claude Pro + this proxy | $20 flat (lower rate limits) |
Need Help?
Claude Max API 代理设置
概述
通过您的Claude Max(200美元/月)或Pro(20美元/月)订阅,将按token计费的Claude API(15-75美元/百万token)替换为固定费率的代理。claude-max-api-proxy包将您已认证的Claude Code CLI会话暴露为localhost:3456上兼容OpenAI的HTTP端点。
工作原理: 该代理使用您已认证的claude CLI会话转发请求。代理不会存储或传输任何API密钥——它依赖于您本地的CLI登录。任何兼容OpenAI的客户端(OpenClaw、LangChain、自定义脚本)均可连接到localhost:3456。
源代码: github.com/atalovesyou/claude-max-api-proxy——安装前请审查源代码。
使用场景
- - Agent API费用超过20美元/月,且您拥有Claude Max或Pro订阅
- 您希望运行Claude Opus 4.6、Sonnet 4.6或Haiku 4.5而无需按token付费
- 您正在配置OpenClaw、LangChain或任何兼容OpenAI的客户端以使用Claude
请勿在以下情况使用:
- - 您没有Claude Max或Pro订阅(请先在claude.ai获取)
- 您需要超过5的并发请求吞吐量(Max计划有速率限制)
- 您处于共享服务器上,其他人可能访问端口3456
安全说明
- - 代理默认仅绑定到localhost——其他机器无法访问
- 它使用您已认证的claude CLI会话,这意味着任何能访问您机器上端口3456的人都可以通过您的订阅发起请求
- 切勿将端口3456暴露到公共互联网——使用防火墙规则限制访问
- 安装前请审查包源代码
设置流程
1. 前置条件检查
bash
验证Node.js 20+
node --version
验证Claude Code CLI已安装并认证
claude --version
claude --print test # 应返回响应且无错误
如果claude未认证,请运行claude login并完成浏览器流程。
2. 安装并启动
bash
首先审查包源代码:https://github.com/atalovesyou/claude-max-api-proxy
npm install -g claude-max-api-proxy
claude-max-api # 默认在localhost:3456启动
验证:
curl http://localhost:3456/health
=> {status:ok,provider:claude-code-cli,...}
3. 配置您的客户端
对于OpenClaw(~/.openclaw/openclaw.json):
json
{
env: {
OPENAIAPIKEY: not-needed,
OPENAIBASEURL: http://localhost:3456/v1
},
models: {
providers: {
openai: {
baseUrl: http://localhost:3456/v1,
apiKey: not-needed,
models: [
{ id: claude-opus-4, name: Claude Opus 4.6 (Max), contextWindow: 200000, maxTokens: 16384 },
{ id: claude-sonnet-4, name: Claude Sonnet 4.6 (Max), contextWindow: 200000, maxTokens: 16384 },
{ id: claude-haiku-4, name: Claude Haiku 4.5 (Max), contextWindow: 200000, maxTokens: 8192 }
]
}
}
}
}
对于任何兼容OpenAI的客户端:
- - 基础URL:http://localhost:3456/v1
- API密钥:任何非空字符串(代理会忽略)
- 模型ID:claude-opus-4、claude-sonnet-4、claude-haiku-4
4. 作为持久化服务运行(可选)
bash
创建systemd用户服务
根据您的系统调整以下路径——使用以下命令查找:
which claude-max-api
echo $HOME
mkdir -p ~/.config/systemd/user
cat > ~/.config/systemd/user/claude-max-api-proxy.service << EOF
[Unit]
Description=Claude Max API代理
After=network.target
[Service]
Type=simple
ExecStart=$(which claude-max-api)
Environment=HOME=$HOME
Environment=PATH=$HOME/.npm-global/bin:/usr/local/bin:/usr/bin:/bin
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable claude-max-api-proxy
systemctl --user start claude-max-api-proxy
5. 验证
bash
curl http://localhost:3456/v1/chat/completions \
-H Content-Type: application/json \
-d {model:claude-opus-4,messages:[{role:user,content:Say: proxy working}]}
模型ID参考
| 代理模型ID | CLI别名 | 最佳用途 |
|---|
| claude-opus-4 | opus | 复杂推理、研究、长文本 |
| claude-sonnet-4 |
sonnet | 快速+强大,大多数任务 |
| claude-haiku-4 | haiku | 简单任务,高速 |
常见错误
| 错误 | 解决方法 |
|---|
| claude: command not found | npm install -g @anthropic-ai/claude-code |
| 代理返回认证错误 |
运行claude login并完成浏览器认证 |
| Max计划出现速率限制错误 | 在agent配置中添加maxConcurrency: 1;Max有速率限制 |
| 配置未生效 | 更改配置后重启您的agent/客户端 |
| 重启后代理失效 | 设置systemd服务(上述第4步) |
成本对比
| 设置方案 | 月成本 |
|---|
| Claude Opus 4.6 API(活跃agent) | 200-500+美元 |
| Claude Max + 此代理 |
200美元固定 |
| Claude Pro + 此代理 | 20美元固定(速率限制较低) |
需要帮助?