Universal API proxy for using Claude Code with multiple AI providers. Seamlessly translates between Anthropic's Claude API and OpenAI-compatible APIs.
- π API Translation: Anthropic β OpenAI format conversion
- π Multi-Provider: OpenRouter, OpenAI, DeepSeek, Kimi, SiliconFlow
- β‘ Edge Computing: Cloudflare Workers for global performance
- π‘ Streaming Support: Real-time response streaming
- π‘οΈ Type Safety: Full TypeScript implementation
npm install -g @anthropic-ai/claude-code
# Option A: Use shared instance (testing only)
export ANTHROPIC_BASE_URL="https://cc.xiaohui.cool"
export ANTHROPIC_API_KEY="your-provider-api-key"
# Option B: Deploy your own instance (recommended)
git clone https://github.com/your-username/claude-code-router
cd claude-code-router && wrangler deploy
export ANTHROPIC_BASE_URL="https://your-domain.workers.dev"
source ~/.bashrc && claude
Provider | API Key Source | Base URL |
---|---|---|
OpenRouter | openrouter.ai | https://cc.xiaohui.cool |
DeepSeek | platform.deepseek.com | Deploy with DEEPSEEK_BASE_URL |
OpenAI | platform.openai.com | Deploy with OPENAI_BASE_URL |
graph TB
A[Claude Code Client] -->|Anthropic API Format| B[Claude-Code-Router]
B -->|Provider Selection| C{Environment Config}
C -->|OpenRouter| D[OpenRouter API]
C -->|DeepSeek| E[DeepSeek API]
C -->|OpenAI| F[OpenAI API]
C -->|Others| G[Other OpenAI-Compatible APIs]
B -->|Format Conversion| H[Request Translator]
B -->|Response Processing| I[Response Translator]
B -->|Streaming| J[SSE Handler]
subgraph "Cloudflare Workers"
B
H
I
J
end
style A fill:#e1f5fe
style B fill:#fff3e0
style D fill:#f3e5f5
style E fill:#e8f5e8
style F fill:#fff8e1
style G fill:#fce4ec
- Platform: Cloudflare Workers (V8 Isolates)
- Language: TypeScript with strict typing
- Runtime: Edge-optimized JavaScript (no Node.js dependencies)
- Deployment: Wrangler CLI + GitHub Actions
Pattern | Implementation | Benefit |
---|---|---|
Edge Computing | 300+ global locations | <1ms cold start, 0ms warm start |
Serverless | Auto-scaling isolates | 0 maintenance, infinite scale |
Type Safety | Full TypeScript coverage | Runtime error prevention |
Streaming | Web Streams API | Real-time response delivery |
Modular Design | Functional composition | Easy testing & maintenance |
- Bundler: esbuild (10x faster than webpack)
- Module System: ES6 with tree-shaking
- Asset Pipeline: TypeScript β JavaScript + type checking
- Hot Reload: Wrangler dev server with instant updates
git clone https://github.com/your-username/claude-code-router
cd claude-code-router
npm install && npm install -g wrangler
npm run dev # Start development server
# Configure environment variables
wrangler secret put OPENROUTER_BASE_URL # OpenRouter backend
wrangler secret put DEEPSEEK_BASE_URL # DeepSeek backend
wrangler secret put OPENAI_BASE_URL # OpenAI backend
# Deploy to Cloudflare Workers
npm run deploy
flowchart LR
A[Environment Variables] --> B{Provider Selection}
B -->|Priority 1| C[DEEPSEEK_BASE_URL]
B -->|Priority 2| D[OPENAI_BASE_URL]
B -->|Priority 3| E[KIMI_BASE_URL]
B -->|Priority 4| F[SILICONFLOW_BASE_URL]
B -->|Default| G[OPENROUTER_BASE_URL]
C --> H[DeepSeek API]
D --> I[OpenAI API]
E --> J[Kimi API]
F --> K[SiliconFlow API]
G --> L[OpenRouter API]
curl -X POST https://cc.xiaohui.cool/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 100,
"stream": true
}'
Claude Model | OpenRouter | DeepSeek | OpenAI |
---|---|---|---|
claude-3-5-haiku-20241022 |
anthropic/claude-3.5-haiku |
deepseek-chat |
gpt-4o-mini |
claude-3-5-sonnet-20241022 |
anthropic/claude-3.5-sonnet |
deepseek-chat |
gpt-4o |
claude-3-opus-20240229 |
anthropic/claude-3-opus |
deepseek-reasoner |
gpt-4o |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Cloudflare Workers β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π Request Router β π Format Converter β π‘ Stream Handler β
β β’ Path matching β β’ Anthropic β OpenAI β β’ SSE processing β
β β’ Method validation β β’ OpenAI β Anthropic β β’ Chunk buffering β
β β’ Auth handling β β’ Model mapping β β’ Error recovery β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
claude-code-router/
βββ π src/
β βββ π client/ # Frontend & documentation system (TypeScript source)
β β βββ π bestPractices/ # Best practices module (development source)
β β β βββ π core/ # Manager & business logic
β β β βββ π data/ # Card data & configuration
β β β βββ π renderers/ # UI rendering components
β β β βββ π services/ # Content & markdown services
β β β βββ π index.ts # Module entry point
β β βββ π howToImplement/ # Implementation guide module (development source)
β β βββ π core/ # HowToImplementManager
β β βββ π data/ # Card data & configuration
β β βββ π handlers/ # Event handling
β β βββ π renderers/ # UI rendering components
β β βββ π services/ # Content services
β β βββ π index.ts # Module entry point
β βββ π server/ # Worker runtime logic
βββ π modules/ # Static HTML templates + compiled JavaScript
β βββ π best-practices/ # HTML template + bundled client code
β βββ π how-to-implement/ # HTML template + bundled client code
β βββ π get-started/ # Static module components
βββ π shared/ # Cross-platform utilities
β βββ π scripts/ # Generated bundles for runtime
β β βββ π generated/ # Auto-generated from src/client/*
β βββ π utils/ # Helper functions
βββ π scripts/ # Build automation & bundling
βββ π§ index.ts # Worker entry point (fetch handler)
βββ π§ formatRequest.ts # Anthropic β OpenAI transformer
βββ π§ formatResponse.ts # OpenAI β Anthropic transformer
βββ π§ streamResponse.ts # Server-Sent Events handler
βββ π§ types.ts # TypeScript definitions
βββ βοΈ wrangler.toml # Worker configuration & bindings
The project uses a dual-layer frontend architecture:
- Purpose: Modern TypeScript development with full module structure
- Architecture: Modular design (core, data, handlers, renderers, services)
- Benefits: Type safety, code organization, maintainability
- Build Target: Gets compiled and bundled by
scripts/build-client.js
- Purpose: Production-ready HTML templates + compiled JavaScript
- Architecture: Static HTML containers + bundled client code
- Benefits: Single-file deployment, optimized for Cloudflare Workers
- Source: Generated from development layer through build process
graph LR
A[src/client/*/index.ts] -->|esbuild| B[Bundled JavaScript]
B -->|Inject| C[modules/*/index.ts]
C -->|Runtime| D[HTML + JS Module]
E[scripts/build-client.js] -->|Orchestrates| A
style A fill:#e3f2fd
style B fill:#fff3e0
style C fill:#e8f5e8
style D fill:#fce4ec
This approach ensures clean separation between development complexity and runtime efficiency.
- π Edge-First: Optimized for Cloudflare's global network
- π Zero Dependencies: No external runtime dependencies
- β‘ Performance: Sub-millisecond response times
- π Streaming: Native Web Streams API support
- π‘οΈ Type Safety: Full TypeScript coverage with strict mode
Built with inspiration from:
MIT License - Use at your own risk and discretion.