Skip to content

Commit 74f3bd2

Browse files
committed
feat: api配置文件新增多地址,多token配置
1 parent a03d26f commit 74f3bd2

File tree

7 files changed

+320
-118
lines changed

7 files changed

+320
-118
lines changed

README.md

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,26 @@ ccapi set
5757
```json
5858
{
5959
"openrouter": {
60-
"url": "xxx",
60+
"url": "https://api.openrouter.ai",
6161
"token": "your-auth-token",
6262
"model": "claude-sonnet-4-20250514",
6363
"fast": "claude-3-5-haiku-20241022",
6464
"timeout": 600000,
6565
"tokens": 65000
6666
},
67-
"multimodel": {
68-
"url": "https://api.example.com",
69-
"key": "your-api-key",
67+
"multiconfig": {
68+
"url": [
69+
"https://api.example1.com",
70+
"https://api.example2.com"
71+
],
72+
"key": [
73+
"sk-key1-for-api1",
74+
"sk-key2-for-api2"
75+
],
76+
"token": [
77+
"token1-for-auth",
78+
"token2-for-auth"
79+
],
7080
"model": [
7181
"claude-sonnet-4-20250514",
7282
"claude-3-5-haiku-20241022",
@@ -91,9 +101,16 @@ openrouter:
91101
timeout: 600000
92102
tokens: 65000
93103

94-
multimodel:
95-
url: "https://api.example.com"
96-
key: "your-api-key"
104+
multiconfig:
105+
url:
106+
- "https://api.example1.com"
107+
- "https://api.example2.com"
108+
key:
109+
- "sk-key1-for-api1"
110+
- "sk-key2-for-api2"
111+
token:
112+
- "token1-for-auth"
113+
- "token2-for-auth"
97114
model:
98115
- "claude-sonnet-4-20250514"
99116
- "claude-3-5-haiku-20241022"
@@ -130,9 +147,19 @@ fast = "claude-3-5-haiku-20241022"
130147
timeout = 600000
131148
tokens = 65000
132149

133-
[multimodel]
134-
url = "https://api.example.com"
135-
key = "your-api-key"
150+
[multiconfig]
151+
url = [
152+
"https://api.example1.com",
153+
"https://api.example2.com"
154+
]
155+
key = [
156+
"sk-key1-for-api1",
157+
"sk-key2-for-api2"
158+
]
159+
token = [
160+
"token1-for-auth",
161+
"token2-for-auth"
162+
]
136163
model = [
137164
"claude-sonnet-4-20250514",
138165
"claude-3-5-haiku-20241022",
@@ -149,8 +176,14 @@ fast = [
149176
【本工具只提供快速切换环境变量的功能,因此只支持Anthropic格式的配置, 当然只要Claude Code能用就都可以】
150177

151178
- `url`: API厂商服务器地址(必需)
152-
- `key`: API_KEY(key 和 token 至少需要一个)
153-
- `token`: AUTH_TOKEN(key 和 token 至少需要一个)
179+
- **字符串格式**: 直接指定一个URL
180+
- **数组格式**: 可指定多个URL,支持通过索引切换
181+
- `key`: API_KEY(key 和 token 同时只需要一个)
182+
- **字符串格式**: 直接指定一个API Key
183+
- **数组格式**: 可指定多个API Key,支持通过索引切换
184+
- `token`: AUTH_TOKEN(key 和 token 同时只需要一个)
185+
- **字符串格式**: 直接指定一个Auth Token
186+
- **数组格式**: 可指定多个Auth Token,支持通过索引切换
154187
- `model`: 模型名称(非必需,默认claude-sonnet-4-20250514)
155188
- **字符串格式**: 直接指定一个模型
156189
- **数组格式**: 可指定多个模型,支持通过索引切换
@@ -177,31 +210,40 @@ ccapi ls 或者 ccapi list
177210
URL: https://api.openrouter.ai
178211
Model: claude-sonnet-4-20250514
179212
Fast: claude-3-5-haiku-20241022
180-
Key: sk-or123...
213+
Token: your-auth-token...
181214
182-
* 【multimodel】
183-
URL: https://api.example.com
215+
* 【multiconfig】
216+
URL:
217+
* - 1: https://api.example1.com
218+
- 2: https://api.example2.com
184219
Model:
185220
* - 1: claude-sonnet-4-20250514
186221
- 2: claude-3-5-haiku-20241022
187222
- 3: claude-3-opus-20240229
188223
Fast:
189224
- 1: claude-3-5-haiku-20241022
190225
* - 2: claude-3-haiku-20240307
191-
Key: sk-abc123...
226+
Key:
227+
* - 1: sk-key1-for-api1...
228+
- 2: sk-key2-for-api2...
229+
Token:
230+
- 1: token1-for-auth...
231+
* - 2: token2-for-auth...
192232
```
193233

194234
**显示说明:**
195235

196236
-`*`号的配置表示当前正在使用
197-
- 对于数组格式的 model/fast,会显示索引编号
237+
- 对于数组格式的 url/key/token/model/fast,会显示索引编号
238+
- 当前使用的项会用 `* - ` 标识并高亮显示
239+
- 敏感信息(key、token)会自动脱敏显示
198240

199241
### 5. 自由切换配置(切换成功后记得重启Claude终端才会生效!!!)
200242

201243
#### 基本切换
202244

203245
```bash
204-
# 切换到指定配置(使用默认模型)
246+
# 切换到指定配置(使用默认模型,配置若为数组,则默认使用第一个
205247
ccapi use openrouter
206248

207249
# 对于字符串格式的 model/fast,直接切换
@@ -211,22 +253,30 @@ ccapi use anyrouter
211253
#### 高级切换(适用于数组格式)
212254

213255
```bash
214-
# 切换到 multimodel 配置的第2个模型和第1个快速模型
215-
ccapi use multimodel -m 2 -f 1
216-
217-
# 只指定标准模型索引
218-
ccapi use multimodel -m 3
219-
220-
# 只指定快速模型索引
221-
ccapi use multimodel -f 2
256+
# 切换到 multiconfig 配置,并使用第一个url,第一个token,第2个模型,第1个快速模型
257+
ccapi use multiconfig -u 1 -t 1 -m 2 -f 1
258+
259+
# 只切换某些字段的索引
260+
ccapi use multiconfig -k 1 # 只切换到某个Key
261+
ccapi use multiconfig -t 2 # 只切换到某个Token
262+
ccapi use multiconfig -u 1 # 只切换到某个URL
263+
ccapi use multiconfig -m 3 # 只切换到某个Model
264+
ccapi use multiconfig -f 2 # 只切换到某个Fast Model索引
265+
266+
# 组合使用示例
267+
ccapi use multiconfig -u 1 -k 1 -m 1 -f 2
222268
```
223269

224270
**参数说明:**
225271

272+
- `-u <index>`: 指定要使用的URL索引(从1开始计数)
273+
- `-k <index>`: 指定要使用的Key索引(从1开始计数)
274+
- `-t <index>`: 指定要使用的Token索引(从1开始计数)
226275
- `-m <index>`: 指定要使用的模型索引(从1开始计数)
227276
- `-f <index>`: 指定要使用的快速模型索引(从1开始计数)
228277
- 对于字符串格式的配置,会自动忽略索引参数
229278
- 不指定索引时默认使用数组的第一个元素
279+
- 可以任意组合使用这些参数
230280

231281
## 系统要求
232282

README_EN.md

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,26 @@ Create a configuration file (such as `api.json`, `api.yaml`, `api.jsonc`, `api.j
5757
```json
5858
{
5959
"openrouter": {
60-
"url": "xxx",
60+
"url": "https://api.openrouter.ai",
6161
"token": "your-auth-token",
6262
"model": "claude-sonnet-4-20250514",
6363
"fast": "claude-3-5-haiku-20241022",
64-
"timeout": 120000,
65-
"tokens": 20000
64+
"timeout": 600000,
65+
"tokens": 65000
6666
},
67-
"multimodel": {
68-
"url": "https://api.example.com",
69-
"key": "your-api-key",
67+
"multiconfig": {
68+
"url": [
69+
"https://api.example1.com",
70+
"https://api.example2.com"
71+
],
72+
"key": [
73+
"sk-key1-for-api1",
74+
"sk-key2-for-api2"
75+
],
76+
"token": [
77+
"token1-for-auth",
78+
"token2-for-auth"
79+
],
7080
"model": [
7181
"claude-sonnet-4-20250514",
7282
"claude-3-5-haiku-20241022",
@@ -88,12 +98,19 @@ openrouter:
8898
token: "your-auth-token"
8999
model: "claude-sonnet-4-20250514"
90100
fast: "claude-3-5-haiku-20241022"
91-
timeout: 120000
92-
tokens: 20000
93-
94-
multimodel:
95-
url: "https://api.example.com"
96-
key: "your-api-key"
101+
timeout: 600000
102+
tokens: 65000
103+
104+
multiconfig:
105+
url:
106+
- "https://api.example1.com"
107+
- "https://api.example2.com"
108+
key:
109+
- "sk-key1-for-api1"
110+
- "sk-key2-for-api2"
111+
token:
112+
- "token1-for-auth"
113+
- "token2-for-auth"
97114
model:
98115
- "claude-sonnet-4-20250514"
99116
- "claude-3-5-haiku-20241022"
@@ -113,8 +130,8 @@ multimodel:
113130
"token": "your-auth-token",
114131
"model": "claude-sonnet-4-20250514", // default model
115132
"fast": "claude-3-5-haiku-20241022", // fast model
116-
"timeout": 120000, // request timeout
117-
"tokens": 20000 // max output tokens
133+
"timeout": 600000, // request timeout
134+
"tokens": 65000 // max output tokens
118135
}
119136
}
120137
```
@@ -127,12 +144,22 @@ url = "https://api.openrouter.ai"
127144
token = "your-auth-token"
128145
model = "claude-sonnet-4-20250514"
129146
fast = "claude-3-5-haiku-20241022"
130-
timeout = 120000
131-
tokens = 20000
147+
timeout = 600000
148+
tokens = 65000
132149

133-
[multimodel]
134-
url = "https://api.example.com"
135-
key = "your-api-key"
150+
[multiconfig]
151+
url = [
152+
"https://api.example1.com",
153+
"https://api.example2.com"
154+
]
155+
key = [
156+
"sk-key1-for-api1",
157+
"sk-key2-for-api2"
158+
]
159+
token = [
160+
"token1-for-auth",
161+
"token2-for-auth"
162+
]
136163
model = [
137164
"claude-sonnet-4-20250514",
138165
"claude-3-5-haiku-20241022",
@@ -149,16 +176,22 @@ fast = [
149176
[This tool only supports Anthropic format configuration, but anything that works with Claude should be compatible]
150177

151178
- `url`: API provider server address (required)
179+
- **String format**: Directly specify a single URL
180+
- **Array format**: Specify multiple URLs, supports switching via index
152181
- `key`: API_KEY (at least one of key or token is required)
182+
- **String format**: Directly specify a single API Key
183+
- **Array format**: Specify multiple API Keys, supports switching via index
153184
- `token`: AUTH_TOKEN (at least one of key or token is required)
185+
- **String format**: Directly specify a single Auth Token
186+
- **Array format**: Specify multiple Auth Tokens, supports switching via index
154187
- `model`: Model name (optional, default: claude-sonnet-4-20250514)
155188
- **String format**: Directly specify a single model
156189
- **Array format**: Specify multiple models, supports switching via index
157190
- `fast`: Fast model name (optional, default: claude-3-5-haiku-20241022)
158191
- **String format**: Directly specify a single fast model
159192
- **Array format**: Specify multiple fast models, supports switching via index
160193
- `timeout`: Request timeout in milliseconds (optional, default: 600000ms)
161-
- `tokens`: Maximum output tokens (optional, default: 25000)
194+
- `tokens`: Maximum output tokens (optional, default: official)
162195
- `http`: Custom HTTP Proxy Settings (optional)
163196
- `https`: Custom HTTPS Proxy Settings (optional)
164197

@@ -177,25 +210,33 @@ Available API Configurations:
177210
URL: https://api.openrouter.ai
178211
Model: claude-sonnet-4-20250514
179212
Fast: claude-3-5-haiku-20241022
180-
Key: sk-or123...
213+
Token: your-auth-token...
181214
182-
* 【multimodel】
183-
URL: https://api.example.com
215+
* 【multiconfig】
216+
URL:
217+
* - 1: https://api.example1.com
218+
- 2: https://api.example2.com
184219
Model:
185220
* - 1: claude-sonnet-4-20250514
186221
- 2: claude-3-5-haiku-20241022
187222
- 3: claude-3-opus-20240229
188223
Fast:
189224
- 1: claude-3-5-haiku-20241022
190225
* - 2: claude-3-haiku-20240307
191-
Key: sk-abc123...
226+
Key:
227+
* - 1: sk-key1-for-api1...
228+
- 2: sk-key2-for-api2...
229+
Token:
230+
- 1: token1-for-auth...
231+
* - 2: token2-for-auth...
192232
```
193233

194234
**Display Description:**
195235

196236
- Configurations marked with `*` indicate currently active configuration
197-
- For array format model/fast, index numbers are displayed
198-
- Currently used model index is also marked with `*`
237+
- For array format url/key/token/model/fast, index numbers are displayed
238+
- Currently used items are marked with `* - ` and highlighted
239+
- Sensitive information (key, token) is automatically masked
199240

200241
### 5. Switch Configuration (Remember to restart Claude terminal after successful switch!!!)
201242

@@ -212,22 +253,33 @@ ccapi use anyrouter
212253
#### Advanced Switching (for Array Format)
213254

214255
```bash
215-
# Switch to multimodel config's 2nd model and 1st fast model
216-
ccapi use multimodel -m 2 -f 1
256+
# Switch to multiconfig configuration with specified field indices
257+
ccapi use multiconfig -u 1 -k 2 -t 1 -m 2 -f 2
258+
259+
# Mix different parameters
260+
ccapi use multiconfig -u 2 -m 1 -f 1
217261

218-
# Only specify standard model index, fast model uses default (1st)
219-
ccapi use multimodel -m 3
262+
# Switch only specific field indices
263+
ccapi use multiconfig -k 1 # Switch Key index only
264+
ccapi use multiconfig -t 2 # Switch Token index only
265+
ccapi use multiconfig -u 1 # Switch URL index only
266+
ccapi use multiconfig -m 3 # Switch Model index only
267+
ccapi use multiconfig -f 2 # Switch Fast Model index only
220268

221-
# Only specify fast model index, model uses default (1st)
222-
ccapi use multimodel -f 2
269+
# Combination usage examples
270+
ccapi use multiconfig -u 1 -k 1 -t 2 -m 1 -f 2
223271
```
224272

225273
**Parameter Description:**
226274

275+
- `-u <index>`: Specify URL index to use (counting from 1)
276+
- `-k <index>`: Specify Key index to use (counting from 1)
277+
- `-t <index>`: Specify Token index to use (counting from 1)
227278
- `-m <index>`: Specify model index to use (counting from 1)
228279
- `-f <index>`: Specify fast model index to use (counting from 1)
229280
- For string format configurations, index parameters are automatically ignored
230281
- When no index is specified, defaults to the first element of the array
282+
- You can combine these parameters in any way
231283

232284
## System Requirements
233285

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)