A Node.js proxy server that distributes Claude API requests across multiple endpoints using round-robin load balancing.
- Load Balancing: Automatically distributes requests across multiple Claude API endpoints
- Round-Robin Strategy: Ensures even distribution of requests
- Health Monitoring: Built-in health check endpoint
- Error Handling: Comprehensive error handling with appropriate HTTP status codes
- Request Logging: Logs all incoming requests and routing decisions
- CORS Support: Enables cross-origin requests for web applications
- Node.js (v14 or higher)
- npm or yarn
- Access to Claude API endpoints
- Clone the repository:
git clone https://github.com/geminiwen/claude-loadbalancer.git
cd claude-loadbalancer- Install dependencies:
npm install- Configure endpoints:
cp config/endpoints.example.js config/endpoints.js- Edit
config/endpoints.jswith your actual Claude API endpoints:
module.exports = [
{
baseURL: 'https://your-claude-endpoint-1.com/api/',
authToken: 'your_auth_token_here_1'
},
{
baseURL: 'https://your-claude-endpoint-2.com/api/',
authToken: 'your_auth_token_here_2'
}
// Add more endpoints as needed
];- Start the server:
npm startFor development with auto-reload:
npm run devSend Claude API requests to:
POST http://localhost:13255/v1/messages
The server will automatically route requests to available endpoints using round-robin distribution.
Check server status and endpoint configuration:
GET http://localhost:13255/health
Response example:
{
"status": "healthy",
"timestamp": "2024-01-01T00:00:00.000Z",
"endpoints": [
{
"index": 1,
"baseURL": "https://endpoint1.com/api/",
"hasToken": true
},
{
"index": 2,
"baseURL": "https://endpoint2.com/api/",
"hasToken": true
}
],
"currentEndpoint": 1
}PORT: Server port (default: 13255)
Each endpoint in config/endpoints.js must have:
baseURL: Claude API base URL (the server will appendv1/messagesto this URL)authToken: Authentication token for the endpoint
The load balancer handles various error scenarios:
- API Errors: Forwards the original error response from Claude API
- Timeout Errors: Returns 408 status with timeout error message
- Internal Errors: Returns 500 status for unexpected errors
MIT License - see LICENSE file for details.
Gemini Wen