Skip to content

Commit 294d2eb

Browse files
committed
feat: 新增多模型切换
1 parent eb940cb commit 294d2eb

File tree

11 files changed

+401
-80
lines changed

11 files changed

+401
-80
lines changed

README.md

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[English](./README_EN.md) | 中文
44

5-
Claude Code settings.json中key自动配置工具,方便API_KEY、AUTH_TOKEN配置切换
5+
Claude Code settings.json中key自动配置工具,方便API_KEY、AUTH_TOKEN以及多Model之间快速切换
66

77
## 功能特性
88

@@ -35,11 +35,14 @@ ccapi -v
3535
```bash
3636
例如:
3737
# 同时设置两个路径
38-
ccapi set --settings /Users/4xian/Desktop/settings.json --api /Users/4xian/Desktop/api.json
38+
ccapi set --settings /Users/4xian/.claude/settings.json --api /Users/4xian/Desktop/api.json
3939

4040
# 或分别设置
41-
ccapi set --settings /Users/4xian/Desktop/settings.json
41+
ccapi set --settings /Users/4xian/.claude/settings.json
4242
ccapi set --api /Users/4xian/Desktop/api.json
43+
44+
# 查询当前配置文件路径
45+
ccapi set
4346
```
4447

4548
### 3. 自定义API配置文件格式
@@ -56,10 +59,18 @@ ccapi set --api /Users/4xian/Desktop/api.json
5659
"timeout": 120000,
5760
"tokens": 20000
5861
},
59-
"anyrouter": {
60-
"url": "xxx",
61-
"key": "you-api-key",
62-
"model": "claude-sonnet-4-20250514"
62+
"multimodel": {
63+
"url": "https://api.example.com",
64+
"key": "your-api-key",
65+
"model": [
66+
"claude-sonnet-4-20250514",
67+
"claude-3-5-haiku-20241022",
68+
"claude-3-opus-20240229"
69+
],
70+
"fast": [
71+
"claude-3-5-haiku-20241022",
72+
"claude-3-haiku-20240307"
73+
]
6374
}
6475
}
6576
```
@@ -72,24 +83,82 @@ ccapi set --api /Users/4xian/Desktop/api.json
7283
- `key`: API_KEY(key 和 token 至少需要一个)
7384
- `token`: AUTH_TOKEN(key 和 token 至少需要一个)
7485
- `model`: 模型名称(非必需,默认claude-sonnet-4-20250514)
86+
- **字符串格式**: 直接指定一个模型
87+
- **数组格式**: 可指定多个模型,支持通过索引切换
7588
- `fast`: 快速模型名称(非必需,默认claude-3-5-haiku-20241022)
89+
- **字符串格式**: 直接指定一个快速模型
90+
- **数组格式**: 可指定多个快速模型,支持通过索引切换
7691
- `timeout`: 请求超时时间(非必需,默认600000ms)
7792
- `tokens`: 最大输出令牌数(非必需,默认25000)
93+
- `http`: 为网络连接指定 HTTP 代理服务器
94+
- `https`: 为网络连接指定 HTTPS 代理服务器
7895

7996
### 4. 列举api配置文件中的可用配置
8097

8198
```bash
8299
ccapi ls 或者 ccapi list
83100
```
84101

85-
> `*`号的配置表示当前正在使用
102+
显示效果:
103+
104+
```text
105+
可用的API配置:
106+
107+
【openrouter】
108+
URL: https://api.openrouter.ai
109+
Model: claude-sonnet-4-20250514
110+
Fast: claude-3-5-haiku-20241022
111+
Key: sk-or123...
112+
113+
* 【multimodel】
114+
URL: https://api.example.com
115+
Model:
116+
* - 1: claude-sonnet-4-20250514
117+
- 2: claude-3-5-haiku-20241022
118+
- 3: claude-3-opus-20240229
119+
Fast:
120+
- 1: claude-3-5-haiku-20241022
121+
* - 2: claude-3-haiku-20240307
122+
Key: sk-abc123...
123+
```
124+
125+
**显示说明:**
126+
127+
-`*`号的配置表示当前正在使用
128+
- 对于数组格式的 model/fast,会显示索引编号
86129

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

132+
#### 基本切换
133+
89134
```bash
135+
# 切换到指定配置(使用默认模型)
90136
ccapi use openrouter
137+
138+
# 对于字符串格式的 model/fast,直接切换
139+
ccapi use anyrouter
91140
```
92141

142+
#### 高级切换(适用于数组格式)
143+
144+
```bash
145+
# 切换到 multimodel 配置的第2个模型和第1个快速模型
146+
ccapi use multimodel -m 2 -f 1
147+
148+
# 只指定标准模型索引
149+
ccapi use multimodel -m 3
150+
151+
# 只指定快速模型索引
152+
ccapi use multimodel -f 2
153+
```
154+
155+
**参数说明:**
156+
157+
- `-m <index>`: 指定要使用的模型索引(从1开始计数)
158+
- `-f <index>`: 指定要使用的快速模型索引(从1开始计数)
159+
- 对于字符串格式的配置,会自动忽略索引参数
160+
- 不指定索引时默认使用数组的第一个元素
161+
93162
## 系统要求
94163

95164
- Node.js >= 14.0.0

README_EN.md

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
English | [中文](./README.md)
44

5-
Claude Code settings.json key auto-configuration tool for easy API_KEY and AUTH_TOKEN configuration switching
5+
Claude Code settings.json key auto-configuration tool for easy API_KEY and AUTH_TOKEN and multimodel configuration switching
66

77
## Features
88

@@ -40,6 +40,9 @@ ccapi set --settings /Users/4xian/Desktop/settings.json --api /Users/4xian/Deskt
4040
# Or set them separately
4141
ccapi set --settings /Users/4xian/Desktop/settings.json
4242
ccapi set --api /Users/4xian/Desktop/api.json
43+
44+
# Or get current path
45+
ccapi set
4346
```
4447

4548
### 3. Custom API Configuration File Format
@@ -56,10 +59,18 @@ Create an `api.json` file with the following format:
5659
"timeout": 120000,
5760
"tokens": 20000
5861
},
59-
"anyrouter": {
60-
"url": "xxx",
61-
"key": "you-api-key",
62-
"model": "claude-sonnet-4-20250514"
62+
"multimodel": {
63+
"url": "https://api.example.com",
64+
"key": "your-api-key",
65+
"model": [
66+
"claude-sonnet-4-20250514",
67+
"claude-3-5-haiku-20241022",
68+
"claude-3-opus-20240229"
69+
],
70+
"fast": [
71+
"claude-3-5-haiku-20241022",
72+
"claude-3-haiku-20240307"
73+
]
6374
}
6475
}
6576
```
@@ -72,24 +83,83 @@ Create an `api.json` file with the following format:
7283
- `key`: API_KEY (at least one of key or token is required)
7384
- `token`: AUTH_TOKEN (at least one of key or token is required)
7485
- `model`: Model name (optional, default: claude-sonnet-4-20250514)
86+
- **String format**: Directly specify a single model
87+
- **Array format**: Specify multiple models, supports switching via index
7588
- `fast`: Fast model name (optional, default: claude-3-5-haiku-20241022)
89+
- **String format**: Directly specify a single fast model
90+
- **Array format**: Specify multiple fast models, supports switching via index
7691
- `timeout`: Request timeout in milliseconds (optional, default: 600000ms)
7792
- `tokens`: Maximum output tokens (optional, default: 25000)
93+
- `http`: Custom HTTP Proxy Settings (optional)
94+
- `https`: Custom HTTPS Proxy Settings (optional)
7895

7996
### 4. List Available Configurations
8097

8198
```bash
8299
ccapi ls or ccapi list
83100
```
84101

85-
> Configurations marked with `*` indicate currently active configuration
102+
Display example:
103+
104+
```text
105+
Available API Configurations:
106+
107+
【openrouter】
108+
URL: https://api.openrouter.ai
109+
Model: claude-sonnet-4-20250514
110+
Fast: claude-3-5-haiku-20241022
111+
Key: sk-or123...
112+
113+
* 【multimodel】
114+
URL: https://api.example.com
115+
Model:
116+
* - 1: claude-sonnet-4-20250514
117+
- 2: claude-3-5-haiku-20241022
118+
- 3: claude-3-opus-20240229
119+
Fast:
120+
- 1: claude-3-5-haiku-20241022
121+
* - 2: claude-3-haiku-20240307
122+
Key: sk-abc123...
123+
```
124+
125+
**Display Description:**
126+
127+
- Configurations marked with `*` indicate currently active configuration
128+
- For array format model/fast, index numbers are displayed
129+
- Currently used model index is also marked with `*`
86130

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

133+
#### Basic Switching
134+
89135
```bash
136+
# Switch to specified configuration (using default model)
90137
ccapi use openrouter
138+
139+
# For string format model/fast, direct switching
140+
ccapi use anyrouter
91141
```
92142

143+
#### Advanced Switching (for Array Format)
144+
145+
```bash
146+
# Switch to multimodel config's 2nd model and 1st fast model
147+
ccapi use multimodel -m 2 -f 1
148+
149+
# Only specify standard model index, fast model uses default (1st)
150+
ccapi use multimodel -m 3
151+
152+
# Only specify fast model index, model uses default (1st)
153+
ccapi use multimodel -f 2
154+
```
155+
156+
**Parameter Description:**
157+
158+
- `-m <index>`: Specify model index to use (counting from 1)
159+
- `-f <index>`: Specify fast model index to use (counting from 1)
160+
- For string format configurations, index parameters are automatically ignored
161+
- When no index is specified, defaults to the first element of the array
162+
93163
## System Requirements
94164

95165
- Node.js >= 14.0.0

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.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@4xian/ccapi",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"author": "4xian (https://github.com/4xian)",
5-
"description": "Claude Code settings.json中key自动配置工具,方便API_KEY、AUTH_TOKEN配置切换",
5+
"description": "Claude Code settings.json中key自动配置工具,方便API_KEY、AUTH_TOKEN、多模型快速切换",
66
"repository": "https://github.com/4xian/claude-auto-api.git",
77
"homepage": "https://github.com/4xian",
88
"main": "dist/index.js",

0 commit comments

Comments
 (0)