🔐 Self-hosted Claude API relay service with multi-account management
Open source is not easy, your Star is my motivation to continue updating 🚀
Join Telegram Channel for the latest updates
Please read carefully before using this project:
🚨 Terms of Service Risk: Using this project may violate Anthropic's terms of service. Please carefully read Anthropic's user agreement before use. All risks from using this project are borne by the user.
📖 Disclaimer: This project is for technical learning and research purposes only. The author is not responsible for any account bans, service interruptions, or other losses caused by using this project.
If you have any of these concerns, this project might be suitable for you.
✅ Cost Sharing with Friends: 3-5 friends sharing Claude Code Max subscription, enjoying Opus freely
✅ Privacy Sensitive: Don't want third-party mirrors to see your conversation content
✅ Technical Tinkering: Have basic technical skills, willing to build and maintain yourself
✅ Stability Needs: Need long-term stable Claude access, don't want to be restricted by mirror sites
✅ Regional Restrictions: Cannot directly access Claude official service
❌ Complete Beginner: Don't understand technology at all, don't even know how to buy a server
❌ Occasional Use: Use it only a few times a month, not worth the hassle
❌ Registration Issues: Cannot register Claude account yourself
❌ Payment Issues: No payment method to subscribe to Claude Code
If you're just an ordinary user with low privacy requirements, just want to casually play around and quickly experience Claude, then choosing a mirror site you're familiar with would be more suitable.
📸 Click to view interface preview - See detailed screenshots of the Web management interface
Ubuntu/Debian users:
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install Redis
sudo apt update
sudo apt install redis-server
sudo systemctl start redis-server
CentOS/RHEL users:
# Install Node.js
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs
# Install Redis
sudo yum install redis
sudo systemctl start redis
# Download project
git clone https://github.com/Wei-Shaw/claude-relay-service.git
cd claude-relay-service
# Install dependencies
npm install
# Copy configuration files (Important!)
cp config/config.example.js config/config.js
cp .env.example .env
Edit .env file:
# Generate these two keys randomly, but remember them
JWT_SECRET=your-super-secret-key
ENCRYPTION_KEY=32-character-encryption-key-write-randomly
# Redis configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
Edit config/config.js file:
module.exports = {
server: {
port: 3000, // Service port, can be changed
host: '0.0.0.0' // Don't change
},
redis: {
host: '127.0.0.1', // Redis address
port: 6379 // Redis port
},
// Keep other configurations as default
}
# Initialize
npm run setup # Will randomly generate admin account password info, stored in data/init.json
# Start service
npm run service:start:daemon # Run in background (recommended)
# Check status
npm run service:status
Browser visit: http://your-server-IP:3000/web
Default admin account: Look in data/init.json
This step is quite important, requires OAuth authorization:
Note: If you're in China, this step may require VPN.
Assign a key to each user:
Now you can replace the official API with your own service:
Set environment variables:
export ANTHROPIC_BASE_URL="http://127.0.0.1:3000/api/" # Fill in your server's IP address or domain according to actual situation
export ANTHROPIC_AUTH_TOKEN="API key created in the backend"
Use claude:
claude
# Check service status
npm run service:status
# View logs
npm run service:logs
# Restart service
npm run service:restart:daemon
# Stop service
npm run service:stop
http://your-domain:3000/web - View usage statisticshttp://your-domain:3000/health - Confirm service is normallogs/ directoryWhen a new version is released, follow these steps to upgrade the service:
# 1. Navigate to project directory
cd claude-relay-service
# 2. Pull latest code
git pull origin main
# If you encounter package-lock.json conflicts, use the remote version
git checkout --theirs package-lock.json
git add package-lock.json
# 3. Install new dependencies (if any)
npm install
# 4. Restart service
npm run service:restart:daemon
# 5. Check service status
npm run service:status
Important Notes:
Can't connect to Redis?
# Check if Redis is running
redis-cli ping
# Should return PONG
OAuth authorization failed?
API request failed?
Strongly recommend using Caddy reverse proxy (Automatic HTTPS)
Recommend using Caddy as reverse proxy, it will automatically apply and renew SSL certificates with simpler configuration:
1. Install Caddy
# Ubuntu/Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
# CentOS/RHEL/Fedora
sudo yum install yum-plugin-copr
sudo yum copr enable @caddy/caddy
sudo yum install caddy
2. Caddy Configuration (Super Simple!)
Edit /etc/caddy/Caddyfile:
your-domain.com {
# Reverse proxy to local service
reverse_proxy 127.0.0.1:3000 {
# Support streaming responses (SSE)
flush_interval -1
# Pass real IP
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
# Timeout settings (suitable for long connections)
transport http {
read_timeout 300s
write_timeout 300s
dial_timeout 30s
}
}
# Security headers
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
-Server
}
}
3. Start Caddy
# Test configuration
sudo caddy validate --config /etc/caddy/Caddyfile
# Start service
sudo systemctl start caddy
sudo systemctl enable caddy
# Check status
sudo systemctl status caddy
4. Update service configuration
Modify your service configuration to listen only locally:
// config/config.js
module.exports = {
server: {
port: 3000,
host: '127.0.0.1' // Listen only locally, proxy through nginx
}
// ... other configurations
}
Caddy Advantages:
logs/ directoryThis project uses the MIT License.
⭐ If you find it useful, please give it a Star, this is the greatest encouragement to the author!
🤝 Feel free to submit Issues for problems, welcome PRs for improvement suggestions