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 build:client # Build frontend modules
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/
โ โโโ ๐ api/ # API ้้
ๅจๅ็ฑปๅๅฎไน
โ โ โโโ ๐ adapters/ # ่ฏทๆฑๅๅๅบๆ ผๅผ่ฝฌๆข
โ โ โ โโโ ๐ format.ts # ่ฏทๆฑ/ๅๅบๆ ผๅผๅ
โ โ โ โโโ ๐ stream.ts # ๆตๅค็
โ โ โโโ ๐ types.ts # API ็ฑปๅๅฎไน
โ โ โโโ ๐ providers.ts # ไพๅบๅ้
็ฝฎ
โ โโโ ๐ client/ # ๅ็ซฏๅๆๆกฃ็ณป็ป (TypeScript ๆบ็ )
โ โ โโโ ๐ bestPractices/ # ๆไฝณๅฎ่ทตๆจกๅ (ๅผๅๆบ็ )
โ โ โ โโโ ๐ core/ # ็ฎก็ๅจๅไธๅก้ป่พ
โ โ โ โโโ ๐ data/ # ๅก็ๆฐๆฎๅ้
็ฝฎ
โ โ โ โโโ ๐ renderers/ # UI ๆธฒๆ็ปไปถ
โ โ โ โโโ ๐ services/ # ๅ
ๅฎนๅ Markdown ๆๅก
โ โ โ โโโ ๐ index.ts # ๆจกๅๅ
ฅๅฃ็น
โ โ โโโ ๐ howToApplyCC/ # ๅฆไฝไฝฟ็จ CC ๆจกๅ
โ โ โ โโโ ๐ components/ # UI ็ปไปถ
โ โ โ โโโ ๐ services/ # ๆๅกๅฑ
โ โ โ โโโ ๐ index.ts # ๆจกๅๅ
ฅๅฃ็น
โ โ โโโ ๐ howToImplement/ # ๅฎ็ฐๆๅๆจกๅ (ๅผๅๆบ็ )
โ โ โโโ ๐ core/ # HowToImplementManager
โ โ โโโ ๐ data/ # ๅก็ๆฐๆฎๅ้
็ฝฎ
โ โ โโโ ๐ handlers/ # ไบไปถๅค็
โ โ โโโ ๐ renderers/ # UI ๆธฒๆ็ปไปถ
โ โ โโโ ๐ services/ # ๅ
ๅฎนๆๅก
โ โ โโโ ๐ index.ts # ๆจกๅๅ
ฅๅฃ็น
โ โโโ ๐ components/ # ๅ
ฑไบซ UI ็ปไปถ
โ โโโ ๐ config/ # ๅ
จๅฑ้
็ฝฎ
โ โโโ ๐ server/ # ๆๅกๅจ่ฟ่กๆถ้ป่พ
โ โ โโโ ๐ env.ts # ็ฏๅขๅ้็ฑปๅๅฎไน
โ โ โโโ ๐ index.ts # ๆๅกๅจๅ
ฅๅฃ็น
โ โ โโโ ๐ routes/ # ่ทฏ็ฑๅค็ๅจ
โ โ โโโ ๐ imgProxy.ts # ๅพ็ไปฃ็
โ โโโ ๐ scripts/ # ๅฎขๆท็ซฏ่ๆฌ
โ โ โโโ ๐ generated/ # ไป src/client/* ่ชๅจ็ๆ
โ โโโ ๐ styles/ # ๅ
จๅฑๆ ทๅผ
โ โโโ ๐ templates/ # HTML ๆจกๆฟ
โ โ โโโ ๐ components/ # ๆจกๆฟ็ปไปถ
โ โ โ โโโ ๐ favicon.ts # ๅพๆ ็ๆ
โ โ โโโ ๐ index.ts # ไธป้กตๆจกๆฟ
โ โ โโโ ๐ terms.ts # ๆๅกๆกๆฌพ้กต้ข
โ โ โโโ ๐ privacy.ts # ้็งๆฟ็ญ้กต้ข
โ โโโ ๐ utils/ # ๅทฅๅ
ทๅฝๆฐ
โโโ ๐ modules/ # ้ๆ HTML ๆจกๆฟ + ็ผ่ฏๅ็ JavaScript
โ โโโ ๐ best-practices/ # HTML ๆจกๆฟ + ๆๅ
็ๅฎขๆท็ซฏไปฃ็
โ โโโ ๐ get-started/ # ้ๆๆจกๅ็ปไปถ
โ โโโ ๐ how-to-apply-cc/ # ๅฆไฝไฝฟ็จ CC ๆจกๅ
โ โโโ ๐ how-to-implement/ # HTML ๆจกๆฟ + ๆๅ
็ๅฎขๆท็ซฏไปฃ็
โโโ ๐ scripts/ # ๆๅปบ่ชๅจๅๅๆๅ
โโโ ๐ง index.ts # Worker ๅ
ฅๅฃ็น (fetch ๅค็ๅจ)
โโโ โ๏ธ wrangler.toml # Worker ้
็ฝฎๅ็ปๅฎ
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 -->|build-client.js| C[modules/*/index.ts]
C -->|Runtime| D[HTML + JS Module]
E[npm run build:client] -->|Orchestrates| A
style A fill:#e3f2fd
style B fill:#fff3e0
style C fill:#e8f5e8
style D fill:#fce4ec
Active Modules:
- Best Practices (
src/client/bestPractices
โmodules/best-practices
) - How to Implement (
src/client/howToImplement
โmodules/how-to-implement
) - How to Apply Claude Code (
src/client/howToApplyCC
โmodules/how-to-apply-cc
) - Get Started (Static components in
modules/get-started
)
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.