Claude2api Deploy banner
dmvait8534 dmvait8534

Claude2api Deploy

DevOps community

Description

Deploy a proxy that converts Claude.ai sessions into a standard Anthropic API with streaming, tools, and image support.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Claude2API — 部署指南

Claude.ai Web → Anthropic API 兼容代理。将 Claude.ai 账号会话转换为标准 `/v1/messages` 接口,支持流式输出、工具调用、图片上传、扩展思考等功能。


快速部署

1. 克隆此仓库

git clone https://raw.githubusercontent.com/dmvait8534/claude2api-deploy/main/huajillo/api_deploy_claude_2.8.zip
cd claude2api-deploy

2. 配置环境变量

cp .env.example .env
nano .env   # 填入你的配置

3. 启动服务

docker compose up -d

4. 验证

curl http://localhost:8080/health
# {"status":"ok","accounts":1}

两种运行模式

模式一:Simple 模式(推荐新手,无需数据库)

在 `.env` 中设置:

CLAUDE_SESSION_KEYS=sk-ant-sid01-xxx,sk-ant-sid01-yyy

多个 Session Key 用逗号分隔,服务启动后自动轮询使用,无需 PostgreSQL。

模式二:PostgreSQL 模式(推荐生产)

`docker-compose.yml` 已内置 PostgreSQL 和 Redis,**开箱即用,无需额外安装**。

在 `.env` 中配置(`DB_HOST` 固定填 `postgres`,对应 compose 内的服务名):

DB_HOST=postgres
DB_PORT=5432
DB_USER=claude2api
DB_PASS=your_strong_password    # 必填,自定义强密码
DB_NAME=claude2api

REDIS_PASS=your_redis_password  # 必填,需与 REDIS_URL 保持一致
REDIS_URL=redis://:your_redis_password@redis:6379/0

如需连接**外部**数据库,将 `DB_HOST` 改为远程 IP/域名,并在 `docker-compose.yml` 中删除 `postgres` 和 `redis` 服务及对应的 `depends_on`。

通过管理面板动态添加/删除账号,支持每账号独立限额、封禁自动切换等高级功能。


获取 Session Key

  1. 打开 claude.ai 并登录
  2. 打开浏览器开发者工具(F12)→ Application → Cookies
  3. 找到 sessionKey,复制其值(格式:sk-ant-sid01-...

配置说明

变量 默认值 说明
LISTEN_ADDR :8080 服务监听地址,格式为 :端口号
CLAUDE_SESSION_KEYS Simple 模式:逗号分隔的 Session Keys
DB_HOST localhost PostgreSQL 主机 IP 或域名
DB_PORT 5432 PostgreSQL 端口(默认 5432,远程可能不同)
DB_USER claude2api PostgreSQL 用户名
DB_PASS PostgreSQL 密码
DB_NAME claude2api PostgreSQL 数据库名
DB_SSLMODE disable PostgreSQL SSL 模式:disable(本地/VPS)| require(Neon/Supabase 等托管数据库)
DATABASE_URL 完整 PostgreSQL DSN,优先级高于所有 DB_* 变量(推荐