@sifwenf/cc-proxy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +337 -0
- package/README.md +284 -0
- package/README.zh-CN.md +337 -0
- package/TASKS.md +102 -0
- package/config.example.json +29 -0
- package/package.json +21 -0
- package/scripts/ccp +126 -0
- package/scripts/status.js +32 -0
- package/src/config.ts +86 -0
- package/src/format-converter.ts +168 -0
- package/src/logger.ts +213 -0
- package/src/proxy.ts +83 -0
- package/src/scripts/init.ts +161 -0
- package/src/server.ts +338 -0
- package/src/types.ts +78 -0
package/README.ja.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# cc-proxy
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
Claude Code 用の軽量級 LLM プロキシサーバー - Anthropic API リクエストを任意の LLM プロバイダーにルーティングします。
|
|
6
|
+
|
|
7
|
+
## 機能
|
|
8
|
+
|
|
9
|
+
- **モデルルーティング**: Claude モデル(haiku、sonnet、opus)を任意のプロバイダーモデルにマッピング
|
|
10
|
+
- **マルチプロバイダー**: 複数の LLM プロバイダーを同時サポート
|
|
11
|
+
- **フォーマット変換**: Anthropic と OpenAI フォーマット間の自動変換
|
|
12
|
+
- **ホットリロード**: 設定変更を自動適用、再起動不要
|
|
13
|
+
- **パフォーマンス最適化**: 非同バッチログ記録でオーバーヘッド最小化
|
|
14
|
+
- **自動起動**: Shell 統み込み、バックグラウンドで静黙起動
|
|
15
|
+
|
|
16
|
+
## インストール
|
|
17
|
+
|
|
18
|
+
### オプション 1: Bun グローバルインストール(推奨)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# npm からインストール
|
|
22
|
+
bun install -g cc-proxy
|
|
23
|
+
|
|
24
|
+
# またはローカルソースから
|
|
25
|
+
cd cc-proxy
|
|
26
|
+
bun link
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
これにより `ccp` コマンドがグローバルにインストールされます:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
ccp start # プロキシサーバーを起動
|
|
33
|
+
ccp status # ステータス確認
|
|
34
|
+
ccp config # エディターで設定ファイルを開く
|
|
35
|
+
ccp logs # ログ表示
|
|
36
|
+
ccp help # すべてのコマンドを表示
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Shell 起動時に自動起動するため、`~/.zshrc` または `~/.bashrc` に追加:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
eval "$(ccp activate)"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### オプション 2: 手動セットアップ
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# リポジトリをクローン
|
|
49
|
+
git clone https://github.com/your-username/cc-proxy.git
|
|
50
|
+
cd cc-proxy
|
|
51
|
+
|
|
52
|
+
# 依存関係をインストール
|
|
53
|
+
bun install
|
|
54
|
+
|
|
55
|
+
# 設定を初期化
|
|
56
|
+
bun run init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## クイックスタート
|
|
60
|
+
|
|
61
|
+
### 1. 設定の初期化
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bun run init
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
これにより作成されます:
|
|
68
|
+
- `~/.claude-code-proxy/` ディレクトリ構造
|
|
69
|
+
- デフォルトの設定ファイル
|
|
70
|
+
- ログディレクトリ
|
|
71
|
+
|
|
72
|
+
### 2. プロバイダーの設定
|
|
73
|
+
|
|
74
|
+
設定ファイルを編集:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
~/.claude-code-proxy/config.json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. サーバーの起動
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# ccp コマンド使用(グローバルインストール場合)
|
|
84
|
+
ccp start
|
|
85
|
+
|
|
86
|
+
# または bun 使用
|
|
87
|
+
bun start
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## 構成リファレンス
|
|
92
|
+
|
|
93
|
+
### 完全な構造
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"server": {
|
|
98
|
+
"port": 3457,
|
|
99
|
+
"host": "127.0.0.1"
|
|
100
|
+
},
|
|
101
|
+
"logging": {
|
|
102
|
+
"enabled": true,
|
|
103
|
+
"level": "verbose",
|
|
104
|
+
"dir": "~/.claude-code-proxy/logs"
|
|
105
|
+
},
|
|
106
|
+
"providers": [
|
|
107
|
+
{
|
|
108
|
+
"name": "zp",
|
|
109
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
110
|
+
"apiKey": "your-api-key",
|
|
111
|
+
"format": "anthropic"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"router": {
|
|
115
|
+
"haiku": "zp,glm-4.7",
|
|
116
|
+
"sonnet": "zp,glm-4.7",
|
|
117
|
+
"opus": "zp,glm-4.7",
|
|
118
|
+
"image": "zp,glm-4.7"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### パラメータ
|
|
124
|
+
|
|
125
|
+
#### `server`
|
|
126
|
+
|
|
127
|
+
| パラメータ | 型 | デフォルト | 説明 |
|
|
128
|
+
|-----------|------|------------|------|
|
|
129
|
+
| `port` | number | `3457` | プロキシサーバーのポート番号 |
|
|
130
|
+
| `host` | string | `"127.0.0.1"` | バインドするホストアドレス |
|
|
131
|
+
|
|
132
|
+
#### `logging`
|
|
133
|
+
|
|
134
|
+
| パラメータ | 型 | デフォルト | 説明 |
|
|
135
|
+
|-----------|------|------------|------|
|
|
136
|
+
| `enabled` | boolean | `true` | ログの有効/無効 |
|
|
137
|
+
| `level` | string | `"verbose"` | ログレベル:`"basic"`、`"standard"`、`"verbose"` |
|
|
138
|
+
| `dir` | string | `"~/.claude-code-proxy/logs"` | ログファイル保存先 |
|
|
139
|
+
|
|
140
|
+
#### `providers`
|
|
141
|
+
|
|
142
|
+
プロバイダー設定配列。各プロバイダーオブジェクト:
|
|
143
|
+
|
|
144
|
+
| パラメータ | 型 | 必須 | 説明 |
|
|
145
|
+
|-----------|------|--------|------|
|
|
146
|
+
| `name` | string | ✅ はい | プロバイダーの一意識別子(ルーティングで使用) |
|
|
147
|
+
| `baseUrl` | string | ✅ はい | API エンドポイント URL |
|
|
148
|
+
| `apiKey` | string | ✅ はい | API 認証キー |
|
|
149
|
+
| `format` | string | いいえ | API フォーマット:`"anthropic"`、`"openai"`、または省略(pass-through) |
|
|
150
|
+
|
|
151
|
+
**フォーマット種類:**
|
|
152
|
+
- `"anthropic"`:Anthropic 互換ヘッダーを使用(x-api-key, anthropic-version)
|
|
153
|
+
- `"openai"`:OpenAI フォーマットに変換(Authorization: Bearer)
|
|
154
|
+
- 省略:Pass-through モード(元のヘッダーを転送、API キーのみ置換)
|
|
155
|
+
|
|
156
|
+
#### `router`
|
|
157
|
+
|
|
158
|
+
Claude モデル名をプロバイダーエンドポイントにマッピング。
|
|
159
|
+
|
|
160
|
+
形式:`"<claude-model>": "<provider-name>,<actual-model-name>"`
|
|
161
|
+
|
|
162
|
+
| パラメータ | 説明 | 例 |
|
|
163
|
+
|-----------|------|------|
|
|
164
|
+
| `haiku` | 高速/低コストモデルルーティング | `"zp,glm-4.7"` |
|
|
165
|
+
| `sonnet` | バランス性能モデルルーティング | `"zp,glm-4.7"` |
|
|
166
|
+
| `opus` | 高性能モデルルーティング | `"openrouter,anthropic/claude-opus-4.5"` |
|
|
167
|
+
| `image` | 画像生成モデルルーティング | `"zp,glm-4.7"` |
|
|
168
|
+
|
|
169
|
+
### ルーティング構文
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
"router": {
|
|
173
|
+
"haiku": "provider-name,model-name"
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**構成要素:**
|
|
178
|
+
- **プロバイダー名**:プロバイダーの `name` フィールドに一致する必要
|
|
179
|
+
- **モデル名**:プロバイダーにリクエストする実際のモデル
|
|
180
|
+
|
|
181
|
+
**例:**
|
|
182
|
+
- `"zp,glm-4.7"`:`zp` プロバイダー使用、`glm-4.7` モデルリクエスト
|
|
183
|
+
- `"openrouter,anthropic/claude-opus-4.5"`:OpenRouter 使用、Claude Opus 4.5 リクエスト
|
|
184
|
+
|
|
185
|
+
### 環境変数による上書き
|
|
186
|
+
|
|
187
|
+
`ANTHROPIC_BASE_URL` からポートを検出可能:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
これにより `server.port` 設定を上書きし、ポート `3456` を使用します。
|
|
194
|
+
|
|
195
|
+
サバーは:
|
|
196
|
+
- `~/.claude-code-proxy/` から設定を読み込み
|
|
197
|
+
- `~/.claude-code-proxy/logs/` にログを保存
|
|
198
|
+
- 設定ファイルの変更を監視し、ホットリロード
|
|
199
|
+
|
|
200
|
+
## 設定例
|
|
201
|
+
|
|
202
|
+
### Zhipu AI(Anthropic フォーマット)
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"name": "zp",
|
|
207
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
208
|
+
"apiKey": "your-key",
|
|
209
|
+
"format": "anthropic"
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### OpenRouter(OpenAI フォーマット)
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"name": "openrouter",
|
|
218
|
+
"baseUrl": "https://openrouter.ai/api/v1/chat/completions",
|
|
219
|
+
"apiKey": "sk-or-...",
|
|
220
|
+
"format": "openai"
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 複数プロバイダー設定
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"providers": [
|
|
229
|
+
{
|
|
230
|
+
"name": "zp",
|
|
231
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
232
|
+
"apiKey": "your-zpai-key"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"name": "openrouter",
|
|
236
|
+
"baseUrl": "https://openrouter.ai/api/v1/chat/completions",
|
|
237
|
+
"apiKey": "sk-or-..."
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"router": {
|
|
241
|
+
"haiku": "zp,glm-4.7",
|
|
242
|
+
"sonnet": "zp,glm-4.7",
|
|
243
|
+
"opus": "openrouter,anthropic/claude-opus-4.5"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## CLI コマンド
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
ccp activate # 静黙自動起動(Shell 設定用)
|
|
252
|
+
ccp start # 強制再起動して起動
|
|
253
|
+
ccp stop # プロキシサーバーを停止
|
|
254
|
+
ccp restart # プロキシサーバーを再起動
|
|
255
|
+
ccp status # 実行中ステータスを表示
|
|
256
|
+
ccp config # エディターで設定ファイルを開く(zed > vscode > vi)
|
|
257
|
+
ccp logs # サーバーログをリアルタイム表示
|
|
258
|
+
ccp help # ヘルプを表示
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Claude Code 連携
|
|
262
|
+
|
|
263
|
+
Claude Code で cc-proxy を使用するため、環境変数を設定:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
267
|
+
export ANTHROPIC_API_KEY="routing-key"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Shell 起動時に自動起動する場合、`~/.zshrc` に追加:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
eval "$(ccp activate)"
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## ログ管理
|
|
277
|
+
|
|
278
|
+
### 最新ログの表示
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# サーバーログ
|
|
282
|
+
ccp logs
|
|
283
|
+
|
|
284
|
+
# リクエストログ(JSONL フォーマット)
|
|
285
|
+
tail -f ~/.claude-code-proxy/logs/requests.jsonl | jq '.'
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### ログのフィルタリング
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
# プロバイダーでフィルタ
|
|
292
|
+
cat ~/.claude-code-proxy/logs/requests.jsonl | jq 'select(.provider == "zp")'
|
|
293
|
+
|
|
294
|
+
# タイプでフィルタ
|
|
295
|
+
cat ~/.claude-code-proxy/logs/requests.jsonl | jq 'select(.type == "forward")'
|
|
296
|
+
cat ~/.claude-code-proxy/logs/requests.jsonl | jq 'select(.type == "response")'
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## パフォーマンス
|
|
300
|
+
|
|
301
|
+
高並発シナリオ向けに最適化されています:
|
|
302
|
+
|
|
303
|
+
- **非同期バッチログ**: 100ms フラッシュ間隔で I/O ブロッキング最小化
|
|
304
|
+
- **チャンクごとのログなし**: ストリームングレスホンスでチャンク単位のオーバーヘッドを回避
|
|
305
|
+
- **効率的メモリ使用**: 約 100KB バッファ制限
|
|
306
|
+
- **グレースフルシャットダウン**: 終了前にログフラッシュ
|
|
307
|
+
|
|
308
|
+
agent-swarm シナリオで 100+ 並発リクエストを処理可能。
|
|
309
|
+
|
|
310
|
+
## トラブルシューティング
|
|
311
|
+
|
|
312
|
+
### サーバーが起動しない
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# 既に実行中か確認
|
|
316
|
+
ccp status
|
|
317
|
+
|
|
318
|
+
# ログを確認
|
|
319
|
+
ccp logs
|
|
320
|
+
|
|
321
|
+
# 強制再起動を試みる
|
|
322
|
+
ccp restart
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### 設定が読み込まれない
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# 設定ファイルの存在を確認
|
|
329
|
+
cat ~/.claude-code-proxy/config.json
|
|
330
|
+
|
|
331
|
+
# 再度初期化
|
|
332
|
+
bun run init
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## ライセンス
|
|
336
|
+
|
|
337
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# cc-proxy
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md) | [日本語](README.ja.md)
|
|
4
|
+
|
|
5
|
+
Lightweight LLM proxy server for Claude Code - route Anthropic API requests to any LLM provider.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Model Routing**: Map Claude models (haiku, sonnet, opus) to any provider model
|
|
10
|
+
- **Multi-Provider**: Support multiple LLM providers simultaneously
|
|
11
|
+
- **Format Conversion**: Auto-convert between Anthropic and OpenAI formats
|
|
12
|
+
- **Hot Reload**: Configuration changes applied automatically without restart
|
|
13
|
+
- **Performance Optimized**: Async batch logging for minimal overhead
|
|
14
|
+
- **Auto-Start**: Shell integration for silent background startup
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### Option 1: Bun Global Install (Recommended)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# From npm registry
|
|
22
|
+
bun install -g cc-proxy
|
|
23
|
+
|
|
24
|
+
# Or from local source
|
|
25
|
+
cd cc-proxy
|
|
26
|
+
bun link
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This installs the `ccp` command globally:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
ccp start # Start proxy server
|
|
33
|
+
ccp status # Check status
|
|
34
|
+
ccp config # Open config file in editor
|
|
35
|
+
ccp logs # View logs
|
|
36
|
+
ccp help # Show all commands
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add to `~/.zshrc` or `~/.bashrc` for auto-start on shell open:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
eval "$(ccp activate)"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Option 2: Manual Setup
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Clone repository
|
|
49
|
+
git clone https://github.com/your-username/cc-proxy.git
|
|
50
|
+
cd cc-proxy
|
|
51
|
+
|
|
52
|
+
# Install dependencies
|
|
53
|
+
bun install
|
|
54
|
+
|
|
55
|
+
# Initialize configuration
|
|
56
|
+
bun run init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### 1. Initialize Configuration
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bun run init
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This creates:
|
|
68
|
+
- `~/.claude-code-proxy/` directory structure
|
|
69
|
+
- Default configuration file
|
|
70
|
+
- Logs directory
|
|
71
|
+
|
|
72
|
+
### 2. Configure Providers
|
|
73
|
+
|
|
74
|
+
Edit your config at:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
~/.claude-code-proxy/config.json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Start Server
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Using ccp command (if globally installed)
|
|
84
|
+
ccp start
|
|
85
|
+
|
|
86
|
+
# Or using bun
|
|
87
|
+
bun start
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Configuration Reference
|
|
92
|
+
|
|
93
|
+
### Complete Configuration Structure
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"server": {
|
|
98
|
+
"port": 3457,
|
|
99
|
+
"host": "127.0.0.1"
|
|
100
|
+
},
|
|
101
|
+
"logging": {
|
|
102
|
+
"enabled": true,
|
|
103
|
+
"level": "verbose",
|
|
104
|
+
"dir": "~/.claude-code-proxy/logs"
|
|
105
|
+
},
|
|
106
|
+
"providers": [
|
|
107
|
+
{
|
|
108
|
+
"name": "zp",
|
|
109
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
110
|
+
"apiKey": "your-api-key",
|
|
111
|
+
"format": "anthropic"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"router": {
|
|
115
|
+
"haiku": "zp,glm-4.7",
|
|
116
|
+
"sonnet": "zp,glm-4.7",
|
|
117
|
+
"opus": "zp,glm-4.7",
|
|
118
|
+
"image": "zp,glm-4.7"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Parameters
|
|
124
|
+
|
|
125
|
+
#### `server`
|
|
126
|
+
|
|
127
|
+
| Parameter | Type | Default | Description |
|
|
128
|
+
|----------|------|---------|-------------|
|
|
129
|
+
| `port` | number | `3457` | Port number for the proxy server |
|
|
130
|
+
| `host` | string | `"127.0.0.1"` | Host address to bind to |
|
|
131
|
+
|
|
132
|
+
#### `logging`
|
|
133
|
+
|
|
134
|
+
| Parameter | Type | Default | Description |
|
|
135
|
+
|----------|------|---------|-------------|
|
|
136
|
+
| `enabled` | boolean | `true` | Enable/disable logging |
|
|
137
|
+
| `level` | string | `"verbose"` | Log detail level: `"basic"`, `"standard"`, or `"verbose"` |
|
|
138
|
+
| `dir` | string | `"~/.claude-code-proxy/logs"` | Directory to store log files |
|
|
139
|
+
|
|
140
|
+
#### `providers`
|
|
141
|
+
|
|
142
|
+
Array of provider configurations. Each provider object:
|
|
143
|
+
|
|
144
|
+
| Parameter | Type | Required | Description |
|
|
145
|
+
|----------|------|----------|-------------|
|
|
146
|
+
| `name` | string | ✅ Yes | Unique provider identifier (used in routing) |
|
|
147
|
+
| `baseUrl` | string | ✅ Yes | API endpoint URL |
|
|
148
|
+
| `apiKey` | string | ✅ Yes | API key for authentication |
|
|
149
|
+
| `format` | string | No | API format: `"anthropic"`, `"openai"`, or omit for pass-through |
|
|
150
|
+
|
|
151
|
+
**Format Types:**
|
|
152
|
+
- `"anthropic"`: Use Anthropic-compatible headers (x-api-key, anthropic-version)
|
|
153
|
+
- `"openai"`: Convert to OpenAI format (Authorization: Bearer)
|
|
154
|
+
- Omitted: Pass-through mode (forward original headers, only replace API key)
|
|
155
|
+
|
|
156
|
+
#### `router`
|
|
157
|
+
|
|
158
|
+
Maps Claude model names to provider endpoints.
|
|
159
|
+
|
|
160
|
+
Format: `"<claude-model>": "<provider-name>,<actual-model-name>"`
|
|
161
|
+
|
|
162
|
+
| Parameter | Description | Example |
|
|
163
|
+
|----------|-------------|---------|
|
|
164
|
+
| `haiku` | Fast/inexpensive model routing | `"zp,glm-4.7"` |
|
|
165
|
+
| `sonnet` | Balanced performance model routing | `"zp,glm-4.7"` |
|
|
166
|
+
| `opus` | High-performance model routing | `"openrouter,anthropic/claude-opus-4.5"` |
|
|
167
|
+
| `image` | Image generation model routing | `"zp,glm-4.7"` |
|
|
168
|
+
|
|
169
|
+
### Router Syntax
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
"router": {
|
|
173
|
+
"haiku": "provider-name,model-name"
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Components:**
|
|
178
|
+
- **Provider name**: Must match a provider's `name` field
|
|
179
|
+
- **Model name**: Actual model to request from provider
|
|
180
|
+
|
|
181
|
+
**Examples:**
|
|
182
|
+
- `"zp,glm-4.7"`: Use `zp` provider, request `glm-4.7` model
|
|
183
|
+
- `"openrouter,anthropic/claude-opus-4.5"`: Use OpenRouter, request Claude Opus 4.5
|
|
184
|
+
|
|
185
|
+
### Environment Variables Override
|
|
186
|
+
|
|
187
|
+
The proxy can detect port from `ANTHROPIC_BASE_URL`:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This will override the `server.port` configuration and use port `3456`.
|
|
194
|
+
|
|
195
|
+
## Configuration Examples
|
|
196
|
+
|
|
197
|
+
### Zhipu AI (Anthropic format)
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"name": "zp",
|
|
202
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
203
|
+
"apiKey": "your-key",
|
|
204
|
+
"format": "anthropic"
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### OpenRouter (OpenAI format)
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"name": "openrouter",
|
|
213
|
+
"baseUrl": "https://openrouter.ai/api/v1/chat/completions",
|
|
214
|
+
"apiKey": "sk-or-...",
|
|
215
|
+
"format": "openai"
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Multiple Providers
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"providers": [
|
|
224
|
+
{
|
|
225
|
+
"name": "zp",
|
|
226
|
+
"baseUrl": "https://api.z.ai/api/anthropic/v1/messages",
|
|
227
|
+
"apiKey": "your-zpai-key"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"name": "openrouter",
|
|
231
|
+
"baseUrl": "https://openrouter.ai/api/v1/chat/completions",
|
|
232
|
+
"apiKey": "sk-or-..."
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
"router": {
|
|
236
|
+
"haiku": "zp,glm-4.7",
|
|
237
|
+
"sonnet": "zp,glm-4.7",
|
|
238
|
+
"opus": "openrouter,anthropic/claude-opus-4.5"
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## CLI Commands
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
ccp activate # Silent auto-start (for shell config)
|
|
247
|
+
ccp start # Force restart and start
|
|
248
|
+
ccp stop # Stop the proxy server
|
|
249
|
+
ccp restart # Restart the proxy server
|
|
250
|
+
ccp status # Show running status
|
|
251
|
+
ccp config # Open config file in editor (zed > vscode > vi)
|
|
252
|
+
ccp logs # Tail server logs in real-time
|
|
253
|
+
ccp help # Show help message
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Claude Code Integration
|
|
257
|
+
|
|
258
|
+
Set environment variables to use cc-proxy with Claude Code:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
262
|
+
export ANTHROPIC_API_KEY="routing-key"
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
For auto-start on shell open, add to your `~/.zshrc`:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
eval "$(ccp activate)"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Performance
|
|
272
|
+
|
|
273
|
+
The proxy is optimized for high-concurrency scenarios:
|
|
274
|
+
|
|
275
|
+
- **Async batch logging**: 100ms flush intervals for minimal I/O blocking
|
|
276
|
+
- **No per-chunk logging**: Streaming responses bypass per-chunk overhead
|
|
277
|
+
- **Efficient memory usage**: ~100KB buffer limit
|
|
278
|
+
- **Graceful shutdown**: Flushes logs before exit
|
|
279
|
+
|
|
280
|
+
Handles 100+ concurrent requests from agent-swarm scenarios.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT
|