Integrate Claude Router v1.1.0 as a new service in the main docker-compose stack: Features: - Smart API router with automatic failover between Claude Pro and Claude API - Scheduled health checks every hour (0-4 minutes) to detect quota recovery - Intelligent auto-switch back to Claude Pro when available - Manual health check endpoint for immediate testing - Complete documentation and Docker containerization - Compatible with Claude Code CLI Changes: - Add router/ subdirectory with complete Claude Router project - Integrate claude-router service into main docker-compose.yml - Resolve port conflict (move SillyTavern to 8002, Claude Router uses 8000) - Update .gitignore for router-specific exclusions The router automatically detects when Claude Pro quota is restored and switches back to prioritize the premium service. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import os
|
|
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
class Config(BaseModel):
|
|
# Claude API configurations
|
|
claude_pro_api_key: str = ""
|
|
claude_api_key: str = ""
|
|
|
|
# Router settings
|
|
port: int = 8000
|
|
host: str = "0.0.0.0"
|
|
|
|
# Retry settings
|
|
max_retries: int = 3
|
|
retry_delay: float = 1.0
|
|
|
|
# API endpoints
|
|
claude_pro_base_url: str = "https://api.anthropic.com"
|
|
claude_api_base_url: str = "https://api.anthropic.com"
|
|
|
|
# Health check settings
|
|
health_check_enabled: bool = True
|
|
health_check_cron: str = "0-4 * * * *" # Every hour, first 5 minutes
|
|
health_check_message: str = "ping"
|
|
health_check_model: str = "claude-3-haiku-20240307" # Use cheapest model for checks
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
# Load from environment or token file
|
|
self.load_from_env()
|
|
|
|
def load_from_env(self):
|
|
"""Load configuration from environment variables or token file"""
|
|
# Try environment variables first
|
|
self.claude_api_key = os.getenv("CLAUDE_API_KEY", "")
|
|
|
|
# Load from tokens.txt if not found in env
|
|
if not self.claude_api_key:
|
|
try:
|
|
with open("/home/will/docker/tokens.txt", "r") as f:
|
|
for line in f:
|
|
if line.startswith("claude_API="):
|
|
self.claude_api_key = line.split("=", 1)[1].strip()
|
|
break
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
# For MVP, we'll use the same API key for both pro and regular
|
|
# In practice, Claude Pro might use a different endpoint or key
|
|
self.claude_pro_api_key = self.claude_api_key
|
|
|
|
# Global config instance
|
|
config = Config() |