billion-context 0.1.19 → 0.1.21
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.md +198 -65
- package/README.zh-CN.md +147 -63
- package/dist/index.js +598 -50
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,54 +40,222 @@ npm install -g billion-context
|
|
|
40
40
|
|
|
41
41
|
This installs the `bili` command (`bili-proxy` is kept as an alias).
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Quickstart
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Three steps: **start the proxy → edit the config file → point your client at it**.
|
|
46
|
+
Compression is injected automatically — you only configure routing, never
|
|
47
|
+
compression itself.
|
|
48
|
+
|
|
49
|
+
### Step 1 — Start the proxy
|
|
46
50
|
|
|
47
51
|
```bash
|
|
48
52
|
bili
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
It listens on `http://127.0.0.1:8787`. Keep this terminal open (or run in the
|
|
56
|
+
background; see [Running the proxy](#running-the-proxy)).
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
On first run `bili` **auto-creates an empty config file** and tells you where:
|
|
59
|
+
so you don't have to invent the schema from scratch:
|
|
54
60
|
|
|
55
|
-
```bash
|
|
56
|
-
bili --port 9000 # change listen port
|
|
57
|
-
bili --host 0.0.0.0 # listen on all interfaces
|
|
58
|
-
bili --debug # verbose logging (also: set "debug": true in config)
|
|
59
|
-
bili --passthrough # forward without compression (smoke-test mode)
|
|
60
|
-
bili --config ~/my-bili.json # use a different config file
|
|
61
61
|
```
|
|
62
|
+
[acp-config] created empty config at ~/.config/billion-context/billion-context.json — add your providers (see README Quickstart), then restart
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Or configure via the web UI** (easier): open `http://localhost:8787/__acp/` in
|
|
66
|
+
a browser while the proxy is running — edit providers in a form, and get
|
|
67
|
+
copy-ready config snippets for Pi / OpenCode / Codex. The startup banner prints
|
|
68
|
+
this URL too:
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
```
|
|
71
|
+
acp-proxy listening on http://localhost:8787 — web UI: http://localhost:8787/__acp/
|
|
72
|
+
```
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
This is the recommended path for first-time setup. (Prefer editing the JSON
|
|
75
|
+
file directly — e.g. for git-managed or scripted deployments? See
|
|
76
|
+
[Manual config file](#manual-config-file) below.)
|
|
66
77
|
|
|
67
|
-
|
|
78
|
+
### How routing works
|
|
68
79
|
|
|
69
|
-
|
|
80
|
+
The proxy routes by a **provider name in the URL path** — the first path
|
|
81
|
+
segment after the host. It strips the name and forwards the rest to that
|
|
82
|
+
provider. Everything after the name is passed through untouched:
|
|
70
83
|
|
|
71
|
-
```bash
|
|
72
|
-
export ANTHROPIC_BASE_URL=http://localhost:8787/anthropic
|
|
73
|
-
export ANTHROPIC_API_KEY=sk-ant-... # real key — passed through as-is
|
|
74
|
-
claude
|
|
75
84
|
```
|
|
85
|
+
client baseURL: http://localhost:8787/zhipu/api/coding/paas/v4
|
|
86
|
+
└──────────┬──────────┘└────────┬────────┘
|
|
87
|
+
proxy host remaining path
|
|
88
|
+
+ provider name (forwarded as-is)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This is why Step 2 has you declare named providers, and Step 3 has you put that
|
|
92
|
+
same name at the start of the client's base URL — it's how the proxy knows where
|
|
93
|
+
to send each request. In the config below, `zhipu` corresponds to:
|
|
94
|
+
```json
|
|
95
|
+
"zhipu": {
|
|
96
|
+
"url": "https://open.bigmodel.cn",
|
|
97
|
+
"models": {
|
|
98
|
+
"glm-5.2": { "context": 1000000, "output": 131072 }
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Step 2 — Configure your providers
|
|
103
|
+
|
|
104
|
+
Open the **web UI** at `http://localhost:8787/__acp/` and add your providers
|
|
105
|
+
there (add provider → fill name + URL + per-model context → Save). This writes
|
|
106
|
+
to `~/.config/billion-context/billion-context.json` directly. Then **restart
|
|
107
|
+
`bili`** — the startup banner lists your routes:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
acp-proxy listening on http://localhost:8787 — routes: anthropic=https://api.anthropic.com, zhipu=https://open.bigmodel.cn
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
That confirms the proxy picked up your config. (Prefer editing the JSON file by
|
|
114
|
+
hand? See [Manual config file](#manual-config-file). Full schema — per-model
|
|
115
|
+
context windows, optional fields — is in [Configuration](#configuration).)
|
|
116
|
+
|
|
117
|
+
### Step 3 — Point your client at the proxy
|
|
118
|
+
|
|
119
|
+
Edit the client's own config file so it sends requests to
|
|
120
|
+
`http://localhost:8787/<provider>/...` (the provider name from Step 2 as the
|
|
121
|
+
first path segment). Put your **real** API key in the client's config too —
|
|
122
|
+
the proxy passes it through untouched.
|
|
123
|
+
|
|
124
|
+
#### Pi (billion-context-pi)
|
|
125
|
+
|
|
126
|
+
Open `~/.pi/agent/models.json` and change your existing provider's **`baseUrl` line** to point at the proxy — leave every other field alone:
|
|
127
|
+
|
|
128
|
+
```jsonc
|
|
129
|
+
// before:
|
|
130
|
+
"baseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
131
|
+
// after (swap the host for the proxy + the provider name you picked):
|
|
132
|
+
"baseUrl": "http://localhost:8787/zhipu/api/coding/paas/v4",
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`http://localhost:8787` is the proxy, `zhipu` is the name from Step 2, and the remaining path `/api/coding/paas/v4` is forwarded as-is to Zhipu. `apiKey`, `api`, and `models` stay unchanged.
|
|
136
|
+
|
|
137
|
+
| `api` value | `baseUrl` should point at |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `openai-completions` | an OpenAI-compatible endpoint (GLM/DeepSeek/OpenAI) → `…/zhipu/...` |
|
|
140
|
+
| `anthropic-messages` | an Anthropic-compatible endpoint → `…/anthropic` |
|
|
141
|
+
|
|
142
|
+
> If you use the `billion-context-pi` extension, run Pi in an isolated agent
|
|
143
|
+
dir (`PI_CODING_AGENT_DIR=…`) so the client-side extension doesn't double-
|
|
144
|
+
compress alongside the proxy. The `bili-test-pi` helper does this for you.
|
|
145
|
+
|
|
146
|
+
#### OpenCode
|
|
147
|
+
|
|
148
|
+
Open `~/.config/opencode/opencode.json` and change your existing provider's **`baseURL` line** to point at the proxy:
|
|
149
|
+
|
|
150
|
+
```jsonc
|
|
151
|
+
// before:
|
|
152
|
+
"baseURL": "https://open.bigmodel.cn/api/coding/paas/v4"
|
|
153
|
+
// after:
|
|
154
|
+
"baseURL": "http://localhost:8787/zhipu/api/coding/paas/v4"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Everything else (`apiKey`, `models`) stays unchanged. For an Anthropic provider, change `baseURL` to `http://localhost:8787/anthropic`.
|
|
158
|
+
|
|
159
|
+
#### Codex
|
|
160
|
+
|
|
161
|
+
Open `~/.codex/config.toml` and change your existing provider's **`base_url` line** to point at the proxy:
|
|
162
|
+
|
|
163
|
+
```toml
|
|
164
|
+
# before:
|
|
165
|
+
base_url = "https://open.bigmodel.cn/api/coding/paas/v4"
|
|
166
|
+
# after:
|
|
167
|
+
base_url = "http://localhost:8787/zhipu/api/coding/paas/v4"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Everything else (`name`, `wire_api`, `env_key`) stays unchanged.
|
|
171
|
+
|
|
172
|
+
> Codex's Responses API needs an upstream that speaks the Responses protocol.
|
|
173
|
+
> Most regional OpenAI-compatible endpoints only speak `/chat/completions`; if
|
|
174
|
+
> yours 404s on `/responses`, use a relay that speaks Responses, or the
|
|
175
|
+
> official OpenAI API.
|
|
176
|
+
|
|
177
|
+
#### Other clients (Cursor / Aider / Continue …)
|
|
178
|
+
|
|
179
|
+
Not yet supported. The proxy currently speaks the Anthropic, OpenAI
|
|
180
|
+
chat-completions, and OpenAI Responses protocols — if your client uses a
|
|
181
|
+
different protocol or a non-standard auth header, it won't work yet.
|
|
182
|
+
|
|
183
|
+
### Web UI
|
|
76
184
|
|
|
77
|
-
|
|
185
|
+
Open `http://localhost:8787/__acp/` in a browser while the proxy is running. You can:
|
|
186
|
+
|
|
187
|
+
- **Edit providers** in a form (add/remove providers and per-model context windows) and save — this writes to `billion-context.json` directly.
|
|
188
|
+
- **Generate client URLs** — pick a provider, get ready-to-copy config snippets for Pi / OpenCode / Codex (the `baseUrl`/`baseURL`/`base_url` line with the proxy origin + provider name filled in).
|
|
189
|
+
- **View sessions** — live table of active sessions (requests, tokens saved, last seen), auto-refreshing.
|
|
190
|
+
|
|
191
|
+
Changes to providers require a **restart** to take effect (the UI tells you this).
|
|
192
|
+
|
|
193
|
+
### Manual config file
|
|
194
|
+
|
|
195
|
+
Prefer editing JSON by hand — for git-managed configs, scripted deployments, or
|
|
196
|
+
if you just don't want to use the browser? The web UI writes to the same file,
|
|
197
|
+
so you can edit it directly with identical results.
|
|
198
|
+
|
|
199
|
+
Open `~/.config/billion-context/billion-context.json` and edit the `providers`
|
|
200
|
+
block. Each entry is a **name → URL** mapping; the name is what you put in the
|
|
201
|
+
client's base URL in Step 3.
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"providers": {
|
|
206
|
+
"zhipu": {
|
|
207
|
+
"url": "https://open.bigmodel.cn",
|
|
208
|
+
"models": {
|
|
209
|
+
"glm-5.2": { "context": 1000000, "output": 131072 }
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"anthropic": "https://api.anthropic.com"
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
- Delete providers you don't use.
|
|
218
|
+
- Add others (e.g. `"deepseek": "https://api.deepseek.com"`).
|
|
219
|
+
- The API key is **not** here — it lives in the client; the proxy passes it
|
|
220
|
+
through untouched.
|
|
221
|
+
|
|
222
|
+
After saving, **restart `bili`**. (Full schema — per-model context windows,
|
|
223
|
+
optional fields — is in [Configuration](#configuration).)
|
|
224
|
+
|
|
225
|
+
### Verify
|
|
226
|
+
|
|
227
|
+
With the proxy running and your config saved, check it answers and that your
|
|
228
|
+
first real request shows compression activity in the log:
|
|
78
229
|
|
|
79
230
|
```bash
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
231
|
+
# Health check (proxy up + where it forwards)
|
|
232
|
+
curl -s http://localhost:8787/__acp/health
|
|
233
|
+
# → {"ok":true,"upstream":"https://api.anthropic.com"}
|
|
234
|
+
|
|
235
|
+
# Live session stats (after a real request)
|
|
236
|
+
curl -s http://localhost:8787/__acp/stats
|
|
83
237
|
```
|
|
84
238
|
|
|
85
|
-
|
|
86
|
-
|
|
239
|
+
Then send one message from your client and watch the log
|
|
240
|
+
(`~/.local/state/billion-context/bili.log`, also printed to stderr). You
|
|
241
|
+
should see a `processTurn` line per request, and once the conversation grows,
|
|
242
|
+
`[acp-usage] round N input=X cached=Y (cache hit Z%)` + a `compress` event.
|
|
87
243
|
|
|
88
|
-
|
|
244
|
+
## Running the proxy
|
|
89
245
|
|
|
90
|
-
|
|
246
|
+
### Flags
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
bili --port 9000 # change listen port
|
|
250
|
+
bili --host 0.0.0.0 # listen on all interfaces (see host note below)
|
|
251
|
+
bili --debug # verbose logging (also: set "debug": true in config)
|
|
252
|
+
bili --passthrough # forward without compression (smoke-test mode)
|
|
253
|
+
bili --config ~/my-bili.json # use a different config file
|
|
254
|
+
bili update # check & install a newer version now (bypasses throttle)
|
|
255
|
+
bili --no-auto-update # disable self-update for this run
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Flags override env vars and the config file. `bili --help` lists them all.
|
|
91
259
|
|
|
92
260
|
### Debugging
|
|
93
261
|
|
|
@@ -108,8 +276,6 @@ All logs are **tee'd to a file by default**: `~/.local/state/billion-context/bil
|
|
|
108
276
|
shows them in the terminal.
|
|
109
277
|
|
|
110
278
|
```bash
|
|
111
|
-
bili start # logs → ~/.local/state/billion-context/bili.log + terminal
|
|
112
|
-
bili update # (see below)
|
|
113
279
|
# Config: "logFile": "/custom/path.log"
|
|
114
280
|
# Env: ACP_LOG_FILE=/custom/path.log (or ACP_LOG_FILE=off to disable the file)
|
|
115
281
|
```
|
|
@@ -124,11 +290,6 @@ The proxy checks npm for a newer version on startup and every 3 minutes. When a
|
|
|
124
290
|
newer version is found it installs it globally (`npm install -g`) and logs a
|
|
125
291
|
notice — **restart `bili` to pick up the new version**.
|
|
126
292
|
|
|
127
|
-
```bash
|
|
128
|
-
bili update # check & install now (manual, bypasses 3min throttle)
|
|
129
|
-
bili --no-auto-update # disable self-update for this run
|
|
130
|
-
```
|
|
131
|
-
|
|
132
293
|
Disable permanently via config (`"autoUpdate": false`) or env
|
|
133
294
|
(`ACP_AUTO_UPDATE=0`).
|
|
134
295
|
|
|
@@ -259,43 +420,15 @@ built-in model table, then to `modelContextLimit`.
|
|
|
259
420
|
**API keys are never stored in the proxy** — whatever key the agent sends is
|
|
260
421
|
passed through untouched to the upstream.
|
|
261
422
|
|
|
262
|
-
###
|
|
263
|
-
|
|
264
|
-
Point any agent at the proxy using a provider name as a path segment. The
|
|
265
|
-
proxy strips the name and forwards to that provider's root URL.
|
|
266
|
-
|
|
267
|
-
```
|
|
268
|
-
agent baseURL: http://localhost:8787/zhipu/api/coding/paas/v4
|
|
269
|
-
└──────────┬──────────┘└────────┬────────┘
|
|
270
|
-
proxy host remaining path
|
|
271
|
-
+ provider name (forwarded as-is)
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
#### Claude Code (Anthropic)
|
|
275
|
-
|
|
276
|
-
```bash
|
|
277
|
-
export ANTHROPIC_BASE_URL=http://localhost:8787/anthropic
|
|
278
|
-
export ANTHROPIC_API_KEY=sk-ant-... # real key — passed through as-is
|
|
279
|
-
claude
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
#### Codex / any OpenAI-compatible agent (zhipu / openai / deepseek)
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
export OPENAI_BASE_URL=http://localhost:8787/zhipu/api/coding/paas/v4
|
|
286
|
-
export OPENAI_API_KEY=<your real glm key> # passed through as-is
|
|
287
|
-
codex
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
The `/zhipu/...` prefix tells the proxy to route to the `zhipu` provider; the
|
|
291
|
-
remaining `/api/coding/paas/v4/...` path is preserved.
|
|
292
|
-
|
|
293
|
-
### Notes on provider names
|
|
423
|
+
### Provider name rules
|
|
294
424
|
|
|
295
425
|
- Must start with a letter, contain only letters/digits/`-`/`_`.
|
|
296
426
|
- Reserved words (`v1`, `chat`, `completions`, `messages`, `models`, `api`)
|
|
297
427
|
are rejected to avoid colliding with real API path segments.
|
|
298
428
|
- The provider name can appear anywhere in the path; the longest match wins.
|
|
429
|
+
- With **no providers** declared (e.g. you emptied the `providers` block),
|
|
430
|
+
every request is forwarded to the default `upstream` with its full path —
|
|
431
|
+
an edge case, not the normal flow.
|
|
299
432
|
|
|
300
433
|
## How sessions work
|
|
301
434
|
|
package/README.zh-CN.md
CHANGED
|
@@ -40,53 +40,170 @@ npm install -g billion-context
|
|
|
40
40
|
|
|
41
41
|
这会安装 `bili` 命令(`bili-proxy` 保留为别名)。
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## 快速上手
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
三步:**启动代理 → 编辑配置文件 → 把客户端指向它**。
|
|
46
|
+
压缩是自动注入的 —— 你只需配置路由,无需配置压缩本身。
|
|
47
|
+
|
|
48
|
+
### 第 1 步 —— 启动代理
|
|
46
49
|
|
|
47
50
|
```bash
|
|
48
51
|
bili
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
它监听 `http://127.0.0.1:8787`。保持这个终端开着(或后台运行,见[运行代理](#运行代理))。
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
点击[http://localhost:8787/__acp/](http://localhost:8787/__acp/) 添加你的模型
|
|
57
|
+
<img width="2908" height="1787" alt="image" src="https://github.com/user-attachments/assets/cacf4b64-e5c6-41f2-b270-fd2be02eab0c" />
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
### 第 2 步 —— 编辑配置文件
|
|
60
|
+
|
|
61
|
+
复制以下内容
|
|
62
|
+
|
|
63
|
+
<img width="2931" height="1519" alt="image" src="https://github.com/user-attachments/assets/c02278be-bc7a-4f14-8f58-0f2d83784d54" />
|
|
64
|
+
|
|
65
|
+
> 不想用网页?也可以直接手编 JSON 文件,见下文[手动配置文件](#手动配置文件)。
|
|
66
|
+
|
|
67
|
+
### 第 3 步 —— 把客户端指向代理
|
|
68
|
+
|
|
69
|
+
编辑客户端自己的配置文件,让它把请求发到
|
|
70
|
+
`http://localhost:8787/<provider>/...`(第 2 步声明的 provider 名作为路径
|
|
71
|
+
第一段)。把你的**真实** API key 也填进客户端配置 —— 代理原样透传。
|
|
72
|
+
|
|
73
|
+
#### Pi(billion-context-pi)
|
|
74
|
+
|
|
75
|
+
打开 `~/.pi/agent/models.json`,把你现有 provider 的 **`baseUrl` 这一行**改成指向代理,其他字段都不用动:
|
|
76
|
+
|
|
77
|
+
```jsonc
|
|
78
|
+
// 改之前:
|
|
79
|
+
"baseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
|
|
80
|
+
// 改之后(把 host 换成代理 + 你起的 provider 名):
|
|
81
|
+
"baseUrl": "http://localhost:8787/zhipu/api/coding/paas/v4",
|
|
61
82
|
```
|
|
62
83
|
|
|
63
|
-
|
|
84
|
+
`http://localhost:8787` 是代理,`zhipu` 是第 2 步起的名字,剩余路径 `/api/coding/paas/v4` 原样转发到智谱。`apiKey`、`api`、`models` 都不用改。
|
|
64
85
|
|
|
65
|
-
|
|
86
|
+
| `api` 值 | `baseUrl` 应指向 |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `openai-completions` | OpenAI 兼容端点(GLM/DeepSeek/OpenAI)→ `…/zhipu/...` |
|
|
89
|
+
| `anthropic-messages` | Anthropic 兼容端点 → `…/anthropic` |
|
|
66
90
|
|
|
67
|
-
|
|
91
|
+
> 如果你装了 `billion-context-pi` 扩展,用隔离的 agent 目录跑 Pi
|
|
92
|
+
> (`PI_CODING_AGENT_DIR=…`),免得客户端扩展和 proxy 双重压缩。
|
|
93
|
+
> `bili-test-pi` 脚本帮你做好了这层隔离。
|
|
68
94
|
|
|
69
|
-
####
|
|
95
|
+
#### OpenCode
|
|
70
96
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
打开 `~/.config/opencode/opencode.json`,把你现有 provider 的 **`baseURL` 这一行**改成指向代理:
|
|
98
|
+
|
|
99
|
+
```jsonc
|
|
100
|
+
// 改之前:
|
|
101
|
+
"baseURL": "https://open.bigmodel.cn/api/coding/paas/v4"
|
|
102
|
+
// 改之后:
|
|
103
|
+
"baseURL": "http://localhost:8787/zhipu/api/coding/paas/v4"
|
|
75
104
|
```
|
|
76
105
|
|
|
77
|
-
|
|
106
|
+
其他字段(`apiKey`、`models`)都不用改。如果要走 Anthropic provider,把 `baseURL` 改为 `http://localhost:8787/anthropic`。
|
|
107
|
+
|
|
108
|
+
#### Codex
|
|
109
|
+
|
|
110
|
+
打开 `~/.codex/config.toml`,把现有 provider 的 **`base_url` 这一行**改成指向代理:
|
|
111
|
+
|
|
112
|
+
```toml
|
|
113
|
+
# 改之前:
|
|
114
|
+
base_url = "https://open.bigmodel.cn/api/coding/paas/v4"
|
|
115
|
+
# 改之后:
|
|
116
|
+
base_url = "http://localhost:8787/zhipu/api/coding/paas/v4"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
其他字段(`name`、`wire_api`、`env_key`)都不用改。
|
|
120
|
+
|
|
121
|
+
> Codex 的 Responses API 需要上游说 Responses 协议。多数区域性 OpenAI
|
|
122
|
+
> 兼容端点只说 `/chat/completions`;如果你的端点在 `/responses` 上 404,
|
|
123
|
+
> 用一个说 Responses 的中转,或用官方 OpenAI API。
|
|
124
|
+
|
|
125
|
+
#### 其他客户端(Cursor / Aider / Continue …)
|
|
126
|
+
|
|
127
|
+
暂不支持。代理目前说 Anthropic、OpenAI chat-completions、OpenAI Responses
|
|
128
|
+
三种协议 —— 如果你的客户端用别的协议或非标准 auth header,还用不了。
|
|
129
|
+
|
|
130
|
+
### 手动配置文件
|
|
131
|
+
|
|
132
|
+
上面用网页配置。如果你不想用网页、想把配置纳入 git 管理、或者用脚本
|
|
133
|
+
自动化部署,也可以直接手编 JSON 文件,效果完全一样。
|
|
134
|
+
|
|
135
|
+
打开 `~/.config/billion-context/billion-context.json`,编辑 `providers` 块。
|
|
136
|
+
每个条目是一个**名字 → URL** 映射;这个名字就是你在第 3 步里写进客户端
|
|
137
|
+
base URL 的东西。
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"providers": {
|
|
142
|
+
"zhipu": {
|
|
143
|
+
"url": "https://open.bigmodel.cn",
|
|
144
|
+
"models": {
|
|
145
|
+
"glm-5.2": { "context": 1000000, "output": 131072 }
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"anthropic": "https://api.anthropic.com"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- 删掉你不用的 provider。
|
|
154
|
+
- 添加其他的(例如 `"deepseek": "https://api.deepseek.com"`)。
|
|
155
|
+
- API key **不**写在这里 —— key 在客户端那边,代理原样透传。
|
|
156
|
+
|
|
157
|
+
保存后**重启 `bili`**。启动行列出你的路由:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
acp-proxy listening on http://127.0.0.1:8787 — routes: anthropic=https://api.anthropic.com, zhipu=https://open.bigmodel.cn
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
这证明代理读到了你的配置。(完整 schema —— 按模型的 context 窗口、可选字段 —— 见[配置](#配置)。)
|
|
164
|
+
|
|
165
|
+
### 网页配置
|
|
166
|
+
|
|
167
|
+
代理跑着的时候,在浏览器打开 `http://localhost:8787/__acp/`。你可以:
|
|
168
|
+
|
|
169
|
+
- **编辑 providers** —— 用表单增删 provider 和按模型的 context 窗口,点 Save 直接写入 `billion-context.json`。
|
|
170
|
+
- **生成客户端 URL** —— 选一个 provider,得到可直接复制的配置片段(Pi / OpenCode / Codex 的 `baseUrl`/`baseURL`/`base_url` 一行,已填好代理地址 + provider 名)。
|
|
171
|
+
- **查看会话** —— 实时会话表(请求数、省的 token、最后活跃时间),自动刷新。
|
|
172
|
+
|
|
173
|
+
改完 providers 需要**重启 bili** 才生效(UI 会提醒你)。
|
|
174
|
+
|
|
175
|
+
### 验证
|
|
176
|
+
|
|
177
|
+
代理跑着、配置保存了之后,确认它能应答,并且第一个真实请求在日志里显示压缩活动:
|
|
78
178
|
|
|
79
179
|
```bash
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
180
|
+
# 健康检查(代理是否在跑 + 转发到哪)
|
|
181
|
+
curl -s http://localhost:8787/__acp/health
|
|
182
|
+
# → {"ok":true,"upstream":"https://api.anthropic.com"}
|
|
183
|
+
|
|
184
|
+
# 实时会话统计(发过真实请求后)
|
|
185
|
+
curl -s http://localhost:8787/__acp/stats
|
|
83
186
|
```
|
|
84
187
|
|
|
85
|
-
|
|
188
|
+
然后从助手发一条消息,观察日志(`~/.local/state/billion-context/bili.log`,
|
|
189
|
+
同时也打到 stderr)。每个请求应该看到一行 `processTurn`,等对话变长后
|
|
190
|
+
会出现 `[acp-usage] round N input=X cached=Y (cache hit Z%)` + `compress` 事件。
|
|
191
|
+
|
|
192
|
+
## 运行代理
|
|
193
|
+
|
|
194
|
+
### 命令行参数
|
|
86
195
|
|
|
87
|
-
|
|
196
|
+
```bash
|
|
197
|
+
bili --port 9000 # 改监听端口
|
|
198
|
+
bili --host 0.0.0.0 # 监听所有网卡(见下面的 host 说明)
|
|
199
|
+
bili --debug # 详细日志(也可在配置里设 "debug": true)
|
|
200
|
+
bili --passthrough # 不压缩直接转发(冒烟测试模式)
|
|
201
|
+
bili --config ~/my-bili.json # 用别的配置文件
|
|
202
|
+
bili update # 立即检查并安装新版本(跳过节流)
|
|
203
|
+
bili --no-auto-update # 本次启动禁用自动更新
|
|
204
|
+
```
|
|
88
205
|
|
|
89
|
-
|
|
206
|
+
参数优先级高于环境变量和配置文件。`bili --help` 列出全部。
|
|
90
207
|
|
|
91
208
|
### 调试
|
|
92
209
|
|
|
@@ -100,11 +217,10 @@ codex
|
|
|
100
217
|
|
|
101
218
|
### 日志文件
|
|
102
219
|
|
|
103
|
-
所有日志**默认同时写入文件**:`~/.local/state/billion-context/bili.log`
|
|
220
|
+
所有日志**默认同时写入文件**:`~/.local/state/billion-context/bili.log`
|
|
221
|
+
(XDG state 目录)。同时仍打印到 stderr,所以前台运行 `bili start` 时终端也能看到。
|
|
104
222
|
|
|
105
223
|
```bash
|
|
106
|
-
bili start # 日志 → ~/.local/state/billion-context/bili.log + 终端
|
|
107
|
-
bili update # (见下文)
|
|
108
224
|
# 配置: "logFile": "/custom/path.log"
|
|
109
225
|
# 环境变量: ACP_LOG_FILE=/custom/path.log (或 ACP_LOG_FILE=off 关闭文件,只保留 stderr)
|
|
110
226
|
```
|
|
@@ -115,11 +231,6 @@ bili update # (见下文)
|
|
|
115
231
|
|
|
116
232
|
代理启动时和每 3 分钟检查 npm 是否有新版本。发现新版本就全局安装(`npm install -g`)并打印通知 —— **重启 `bili` 才能生效**。
|
|
117
233
|
|
|
118
|
-
```bash
|
|
119
|
-
bili update # 立即检查并安装(手动,跳过 3 分钟节流)
|
|
120
|
-
bili --no-auto-update # 本次启动禁用自动更新
|
|
121
|
-
```
|
|
122
|
-
|
|
123
234
|
永久禁用:配置(`"autoUpdate": false`)或环境变量(`ACP_AUTO_UPDATE=0`)。
|
|
124
235
|
|
|
125
236
|
## 配置
|
|
@@ -232,40 +343,13 @@ bili --no-auto-update # 本次启动禁用自动更新
|
|
|
232
343
|
|
|
233
344
|
**API key 永远不存进代理** —— 助手发什么 key,原样透传给上游。
|
|
234
345
|
|
|
235
|
-
###
|
|
236
|
-
|
|
237
|
-
用 provider 名作为路径段把任意助手指向代理。代理剥离该名字并转发到该 provider 的根 URL。
|
|
238
|
-
|
|
239
|
-
```
|
|
240
|
-
助手 baseURL: http://localhost:8787/zhipu/api/coding/paas/v4
|
|
241
|
-
└──────────┬──────────┘└────────┬────────┘
|
|
242
|
-
代理 host 剩余路径
|
|
243
|
-
+ provider 名 (原样转发)
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
#### Claude Code(Anthropic)
|
|
247
|
-
|
|
248
|
-
```bash
|
|
249
|
-
export ANTHROPIC_BASE_URL=http://localhost:8787/anthropic
|
|
250
|
-
export ANTHROPIC_API_KEY=sk-ant-... # 真实 key —— 原样透传
|
|
251
|
-
claude
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
#### Codex / 任意 OpenAI 兼容助手(智谱 / openai / deepseek)
|
|
255
|
-
|
|
256
|
-
```bash
|
|
257
|
-
export OPENAI_BASE_URL=http://localhost:8787/zhipu/api/coding/paas/v4
|
|
258
|
-
export OPENAI_API_KEY=<你的真实智谱 key> # 原样透传
|
|
259
|
-
codex
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
`/zhipu/...` 前缀告诉代理路由到 `zhipu` provider;剩余 `/api/coding/paas/v4/...` 路径保留不变。
|
|
263
|
-
|
|
264
|
-
### Provider 名注意事项
|
|
346
|
+
### Provider 名规则
|
|
265
347
|
|
|
266
348
|
- 必须以字母开头,只含字母/数字/`-`/`_`。
|
|
267
349
|
- 保留字(`v1`、`chat`、`completions`、`messages`、`models`、`api`)被拒绝,以免与真实 API 路径段冲突。
|
|
268
350
|
- provider 名可出现在路径任意位置;最长匹配优先。
|
|
351
|
+
- **未声明任何 providers**(比如你清空了 `providers` 块)时,每个请求按完整
|
|
352
|
+
原始路径转发到默认 `upstream` —— 边缘场景,非正常流程。
|
|
269
353
|
|
|
270
354
|
## 会话机制
|
|
271
355
|
|