dsh-sub2api 0.11.1 → 0.12.1
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/CHANGELOG.md +21 -0
- package/README.en.md +181 -0
- package/README.md +16 -1
- package/assets/screenshots/models.png +0 -0
- package/docs/context-windows.html +173 -0
- package/docs/context-windows.md +81 -0
- package/lib/client.js +13 -8
- package/lib/config.js +25 -1
- package/lib/routes.js +19 -0
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
- **An English README.** The plugin list judges language by the share of CJK
|
|
6
|
+
characters, so a Chinese-only README gets flagged as "Chinese only" on the
|
|
7
|
+
detail page — which is the first thing most visitors read. `README.en.md` is
|
|
8
|
+
now the counterpart, linked from both.
|
|
9
|
+
- Screenshots are published for storefronts to surface on the detail page.
|
|
10
|
+
|
|
11
|
+
## 0.12.0
|
|
12
|
+
|
|
13
|
+
- **Works with any sub2api deployment, not just the one this plugin ships with.**
|
|
14
|
+
It always did technically — every call goes through the gateway's own API and
|
|
15
|
+
`apiBase` was configurable — but the README and the package description read
|
|
16
|
+
like a vendor plugin, which hid that from the people running their own
|
|
17
|
+
sub2api. Both now say so, and the self-hosted path is covered by tests.
|
|
18
|
+
- **An explicit empty `payBase` now means "no pay centre", and stays empty.**
|
|
19
|
+
It used to fall back to the default payment page, which would have pointed a
|
|
20
|
+
self-hosted user at a page that cannot know their account. The panel hides the
|
|
21
|
+
recharge card and the recharge routes answer with a sentence instead of
|
|
22
|
+
building a link from nothing.
|
|
23
|
+
|
|
3
24
|
## 0.11.1
|
|
4
25
|
|
|
5
26
|
- Discoverability. The package description and keywords now lead with the terms
|
package/README.en.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# dsh-sub2api
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
Connect a [sub2api](https://github.com/Wei-Shaw/sub2api) gateway to DeepSeek Harness. Install it, sign in once with an email and password, and you are done.
|
|
6
|
+
|
|
7
|
+
**One plugin, two ways to use it:**
|
|
8
|
+
|
|
9
|
+
- **The hosted Psapi gateway** — `sub.svpai.net` is the default, so installing and signing in is all there is to it.
|
|
10
|
+
- **Your own sub2api deployment** — change "gateway address" in the settings to your domain. Everything else is identical: sign-in or sign-up, key provisioning, model sync, balance, recharge, redeem codes.
|
|
11
|
+
|
|
12
|
+
> sub2api is an open-source gateway and plenty of people run their own. This
|
|
13
|
+
> plugin is not tied to any one of them: sign-in, keys, the model catalogue,
|
|
14
|
+
> balance and recharge all go through the gateway's own API, so any deployment
|
|
15
|
+
> that speaks sub2api will work.
|
|
16
|
+
|
|
17
|
+
If your deployment has no pay centre, leave the recharge address empty — balance,
|
|
18
|
+
models and keys keep working, and the recharge card simply does not appear.
|
|
19
|
+
|
|
20
|
+
After installing, open **Settings → dsh-sub2api** and enter an email and password
|
|
21
|
+
once. The rest is automatic:
|
|
22
|
+
|
|
23
|
+
- Existing account: signed in. New email: registered, without leaving DSH.
|
|
24
|
+
- A dedicated key named `dsh` is created on the account and stored in the local credential store.
|
|
25
|
+
- The upstream model catalogue is synced into the model picker — no base URL, API key or model list to type.
|
|
26
|
+
- Balance, usage, subscription, redeem codes, recharge and diagnostics live in one panel.
|
|
27
|
+
|
|
28
|
+
The first conversation needs no manual configuration. If a step did not take
|
|
29
|
+
effect, the panel's **Run diagnostics** names the exact step that failed.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
npm: dsh-sub2api https://www.npmjs.com/package/dsh-sub2api
|
|
33
|
+
repo: pscly/dsh-sub2api https://github.com/pscly/dsh-sub2api
|
|
34
|
+
install: dsh plugin add dsh-sub2api requires DSH >= 0.2.2-rc.1, then restart DSH
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
## Three steps
|
|
40
|
+
|
|
41
|
+
1. Install and restart DSH: `dsh plugin add dsh-sub2api`
|
|
42
|
+
2. Open **Settings → dsh-sub2api** and enter an email and password
|
|
43
|
+
3. Pick one of the gateway's models in the picker and start talking
|
|
44
|
+
|
|
45
|
+
No API key, no base URL, no model list to prepare — the account, the key and the
|
|
46
|
+
catalogue all become ready on their own.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## What it removes
|
|
51
|
+
|
|
52
|
+
Wiring up a gateway by hand takes four steps: get an account, create a key in the
|
|
53
|
+
dashboard, paste the key into settings, remember the model names. Any one of them
|
|
54
|
+
going wrong is where people stop.
|
|
55
|
+
|
|
56
|
+
| By hand | With this plugin |
|
|
57
|
+
|---|---|
|
|
58
|
+
| Register (sometimes in a browser) | Email and password in the panel |
|
|
59
|
+
| Create an API key and copy it | A key named `dsh` is created for you |
|
|
60
|
+
| Paste the key into settings | Written to the credential store |
|
|
61
|
+
| Type the base URL and model list | Synced from `/v1/models` |
|
|
62
|
+
| Guess what broke | **Run diagnostics** names the failing step |
|
|
63
|
+
|
|
64
|
+
## Model context windows are measured, not assumed
|
|
65
|
+
|
|
66
|
+
Most OpenAI-compatible gateways return model names from `/v1/models` with **no
|
|
67
|
+
context length at all**, so a client falls back to 128k — and a model that
|
|
68
|
+
actually takes 950k gets shown as 128k, which is what makes long sessions fail
|
|
69
|
+
with a confusing 400 from upstream.
|
|
70
|
+
|
|
71
|
+
This plugin carries measured values for 24 models, and the method is public:
|
|
72
|
+
|
|
73
|
+
- Technical write-up and the full table: [docs/context-windows.md](docs/context-windows.md) ([web version](docs/context-windows.html))
|
|
74
|
+
- The data itself: [`lib/model-registry.js`](lib/model-registry.js), every row tagged `measured` or `open`
|
|
75
|
+
- The scripts that produce it: `scripts/measure-context.mjs`, `scripts/build-model-registry.mjs`
|
|
76
|
+
|
|
77
|
+
Measurements always win over the open registry, because the open registry is
|
|
78
|
+
wrong in both directions for a real gateway — it claimed 922,000 for a model that
|
|
79
|
+
takes 524,288, and 500,000 for one that takes 131,072. Over-claiming is the
|
|
80
|
+
dangerous direction: the client compacts too late and the upstream answers 400.
|
|
81
|
+
|
|
82
|
+
## Install
|
|
83
|
+
|
|
84
|
+
### npm (recommended)
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
dsh plugin --profile web add dsh-sub2api
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### From GitHub
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
dsh plugin --profile web add github:pscly/dsh-sub2api
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
A GitHub install runs build scripts at first use, which pnpm blocks until you
|
|
97
|
+
approve them. If it stops with `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`, DSH prints
|
|
98
|
+
the exact line to add under `allowBuilds` in your profile's
|
|
99
|
+
`pnpm-workspace.yaml`; retry after adding it.
|
|
100
|
+
|
|
101
|
+
### Requirements
|
|
102
|
+
|
|
103
|
+
- DSH `>= 0.2.2-rc.1`
|
|
104
|
+
- A sub2api gateway (the hosted one, or your own)
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
Everything has a working default; you only touch this if you self-host.
|
|
109
|
+
|
|
110
|
+
| Key | Default | Meaning |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `apiBase` | `https://sub.svpai.net` | Gateway address; a trailing `/v1` is stripped |
|
|
113
|
+
| `payBase` | `https://pay.svpai.net` | Recharge page. **Empty means "no pay centre"** |
|
|
114
|
+
| `keyName` | `dsh` | Name of the API key created on the account |
|
|
115
|
+
| `visibleModels` | `[]` | Allowlist for the model picker; empty shows everything |
|
|
116
|
+
| `contextWindow` | unset | Force one window for every model |
|
|
117
|
+
| `defaultContextWindow` | `128000` | Used only when nothing else knows the real value |
|
|
118
|
+
| `retries` | `2` | Retries before the first chunk, for dropped connections and 5xx |
|
|
119
|
+
|
|
120
|
+
## Commands and tools
|
|
121
|
+
|
|
122
|
+
- `/sub2api [status|models|balance|recharge|help]`
|
|
123
|
+
- Tools exposed to the agent: connection status, model list, balance
|
|
124
|
+
|
|
125
|
+
## How it works
|
|
126
|
+
|
|
127
|
+
The plugin registers one provider route (`sub2api`) and speaks the
|
|
128
|
+
OpenAI-compatible protocol through `@dsh-ai-providers/openai-compatible`, so it
|
|
129
|
+
inherits the harness's own transport behaviour: streaming, idle timeouts, context
|
|
130
|
+
handling and reasoning efforts.
|
|
131
|
+
|
|
132
|
+
Signing in is a two-part flow against the gateway's control API: authenticate,
|
|
133
|
+
then ensure a key exists and belongs to a group. A key without a group is
|
|
134
|
+
rejected by the gateway with `API key is not assigned to any group`, so the
|
|
135
|
+
plugin treats an ungrouped key as one to replace rather than reuse — a login that
|
|
136
|
+
looks successful and fails on the first message is the worst outcome available.
|
|
137
|
+
|
|
138
|
+
Retries only happen **before the first streamed chunk**, so a partially shown
|
|
139
|
+
answer is never repeated. A dropped connection, a 5xx, a rate limit or an empty
|
|
140
|
+
response is retried; a 401, a quota rejection or a context overflow is returned
|
|
141
|
+
immediately, because asking again cannot change those answers.
|
|
142
|
+
|
|
143
|
+
## Errors you may see
|
|
144
|
+
|
|
145
|
+
### `还没有登录 dsh-sub2api`
|
|
146
|
+
|
|
147
|
+
The plugin refuses before sending anything, rather than letting a keyless request
|
|
148
|
+
come back as `401 API key is required in Authorization header` — a message about
|
|
149
|
+
credentials, for someone who simply has not signed in. Open Settings and sign in.
|
|
150
|
+
|
|
151
|
+
### `the endpoint answered 502 Bad Gateway: Upstream service temporarily unavailable`
|
|
152
|
+
|
|
153
|
+
This comes from the gateway, not the plugin: the account pool has no usable
|
|
154
|
+
upstream for that model right now. Check the gateway log:
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
docker logs --since 1h sub2api | grep account_select_failed | tail -5
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The counts in the log (`excluded`, `model_not_supported`, `runtime_blocked`) say
|
|
161
|
+
which. Retrying cannot conjure capacity, so the plugin reports it instead.
|
|
162
|
+
|
|
163
|
+
### A model shows 128k but should show more
|
|
164
|
+
|
|
165
|
+
The gateway did not report a window and the model is not in the measured table.
|
|
166
|
+
Fill it in from the panel, or run the measurement script above.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
npm install
|
|
172
|
+
node scripts/link-host.mjs # link the host packages an installed DSH provides
|
|
173
|
+
npm test
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Tests are offline: a fake gateway, a fake pay centre and a fake host, so no
|
|
177
|
+
network and no credentials are needed.
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
GPL-3.0-only. See [LICENSE](LICENSE).
|
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
# dsh-sub2api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](README.en.md) | 中文
|
|
4
|
+
|
|
5
|
+
在 DeepSeek Harness 里接入 [sub2api](https://github.com/Wei-Shaw/sub2api) 网关。装完填一次邮箱和密码就能用。
|
|
6
|
+
|
|
7
|
+
**两种用法,同一个插件:**
|
|
8
|
+
|
|
9
|
+
- **用 Psapi 公共网关** —— 默认就是 `sub.svpai.net`,装上直接登录,不用配任何东西。
|
|
10
|
+
- **用你自己部署的 sub2api** —— 在设置里把「中转站地址」改成你的域名即可,其余功能完全一样(登录注册、自动建密钥、模型同步、余额、充值、兑换码)。
|
|
11
|
+
|
|
12
|
+
> sub2api 本身是开源网关,很多人在自建。这个插件不绑定任何一家:登录、密钥、模型目录、余额和充值全部通过网关自己的接口完成,所以只要对方跑的是 sub2api,就能用。
|
|
13
|
+
|
|
14
|
+
自建时如果没部署配套的支付站,把「充值地址」留空即可 —— 余额、模型、密钥这些照常工作,只是不显示充值入口。
|
|
4
15
|
|
|
5
16
|
装完只需在 **设置 → dsh-sub2api** 填入一次邮箱和密码,其余全部自动完成:
|
|
6
17
|
|
|
@@ -291,6 +302,10 @@ Cannot switch to sub2api/...: no context capacity; configure contextWindow on th
|
|
|
291
302
|
|
|
292
303
|
## 上下文窗口从哪来
|
|
293
304
|
|
|
305
|
+
> 实测数据与测量方法整理成了独立页面:[24 个模型的上下文上限实测](docs/context-windows.md)
|
|
306
|
+
>(也可以直接看[网页版](docs/context-windows.html))
|
|
307
|
+
|
|
308
|
+
|
|
294
309
|
网关的 `/v1/models` **只返回模型 id,一个容量字段都没有**(46 个模型全是这样)。所以插件必须自己知道这些数字,
|
|
295
310
|
否则每个模型都只能按默认值显示——这也是「有些模型居然只有 128k」的原因。
|
|
296
311
|
|
|
Binary file
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>OpenAI 兼容网关的模型上下文上限怎么测(含 24 个模型实测值)</title>
|
|
7
|
+
<meta name="description" content="多数 OpenAI 兼容网关的 /v1/models 不返回上下文长度,客户端只能按 128k 兜底。这里给出不用文档、直接向服务端问出真实上限的方法,附 24 个模型在 sub2api 网关上的实测结果。">
|
|
8
|
+
<style>
|
|
9
|
+
:root {
|
|
10
|
+
--fg: #1a1d21; --muted: #5b6472; --line: rgba(0,0,0,.10);
|
|
11
|
+
--bg: #fff; --sunken: #f6f7f9; --accent: #2563eb;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-color-scheme: dark) {
|
|
14
|
+
:root { --fg:#e8eaed; --muted:#9aa3b0; --line:rgba(255,255,255,.14);
|
|
15
|
+
--bg:#14181e; --sunken:#1d222a; --accent:#5b95f7; }
|
|
16
|
+
}
|
|
17
|
+
* { box-sizing: border-box; }
|
|
18
|
+
body {
|
|
19
|
+
margin: 0; padding: 48px 20px 96px; background: var(--bg); color: var(--fg);
|
|
20
|
+
font: 16px/1.75 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
|
|
21
|
+
"Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
|
22
|
+
}
|
|
23
|
+
main { max-width: 760px; margin: 0 auto; }
|
|
24
|
+
h1 { font-size: 30px; line-height: 1.35; margin: 0 0 8px; letter-spacing: -.01em; }
|
|
25
|
+
h2 { font-size: 20px; margin: 44px 0 12px; letter-spacing: -.01em; }
|
|
26
|
+
.sub { color: var(--muted); margin: 0 0 32px; font-size: 15px; }
|
|
27
|
+
p { margin: 14px 0; }
|
|
28
|
+
a { color: var(--accent); }
|
|
29
|
+
code {
|
|
30
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
|
|
31
|
+
background: var(--sunken); padding: .15em .4em; border-radius: 5px;
|
|
32
|
+
}
|
|
33
|
+
pre {
|
|
34
|
+
background: var(--sunken); padding: 14px 16px; border-radius: 10px;
|
|
35
|
+
overflow: auto; font-size: 13.5px; line-height: 1.6;
|
|
36
|
+
border: .5px solid var(--line);
|
|
37
|
+
}
|
|
38
|
+
pre code { background: none; padding: 0; }
|
|
39
|
+
table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 14.5px; }
|
|
40
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: .5px solid var(--line); }
|
|
41
|
+
th { font-weight: 600; color: var(--muted); font-size: 13px; letter-spacing: .02em; }
|
|
42
|
+
td:last-child, th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
|
|
43
|
+
.note {
|
|
44
|
+
border-left: 3px solid var(--accent); background: var(--sunken);
|
|
45
|
+
padding: 12px 16px; border-radius: 0 8px 8px 0; margin: 20px 0;
|
|
46
|
+
}
|
|
47
|
+
.foot { margin-top: 56px; padding-top: 20px; border-top: .5px solid var(--line);
|
|
48
|
+
color: var(--muted); font-size: 13.5px; }
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<main>
|
|
53
|
+
|
|
54
|
+
<h1>模型菜单显示 128k,不代表模型只有 128k</h1>
|
|
55
|
+
<p class="sub">一份不用查文档、直接向服务端问出真实上下文上限的方法,附 24 个模型实测值</p>
|
|
56
|
+
|
|
57
|
+
<p>如果你在用 DeepSeek Harness、Cherry Studio、LobeChat 或者任何接入 OpenAI 兼容
|
|
58
|
+
网关的客户端,可能遇到过这种情况:所有模型的上下文都显示 128k,包括那些明明是
|
|
59
|
+
100 万上下文的模型。</p>
|
|
60
|
+
|
|
61
|
+
<p>原因不在客户端。多数网关的 <code>/v1/models</code> <strong>只返回模型名,一个容量字段
|
|
62
|
+
都没有</strong>。客户端拿不到数字,只能按默认值兜底——128k 就是这么来的。</p>
|
|
63
|
+
|
|
64
|
+
<h2>不用文档,直接问服务端</h2>
|
|
65
|
+
|
|
66
|
+
<p>服务端其实会告诉你答案,只是不在模型列表里,而在<strong>报错</strong>里。</p>
|
|
67
|
+
|
|
68
|
+
<p>发一个超过上限的 prompt,请求会在<strong>生成之前</strong>被拒绝,错误信息里带着真实上限:</p>
|
|
69
|
+
|
|
70
|
+
<pre><code>POST /v1/chat/completions
|
|
71
|
+
{
|
|
72
|
+
"model": "deepseek-flash",
|
|
73
|
+
"messages": [{"role": "user", "content": "a a a ... (110 万个词)"}],
|
|
74
|
+
"max_tokens": 1
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
→ 400
|
|
78
|
+
This model's maximum context length is 1048576 tokens;
|
|
79
|
+
the prompt has 1100031 tokens</code></pre>
|
|
80
|
+
|
|
81
|
+
<div class="note">
|
|
82
|
+
<strong>被拒绝的请求不计费。</strong>计费发生在生成阶段,而在那之前就被拒了。
|
|
83
|
+
这一整轮 56 个模型测下来,花了不到 1 元人民币。
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<h2>不报数字的模型怎么办</h2>
|
|
87
|
+
|
|
88
|
+
<p>有些模型只说 <code>Your input exceeds the context window of this model</code>,
|
|
89
|
+
不给具体数字。这种情况用二分法:从一个已知能过的大小开始,翻倍直到被拒,
|
|
90
|
+
然后在「能过」和「过不了」之间二分。</p>
|
|
91
|
+
|
|
92
|
+
<p>取<strong>被拒绝的最小值</strong>作为上限。这个值永远不会高估——而高估是危险的方向:
|
|
93
|
+
客户端会等到上下文远超真实上限才做压缩,然后收到上游的 400,用户看到的就是
|
|
94
|
+
一条莫名其妙的失败。</p>
|
|
95
|
+
|
|
96
|
+
<h2>实测结果</h2>
|
|
97
|
+
|
|
98
|
+
<p>以下是 2026-11 在一个自建 sub2api 网关上的实测值。<code>measured</code> 是实测,
|
|
99
|
+
不是从任何文档抄的。</p>
|
|
100
|
+
|
|
101
|
+
<table>
|
|
102
|
+
<thead><tr><th>模型</th><th>上下文上限</th></tr></thead>
|
|
103
|
+
<tbody>
|
|
104
|
+
<tr><td><code>muse-image</code></td><td>2,097,152</td></tr>
|
|
105
|
+
<tr><td><code>muse-spark</code></td><td>2,097,152</td></tr>
|
|
106
|
+
<tr><td><code>deepseek-flash</code></td><td>1,048,576</td></tr>
|
|
107
|
+
<tr><td><code>deepseek-pro</code></td><td>1,048,576</td></tr>
|
|
108
|
+
<tr><td><code>deepseek-v4-pro</code></td><td>1,048,576</td></tr>
|
|
109
|
+
<tr><td><code>deepseek-v4.1-flash</code></td><td>1,048,576</td></tr>
|
|
110
|
+
<tr><td><code>glm-5.3</code></td><td>1,048,576</td></tr>
|
|
111
|
+
<tr><td><code>qwen3.8-max</code></td><td>1,015,808</td></tr>
|
|
112
|
+
<tr><td><code>codex-auto-review</code></td><td>950,272</td></tr>
|
|
113
|
+
<tr><td><code>gpt-5.6-luna</code></td><td>950,272</td></tr>
|
|
114
|
+
<tr><td><code>gpt-5.6-sol</code></td><td>950,272</td></tr>
|
|
115
|
+
<tr><td><code>gpt-6-sol</code></td><td>950,272</td></tr>
|
|
116
|
+
<tr><td><code>gpt-6.1-sol</code></td><td>950,272</td></tr>
|
|
117
|
+
<tr><td><code>gpt-6.2-sol</code></td><td>950,272</td></tr>
|
|
118
|
+
<tr><td><code>gpt-reserve</code></td><td>950,272</td></tr>
|
|
119
|
+
<tr><td><code>gpt-6.2-astra</code></td><td>524,288</td></tr>
|
|
120
|
+
<tr><td><code>muse-video</code></td><td>262,144</td></tr>
|
|
121
|
+
<tr><td><code>grok-4.7</code></td><td>131,072</td></tr>
|
|
122
|
+
</tbody>
|
|
123
|
+
</table>
|
|
124
|
+
|
|
125
|
+
<div class="note">
|
|
126
|
+
<strong>同代模型可能差一倍。</strong> <code>gpt-6.2-astra</code> 是 524,288,
|
|
127
|
+
而同代的 <code>gpt-6.2-sol</code> 是 950,272。按模型名里的版本号猜家族值,
|
|
128
|
+
一定会猜错。
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<h2>开源的容量表也不能全信</h2>
|
|
132
|
+
|
|
133
|
+
<p>拿 LiteLLM 的公开注册表(7,194 条)和我实测的值逐条对照,它对不上的比例不低,
|
|
134
|
+
而且<strong>偏高</strong>的次数更多:</p>
|
|
135
|
+
|
|
136
|
+
<table>
|
|
137
|
+
<thead><tr><th>模型</th><th>实测</th><th>开源表</th><th>偏差</th></tr></thead>
|
|
138
|
+
<tbody>
|
|
139
|
+
<tr><td><code>gpt-6.2-astra</code></td><td>524,288</td><td>922,000</td><td>+397,712</td></tr>
|
|
140
|
+
<tr><td><code>grok-4.7</code></td><td>131,072</td><td>500,000</td><td>+368,928</td></tr>
|
|
141
|
+
<tr><td><code>gpt-6-sol</code></td><td>950,272</td><td>922,000</td><td>−28,272</td></tr>
|
|
142
|
+
<tr><td><code>deepseek-flash</code></td><td>1,048,576</td><td>1,000,000</td><td>−48,576</td></tr>
|
|
143
|
+
</tbody>
|
|
144
|
+
</table>
|
|
145
|
+
|
|
146
|
+
<p>所以正确的顺序是:<strong>能实测就实测,实测不到才用开源表兜底</strong>,
|
|
147
|
+
并且要标明哪个是哪个。</p>
|
|
148
|
+
|
|
149
|
+
<h2>现成的实现</h2>
|
|
150
|
+
|
|
151
|
+
<p>如果你在用 DeepSeek Harness,这个插件已经把上面整套做完了,装上即用:</p>
|
|
152
|
+
|
|
153
|
+
<pre><code>dsh plugin add dsh-sub2api</code></pre>
|
|
154
|
+
|
|
155
|
+
<p>它会在设置页让你用邮箱和密码登录 sub2api 网关,自动建密钥、同步模型目录,
|
|
156
|
+
并从表里读上下文容量——不会把 95 万上下文的模型显示成 128k。装完默认模型就已经
|
|
157
|
+
指向可用模型,选择器不会是空的。</p>
|
|
158
|
+
|
|
159
|
+
<p>实测脚本也在仓库里,可以对着你自己的网关跑一遍:</p>
|
|
160
|
+
|
|
161
|
+
<pre><code>node scripts/measure-context.mjs --key sk-... --out /tmp/ctx.json
|
|
162
|
+
node scripts/build-model-registry.mjs /tmp/ctx.json</code></pre>
|
|
163
|
+
|
|
164
|
+
<p>仓库:<a href="https://github.com/pscly/dsh-sub2api">github.com/pscly/dsh-sub2api</a></p>
|
|
165
|
+
|
|
166
|
+
<div class="foot">
|
|
167
|
+
数据采集时间:2026 年 11 月 · 网关 <code>sub.svpai.net</code> ·
|
|
168
|
+
所有数值来自被拒绝的请求,未产生生成计费
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
</main>
|
|
172
|
+
</body>
|
|
173
|
+
</html>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# 24 个模型的上下文上限实测(DeepSeek Harness / sub2api 网关)
|
|
2
|
+
|
|
3
|
+
模型菜单里显示 128k,不代表模型只有 128k。多数 OpenAI 兼容网关的 `/v1/models`
|
|
4
|
+
只返回模型名,**一个容量字段都没有**,客户端只能按默认值兜底,于是所有模型都被
|
|
5
|
+
显示成 128k。
|
|
6
|
+
|
|
7
|
+
这份数据是实测的,不是抄文档的。
|
|
8
|
+
|
|
9
|
+
## 怎么测的
|
|
10
|
+
|
|
11
|
+
给模型发一个超过它上限的 prompt,服务端会在**生成之前**拒绝,并在错误信息里报出
|
|
12
|
+
真实上限:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
This model's maximum context length is 1048576 tokens;
|
|
16
|
+
the prompt has 1100031 tokens
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
不报数字的模型(比如 gpt 系列只说 `Your input exceeds the context window`),就用
|
|
20
|
+
二分法在「能过」和「过不了」之间逼近,取被拒绝的最小值——**这个值永远不会高估**。
|
|
21
|
+
|
|
22
|
+
被拒绝的请求不计费。整轮 56 个模型测下来花了不到 1 元,其中 24 个报出了明确数字。
|
|
23
|
+
|
|
24
|
+
## 实测结果(24 个模型)
|
|
25
|
+
|
|
26
|
+
| 模型 | 上下文上限 |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `muse-image` | 2,097,152 |
|
|
29
|
+
| `muse-spark` | 2,097,152 |
|
|
30
|
+
| `deepseek-flash` | 1,048,576 |
|
|
31
|
+
| `deepseek-pro` | 1,048,576 |
|
|
32
|
+
| `deepseek-v4-pro` | 1,048,576 |
|
|
33
|
+
| `deepseek-v4.1-flash` | 1,048,576 |
|
|
34
|
+
| `deepseek/deepseek-v4-pro` | 1,048,576 |
|
|
35
|
+
| `deepseek/deepseek-v4.1-flash` | 1,048,576 |
|
|
36
|
+
| `glm-5.3` | 1,048,576 |
|
|
37
|
+
| `qwen3.8-max` | 1,015,808 |
|
|
38
|
+
| `codex-auto-review` | 950,272 |
|
|
39
|
+
| `gpt-5.6-luna` | 950,272 |
|
|
40
|
+
| `gpt-5.6-sol` | 950,272 |
|
|
41
|
+
| `gpt-5.6-terra` | 950,272 |
|
|
42
|
+
| `gpt-6-astra` | 950,272 |
|
|
43
|
+
| `gpt-6-luna` | 950,272 |
|
|
44
|
+
| `gpt-6-sol` | 950,272 |
|
|
45
|
+
| `gpt-6.1-sol` | 950,272 |
|
|
46
|
+
| `gpt-6.1-terra` | 950,272 |
|
|
47
|
+
| `gpt-6.2-sol` | 950,272 |
|
|
48
|
+
| `gpt-reserve` | 950,272 |
|
|
49
|
+
| `gpt-6.2-astra` | 524,288 |
|
|
50
|
+
| `muse-video` | 262,144 |
|
|
51
|
+
| `grok-4.7` | 131,072 |
|
|
52
|
+
|
|
53
|
+
## 两个值得注意的地方
|
|
54
|
+
|
|
55
|
+
**同代模型容量可能差一倍。** `gpt-6.2-astra` 是 524,288,而同代的 `gpt-6.2-sol`
|
|
56
|
+
是 950,272。按前缀猜家族值一定会出错。
|
|
57
|
+
|
|
58
|
+
**开源的容量表在这个网关上不准。** 拿 LiteLLM 的公开注册表(7,194 条)对照,
|
|
59
|
+
它给 `gpt-6.2-astra` 写的是 922,000(实际 524,288),给 `grok-4.7` 写的是
|
|
60
|
+
500,000(实际 131,072)——**都是高估**。高估是最危险的方向:客户端会等到上下文
|
|
61
|
+
远超真实上限才压缩,然后收到上游的 400。
|
|
62
|
+
|
|
63
|
+
## 怎么用
|
|
64
|
+
|
|
65
|
+
如果你在用 DeepSeek Harness,装这个插件后容量直接从表里读,不用自己填:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
dsh plugin add dsh-sub2api
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
数据在 [`lib/model-registry.js`](../lib/model-registry.js),每条都标了来源
|
|
72
|
+
(`measured` = 实测,`open` = 开源注册表)。仓库里带了复现脚本:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
node scripts/measure-context.mjs --key sk-... --out /tmp/ctx.json
|
|
76
|
+
node scripts/build-model-registry.mjs /tmp/ctx.json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
数据采集:2026-11 / 网关 `sub.svpai.net` / 未计费拒绝请求
|
package/lib/client.js
CHANGED
|
@@ -1506,14 +1506,19 @@ window.__ModuleLoader__.load({
|
|
|
1506
1506
|
onGoRecharge: () => { setOpen((prev) => ({ ...prev, recharge: true })); },
|
|
1507
1507
|
})),
|
|
1508
1508
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1509
|
+
// A gateway with no pay centre has nothing to recharge here, and an
|
|
1510
|
+
// entry that always fails is worse than no entry. `canRecharge` is the
|
|
1511
|
+
// host's answer to "did anyone configure one".
|
|
1512
|
+
state.canRecharge === false
|
|
1513
|
+
? null
|
|
1514
|
+
: h(Collapsible, {
|
|
1515
|
+
id: "sub2api-recharge",
|
|
1516
|
+
title: "充值",
|
|
1517
|
+
meta: Number.isFinite(balance) ? `余额 ${money(balance)}` : null,
|
|
1518
|
+
open: open.recharge,
|
|
1519
|
+
onToggle: () => toggle("recharge"),
|
|
1520
|
+
},
|
|
1521
|
+
h(RechargeDetail, { state, pending, onRecharge, onPoll, onRefresh, onRedeem })),
|
|
1517
1522
|
|
|
1518
1523
|
h(Collapsible, {
|
|
1519
1524
|
title: "API 密钥",
|
package/lib/config.js
CHANGED
|
@@ -89,13 +89,37 @@ function followMovedHost(url) {
|
|
|
89
89
|
return parsed.toString().replace(/\/+$/, "");
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Where the recharge page lives, with "explicitly none" respected.
|
|
94
|
+
*
|
|
95
|
+
* Absent means "use the gateway this plugin ships for"; empty means "there is
|
|
96
|
+
* no pay centre here". Those are different answers and the panel shows a
|
|
97
|
+
* different thing for each.
|
|
98
|
+
* @param {any} config raw or volatile configuration
|
|
99
|
+
* @returns {string}
|
|
100
|
+
*/
|
|
101
|
+
function resolvePayBase(config) {
|
|
102
|
+
// Read the raw value, not through `field`: that helper treats "" as "absent",
|
|
103
|
+
// which is exactly the distinction being made here.
|
|
104
|
+
let raw = config?.["payBase"];
|
|
105
|
+
if (raw !== null && typeof raw === "object" && typeof raw.get === "function") raw = raw.get();
|
|
106
|
+
if (raw === undefined || raw === null) return "https://pay.svpai.net";
|
|
107
|
+
const text = String(raw).trim();
|
|
108
|
+
if (text === "") return "";
|
|
109
|
+
return followMovedHost(normalizeBaseUrl(text));
|
|
110
|
+
}
|
|
111
|
+
|
|
92
112
|
export function resolveConfig(config) {
|
|
93
113
|
const dshHome = process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
94
114
|
const configuredKeyName = String(field(config, "keyName", "")).trim();
|
|
95
115
|
|
|
96
116
|
return {
|
|
97
117
|
apiBase: followMovedHost(normalizeBaseUrl(field(config, "apiBase", "https://sub.svpai.net"))),
|
|
98
|
-
payBase
|
|
118
|
+
// An explicitly empty payBase means "this gateway has no pay centre", and
|
|
119
|
+
// must stay empty. Falling back to the default here would point a
|
|
120
|
+
// self-hosted user at a payment page that cannot possibly know their
|
|
121
|
+
// account, which is worse than showing no recharge button at all.
|
|
122
|
+
payBase: resolvePayBase(config),
|
|
99
123
|
apiKeyEnv: String(field(config, "apiKeyEnv", API_KEY_REF)),
|
|
100
124
|
groupId: toPositiveInt(field(config, "groupId", undefined)),
|
|
101
125
|
keyName: configuredKeyName === "" ? KEY_NAME : configuredKeyName,
|
package/lib/routes.js
CHANGED
|
@@ -100,6 +100,7 @@ export function makeRoutes(deps) {
|
|
|
100
100
|
const view = {
|
|
101
101
|
apiBase: cfg().apiBase,
|
|
102
102
|
payBase: cfg().payBase,
|
|
103
|
+
canRecharge: typeof cfg().payBase === "string" && cfg().payBase !== "",
|
|
103
104
|
keyName: cfg().keyName,
|
|
104
105
|
loggedIn: stored !== undefined,
|
|
105
106
|
email: stored?.email ?? stored?.user?.email ?? null,
|
|
@@ -131,6 +132,22 @@ export function makeRoutes(deps) {
|
|
|
131
132
|
return view;
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/**
|
|
136
|
+
* A gateway without a pay centre cannot recharge. Saying so is the honest
|
|
137
|
+
* answer; building a URL from an empty base produces a broken link to whatever
|
|
138
|
+
* host happens to parse it.
|
|
139
|
+
* @returns {string} the pay centre base
|
|
140
|
+
*/
|
|
141
|
+
function requirePayBase() {
|
|
142
|
+
const base = cfg().payBase;
|
|
143
|
+
if (typeof base !== "string" || base === "") {
|
|
144
|
+
throw new Sub2ApiError("这个网关没有配置充值站点,无法在线充值;请联系站点管理员", {
|
|
145
|
+
code: "no_pay_center",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return base;
|
|
149
|
+
}
|
|
150
|
+
|
|
134
151
|
return [
|
|
135
152
|
defineRoute("GET", `${ROUTE_PREFIX}/status`, async () => status()),
|
|
136
153
|
|
|
@@ -451,6 +468,7 @@ export function makeRoutes(deps) {
|
|
|
451
468
|
|
|
452
469
|
/** Recharge level 1: a signed-in URL the browser opens in a new tab. */
|
|
453
470
|
defineRoute("POST", `${ROUTE_PREFIX}/recharge/link`, async (body) => {
|
|
471
|
+
requirePayBase();
|
|
454
472
|
const stored = await session.read();
|
|
455
473
|
const token = await session.accessToken();
|
|
456
474
|
const userId = stored?.user?.id;
|
|
@@ -470,6 +488,7 @@ export function makeRoutes(deps) {
|
|
|
470
488
|
|
|
471
489
|
/** Recharge level 2: choose the amount here and land straight on checkout. */
|
|
472
490
|
defineRoute("POST", `${ROUTE_PREFIX}/recharge`, async (body) => {
|
|
491
|
+
requirePayBase();
|
|
473
492
|
const stored = await session.read();
|
|
474
493
|
const token = await session.accessToken();
|
|
475
494
|
const userId = stored?.user?.id;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Sub2API
|
|
3
|
+
"version": "0.12.1",
|
|
4
|
+
"description": "Sub2API provider for DeepSeek Harness (DSH): email sign-in, automatic API key and model provisioning, one panel for balance and recharge. Works with the hosted gateway or your own sub2api deployment",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
7
7
|
"main": "./lib/index.js",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
"README.md",
|
|
17
17
|
"assets",
|
|
18
18
|
"cordis.patch.yml",
|
|
19
|
-
"lib"
|
|
19
|
+
"lib",
|
|
20
|
+
"README.en.md",
|
|
21
|
+
"docs"
|
|
20
22
|
],
|
|
21
23
|
"dsh": {
|
|
22
24
|
"bundle": {
|