dsh-cost-meter 1.9.0 → 1.9.2

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.
@@ -0,0 +1,68 @@
1
+ # 自定义余额:随机端口、局域网与 WorkBuddy2API
2
+
3
+ ## 跟随 DSH 随机端口
4
+
5
+ 在 **设置 → 费用 → 额度 → 自定义 Provider 余额** 中,请求 URL 可以填写以单个 `/` 开头的路径:
6
+
7
+ ```json
8
+ {
9
+ "enabled": true,
10
+ "label": "WorkBuddy 积分",
11
+ "unit": "CREDITS",
12
+ "request": { "url": "/plugins/dsh-workbuddy-connect/status" },
13
+ "extract": { "remaining": "credits.total" }
14
+ }
15
+ ```
16
+
17
+ 插件在查询时读取 DSH `webServer.port`,访问当前宿主的本机 HTTP 服务。端口改变后旧余额缓存失效,配置仍保存相对路径。服务尚未监听时提示稍后重试;不会扫描端口、改写账本中的 URL,或把浏览器提供的 origin 当作查询目标。`//host/path`、反斜杠和带凭据的 URL 不被接受,重定向不会被跟随。
18
+
19
+ `dsh-workbuddy-connect` 的状态路由与独立部署的 WorkBuddy2API 是两种来源。只有宿主内注册的路由使用相对路径;独立服务填写其实际 URL。
20
+
21
+ ## 局域网 HTTP
22
+
23
+ HTTPS 和本机回环 HTTP 继续可用。访问 `http://192.168.1.20:8790` 等非回环地址时,在同一条余额配置中:
24
+
25
+ 1. 在凭据白名单填写准确的 `192.168.1.20:8790`。
26
+ 2. 勾选“允许非回环 HTTP”。
27
+
28
+ 这对应 `allowedHosts: ["192.168.1.20:8790"]` 和 `allowInsecureHttp: true`。两个条件缺一不可;白名单按准确的主机和端口匹配,不接受 `192.168.*.*`。HTTP 会明文传输请求头中的凭据,开关默认关闭。已有 CLIProxyAPI 网关配置仍使用其原有的同名开关和白名单。
29
+
30
+ ## WorkBuddy2API 积分预设
31
+
32
+ 点击 **+ WorkBuddy2API 积分**,会创建一条默认关闭的可编辑配置:
33
+
34
+ ```json
35
+ {
36
+ "label": "WorkBuddy2API 积分",
37
+ "unit": "CREDITS",
38
+ "refreshMinutes": 15,
39
+ "request": {
40
+ "url": "http://127.0.0.1:8790/api/credits/expiry?package_limit=1",
41
+ "method": "GET",
42
+ "headers": { "X-Admin-Token": "{{WORKBUDDY2API_ADMIN_TOKEN}}" }
43
+ },
44
+ "extract": { "remaining": "summary.available_remaining" },
45
+ "allowedHosts": ["127.0.0.1:8790"],
46
+ "allowInsecureHttp": false
47
+ }
48
+ ```
49
+
50
+ 填入实际地址和端口,在凭据输入框保存 WorkBuddy2API 管理后台的 **X-Admin-Token**,再启用卡片。该令牌与模型推理 API Key 不同;过期后需要更新。密钥通过 DSH 凭据库保存,不写入上述配置。修改服务地址时同步修改白名单。
51
+
52
+ 显示的是**活跃账号池的可用积分**,不与美元费用换算,也不把仅覆盖部分账号的到期快照 `summary.total_remaining` 当成全部余额。没有可信的总额度就不编造进度条上限。查询只读取服务器已有统计,不发模型请求、不触发账号积分刷新任务。`package_limit=1` 缩小不需要的积分包明细;插件只保留提取后的数字。
53
+
54
+ 上游契约核对于 2026-10-18,commit `02f82cdf3282475ce3c1e87f01afdc044636f549`:
55
+
56
+ - [积分路由和汇总字段](https://github.com/xiaofan6ya/workbuddy2api/blob/02f82cdf3282475ce3c1e87f01afdc044636f549/admin/routers/credits.py)
57
+ - [X-Admin-Token 鉴权](https://github.com/xiaofan6ya/workbuddy2api/blob/02f82cdf3282475ce3c1e87f01afdc044636f549/admin/security.py)
58
+ - [默认监听端口](https://github.com/xiaofan6ya/workbuddy2api/blob/02f82cdf3282475ce3c1e87f01afdc044636f549/admin/config.py)
59
+
60
+ 本轮验证包括真实本地 HTTP 服务的随机端口切换、配置往返和合成 WorkBuddy2API 响应;未连接用户的真实 WorkBuddy2API 账号。
61
+
62
+ 贡献来源:@Jav1es 在 [#311](https://github.com/Han-1413141/dsh-cost-meter/issues/311) 提供随机端口复现及相对路径建议;@snhun 在 [#309](https://github.com/Han-1413141/dsh-cost-meter/issues/309) 提出局域网 HTTP 需求,在 [#310](https://github.com/Han-1413141/dsh-cost-meter/issues/310) 提出 WorkBuddy2API 接入需求。
63
+
64
+ ## English setup
65
+
66
+ Root-relative URLs such as `/plugins/dsh-workbuddy-connect/status` follow the running DSH web server's actual port. Independent WorkBuddy2API deployments use an absolute URL. Non-loopback HTTP requires both `allowInsecureHttp: true` and an exact `host:port` in `allowedHosts`; this explicitly permits plaintext transport. Redirects remain blocked.
67
+
68
+ The **+ WorkBuddy2API credits** preset reads `GET /api/credits/expiry?package_limit=1` with an admin `X-Admin-Token` stored as `WORKBUDDY2API_ADMIN_TOKEN` in DSH credentials. Set the real server address and matching allowlist, update expired admin tokens, then enable the card. The displayed `summary.available_remaining` is the active account pool's available credits, not currency, a single model API key's allowance, or the incomplete expiry snapshot total. No model request or upstream credit-refresh task is triggered. Authentication was tested with synthetic responses, not a live account.
@@ -1,103 +1,93 @@
1
- # OpenDesign billing and quota / 计费与额度
2
-
3
- ## English
4
-
5
- This release addresses [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274), requested by @playgithub. It adds an OpenDesign price channel and read-only workspace quota queries; it is included in version 1.8.27. It does not install OpenDesign, create an account or change a model route.
6
-
7
- The quota query also implements the Bearer-only fallback discovered by @yunjuanhuakai in the [#274 follow-up comments](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566): on accounts whose usage route rejects a Control Key, the plugin retries the `billing/preflight` endpoint with the same credential. @codeforker654's [401 report](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) is the reproduction behind the fallback.
8
-
9
- ### Conversation costs
10
-
11
- - The offline catalog contains 35 token-priced models checked on **2026-10-15**, from the [official public API](https://amr-api.open-design.ai/api/v1/public/model-prices). Prices are **USD per 1M tokens**, with cache read/write rates and long-context tiers where provided. The long tier applies to the entire request only above its input threshold, including cached input.
12
- - Provider IDs `opendesign`, `open-design`, `open-design-api` and `amr-link.open-design.ai`, including DSH's `llm-` prefix, use this separate catalog. A custom price under the original alias takes priority. Other provider IDs can use the existing explicit price mapping and plan-assignment controls.
13
- - OpenDesign prices never serve as fallback prices for another provider. Unknown OpenDesign models stay unpriced; the plugin does not borrow a direct-vendor price.
14
- - **Settings → Cost → Prices → Sync official prices** also refreshes the public OpenDesign catalog. A used/enabled OpenDesign channel refreshes at startup and hourly. No key or model request is needed. User-edited prices and removed models stay intact. Saved price versions preserve existing details when rates change; recalculation is explicit and retains the original amounts. A historical price version that was never captured cannot be reconstructed.
15
-
16
- OpenDesign uses shared subscription allowances and can fall back to its wallet; see its [model-credit rules](https://open-design.ai/model-credits/). Calls default to **Plan-equivalent cost**, which is not a subscription payment or a cash bill. Set wallet-funded calls to **API** in the billing-classification controls, or assign individual models explicitly. DSH's standard usage response does not identify each request's funding source, account-specific discount, image charge or automatic top-up. Those amounts are not invented from the list price or balance movement.
17
-
18
- ### Quota queries
19
-
20
- 1. Open **Settings → Cost → Quotas**, find **OpenDesign**, and expand its settings.
21
- 2. Enter the exact **workspace ID** from your OpenDesign Cloud workspace.
22
- 3. Configure a **Control Key** in the credential editor, or supply `OPENDESIGN_CONTROL_KEY` / `VELA_CONTROL_KEY` to the DSH host. An inference key from the Cloud API Keys page is a different credential and cannot be used for this query. The existing OpenDesign/Vela login keeps control credentials in its own profile; the plugin does not read or rewrite that profile automatically.
23
- 4. Enable the card and refresh. Select its location to also show it in the sidebar or quota strip.
24
-
25
- The host issues only these authenticated GET requests to the fixed official HTTPS origin:
26
-
27
- ```text
28
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/coding-plan-usage # primary window query
29
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # Bearer-only fallback, only after a 401/403
30
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # wallet, read independently
31
- ```
32
-
33
- #### Endpoint permissions, Bearer-only fallback and 401 troubleshooting
34
-
35
- - The usage endpoint is not always scoped to a Control Key: for some plans/accounts it only accepts a **browser session cookie**, so a Control Key can return `401`/`403` for `billing/coding-plan-usage` while `/billing/preflight`, `/wallet/balance` and other API endpoints still answer `200` with the same key. The plugin never sends a browser cookie. It first queries the usage route with `Authorization: Bearer ...`; when that route answers `401`/`403`, it retries `billing/preflight` once with the same header. `preflight` returns the identical window packet nested under `codingPlan`, so the same parser and percentage rules apply.
36
- - A `200`, a malformed body or any other HTTP status on the primary route never triggers the fallback. The wallet route is read independently and in parallel: when only one side is rejected, the other value is still displayed, the rejected side is omitted rather than fabricated as zero, and its cause (credential rejected / no subscription / invalid response / network) is kept in the refresh trace. Only when both sides fail does the card show an error state.
37
- - A successful fallback keeps the standard `{ windows, endpoint }` answer, with `endpoint` naming the route that actually answered. A fallback response that is itself rejected, malformed or unreachable is reported as the window side's failure cause, not as a wallet failure.
38
- - `preflight` also carries `workspaceMemberId` and `balanceUsd`. The member is checked against the wallet member; `balanceUsd` is only used as the displayed balance when `/wallet/balance` cannot be read, and never adds to or replaces a readable wallet value.
39
- - The workspace ID must be the `workspaceId` field of `items[]` from `GET https://amr-api.open-design.ai/api/v1/workspaces`. It is **not** `profiles.prod.user.id` from `~/.amr/config.json`: that user id authenticates but scopes the request to the wrong resource, and the server replies `403 workspace_billing_scope_forbidden`.
40
- - Troubleshooting a `401`/`403` on the quota endpoint:
41
- 1. Confirm the stored credential is a **Control Key**, not an inference API key from the Cloud API Keys page.
42
- 2. Call `GET /api/v1/workspaces` with the same credential and copy the exact `items[].workspaceId`.
43
- 3. If `/workspaces` succeeds but `/billing/coding-plan-usage` returns `401`/`403`, the automatic `preflight` fallback normally covers this account and needs no browser session. If `preflight` also returns `401`/`403` for the same key, that account does not expose a Control-Key window read; log in to the OpenDesign Cloud console to check usage there. The wallet endpoint may still be readable, and is shown on its own.
44
- 4. Verify the key and workspace belong to the same account and that the key was not rotated or revoked.
45
-
46
- Quota and wallet responses must match the requested workspace. The wallet must identify its member; if the quota response provides a member identity, both must match. A preflight response that omits the redundant outer `workspaceId` is accepted only after the requested workspace has scoped the request; a body naming a different workspace is rejected. Credentials are never forwarded through a redirect and no cookie is attached. They use the existing DSH credential store and are excluded from the ledger and client snapshot.
47
-
48
- Each returned allowance window has its own used percentage and reset time. Simultaneous windows are not added together or called unlimited. Wallet credit remains a separate USD-equivalent value, including a real zero. Quota and wallet are fetched independently, so a failure on one side keeps the other side visible; an `eligible: false` / empty-window answer (from the primary route or the fallback) is reported as **no active subscription** instead of a credential failure. Invalid, unauthorized or missing responses never fabricate a zero allowance; when both sides fail, the card shows an error/unavailable state. The workspace setting is kept across restarts and invalidates the previous query when changed.
49
-
50
- ### Evidence and limits
51
-
52
- The public catalog was fetched without authentication. The authenticated adapter, the Bearer-only `billing/preflight` fallback and bilingual settings were verified with synthetic responses, including large credit counts, zero balances, mismatched identities, authorization failures on either side, a preflight-shaped `codingPlan` body, and price-refresh persistence. **No live account query or paid model request was made.** Production Control Key permissions and response availability still require a configured account.
53
-
54
- Endpoint provenance: the official Cloud bundles `cloud-root-B21Emo2w.js` and `pricing-refund-policy-BDFJHl33.js` served on 2026-10-15; the [workspace-wallet contract](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts) and [Vela billing adapter](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts) at the inspected commit. The exact `billing/preflight` shape (`codingPlan`-nested windows, `workspaceMemberId`, `balanceUsd`) comes from @yunjuanhuakai's [#274 comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566); the 401 reproduction and attached report come from @codeforker654's [comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870). The [official guide](https://open-design.ai/zh/model-credits/) explicitly lists DSH as a supported API client; the issue has a usable integration request. Its short promotional wording alone does not establish advertising or spam.
55
-
56
- ## 中文
57
-
58
- 本版本实现了 @playgithub 在 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274) 提出的接入需求,随 1.8.27 发布。同时落实 #274 后续评论中 @yunjuanhuakai 发现的纯 Bearer 回退端点([评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566)),并以 @codeforker654 的 [401 复现报告](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) 为验证案例。不会安装 OpenDesign、注册账户或改变模型路由。
59
-
60
- ### 会话计费
61
-
62
- - 从[官方公开价表](https://amr-api.open-design.ai/api/v1/public/model-prices)加入 **35 个模型**,核对日期为 **2026-10-15**。单位为 **美元/百万 Token**,包含已公布的缓存读取、缓存写入和长上下文价格。超过输入阈值后,整次请求使用长档,输入阈值包含缓存输入。
63
- - `opendesign`、`open-design`、`open-design-api`、`amr-link.open-design.ai` 及其 `llm-` 前缀使用独立目录;原渠道中手工配置的价格优先。其他自定义名称可通过既有价格映射和套餐归属入口关联。
64
- - 未收录的 OpenDesign 模型标为未定价,不借用直连厂商价格;其他渠道也不会使用 OpenDesign 价作为兜底。
65
- - **设置 → 费用 → 价格 → 同步官方价格**会同步公开目录。已使用或开启 OpenDesign 时,启动和每小时也会刷新;不需要密钥,不调用模型。自定义价格、取消挂载和已保存价格版本的历史明细保留。历史重算需要主动确认并保留原金额;未保存过的历史价格版本无法还原。
66
-
67
- OpenDesign 的 API 与客户端共用套餐,套餐用尽后可以继续扣钱包,详见[官方额度规则](https://open-design.ai/zh/model-credits/)。因此默认计入 **Plan 等值费用**,不把额度当成现金支出。钱包付款可在计费分类中设为 **API**,也可逐模型配置。DSH 的标准用量回执没有逐次扣款来源、账户折扣、图片费用或自动充值金额,这些金额不会通过公开单价或余额变化猜算。
68
-
69
- ### 额度查询
70
-
71
- 1. 在 **设置 → 费用 → 额度**找到并展开 **OpenDesign**。
72
- 2. 填入 OpenDesign Cloud 中对应的**工作区 ID**。
73
- 3. 在凭据编辑器中配置 **Control Key**,或向 DSH 宿主提供 `OPENDESIGN_CONTROL_KEY` / `VELA_CONTROL_KEY`。Cloud API Keys 页生成的推理密钥与查询凭据不同,不能混用。已有 OpenDesign/Vela 登录将控制端凭据保存在其自身配置中,本插件不会自动读取或修改那个配置。
74
- 4. 开启并刷新,可选择在侧栏或额度横条显示。
75
-
76
- 查询只访问以下固定官方 HTTPS GET 端点,并在凭据/工作区校验之后才发起:
77
-
78
- ```text
79
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/coding-plan-usage # 优先窗口端点
80
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # 纯 Bearer 回退,仅在 401/403 后尝试一次
81
- https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # 钱包端点,独立读取
82
- ```
83
-
84
- #### 端点权限、Bearer 回退与 401 排查
85
-
86
- - 用量端点并非总是接受 Control Key:部分套餐/账户只接受**浏览器会话 Cookie**,因此同一个 Control Key 可能在 `billing/coding-plan-usage` 返回 `401`/`403`,而 `/billing/preflight`、`/wallet/balance` 等其它端点仍返回 `200`。插件从不发送浏览器 Cookie:先以 `Authorization: Bearer ...` 查询用量端点;若返回 `401`/`403`,再用同一请求头重试一次 `billing/preflight`。后者把同样的窗口数据嵌套在 `codingPlan` 下,解析与百分比规则完全一致。
87
- - 主端点返回 `200`、响应格式错误或其它 HTTP 状态时都不会触发回退。钱包端点独立并行读取:只有一侧失败时仍显示另一侧数值,失败侧留空而不是编造为零,失败原因(凭据被拒/无订阅/响应无效/网络失败)保留在刷新记录中;两侧都失败才显示错误状态。
88
- - 回退成功仍返回标准 `{ windows, endpoint }`,`endpoint` 指向实际返回数据的端点。回退端点本身被拒、格式错误或网络失败时,记为窗口侧失败原因,而不是钱包失败。
89
- - `preflight` 同时返回 `workspaceMemberId` 与 `balanceUsd`。成员身份会与钱包成员核对;`balanceUsd` 只在 `/wallet/balance` 不可读时作为显示余额的兜底,不会与可读的钱包金额相加或覆盖它。
90
- - 工作区 ID 必须取 `GET https://amr-api.open-design.ai/api/v1/workspaces` 返回的 `items[].workspaceId`;**不能**使用 `~/.amr/config.json` 里的 `profiles.prod.user.id`。后者虽然能通过认证,却会把请求指向错误的资源范围,服务端返回 `403 workspace_billing_scope_forbidden`。
91
- - 额度端点返回 `401`/`403` 时的排查步骤:
92
- 1. 确认保存的是 **Control Key**,不是 Cloud API Keys 页生成的推理密钥。
93
- 2. 用同一凭据调用 `GET /api/v1/workspaces`,复制准确的 `items[].workspaceId`。
94
- 3. 若 `/workspaces` 成功而 `/billing/coding-plan-usage` 返回 `401`/`403`,自动 `preflight` 回退通常已覆盖该账户,不需要浏览器会话。若同一凭据在 `preflight` 也返回 `401`/`403`,说明该账户没有开放 Control Key 的窗口读取;请登录 OpenDesign Cloud 控制台查看用量。钱包端点可能仍可读取,会单独显示。
95
- 4. 核对密钥与工作区属于同一账户,并确认密钥未被轮换或撤销。
96
-
97
- 查询只访问上文列出的固定官方 HTTPS GET 端点;核对工作区,钱包必须提供成员身份,额度响应提供成员身份时再核对二者一致。回退响应省略外层冗余 `workspaceId` 时,在已由请求范围校验工作区的前提下仍接受;若响应指向不同工作区则拒绝。凭据由 DSH 凭据库管理,不回显、不写入账本,不跟随重定向,也不附带浏览器 Cookie。
98
-
99
- 所有实际返回的窗口分别显示已用百分比和重置时间,不相加、不标成无限。钱包作为独立的美元等值额度显示,真实零余额保留。额度与钱包独立查询:一侧失败时另一侧仍照常显示;`eligible: false`/空窗口回执(无论来自主端点还是回退端点)会明确报告为**无生效订阅**,不再与凭据失效混为一谈。认证失败、缺失回执或身份不匹配不显示虚构的零额度,两侧都失败时才显示错误/不可用状态。工作区配置跨重启保留,改变后清理原查询缓存。
100
-
101
- 公开价表已经直接读取;认证查询、Bearer-only `preflight` 回退与中英文设置使用模拟数据验证,覆盖大整数、零余额、串工作区/成员、单侧认证失败、preflight 形状的 `codingPlan` 回执、价格持久化等情况。**没有真实账户验证,没有调用付费模型。**真实账户的 Control Key 权限与服务端响应需要在配置后核对。
102
-
103
- 端点来源:官方 Cloud bundle `cloud-root-B21Emo2w.js` 与 `pricing-refund-policy-BDFJHl33.js`(2026-10-15 读取);[工作区钱包契约](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts)与 [Vela 计费适配器](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts)(上述 commit)。`billing/preflight` 的准确回执形状(`codingPlan` 内嵌窗口、`workspaceMemberId`、`balanceUsd`)来自 @yunjuanhuakai 的 [#274 评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566);401 复现与附件来自 @codeforker654 的 [评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870)。官方明确支持 DSH,说明这条 issue 有可执行的接入需求;仅凭“便宜、可能流行”的一句话,不能认定为广告。
1
+ # OpenDesign billing and quota / 计费与额度
2
+
3
+ ## English
4
+
5
+ This release addresses [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274), requested by @playgithub. It adds an OpenDesign price channel and read-only workspace quota queries; it is included in version 1.8.27. It does not install OpenDesign, create an account or change a model route.
6
+
7
+ The quota query uses the Bearer-only preflight endpoint discovered by @yunjuanhuakai in the [#274 follow-up comments](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566): the plugin directly reads `billing/preflight` with a Control Key. @unifilitence confirmed this behavior and the independent wallet contract in [#313](https://github.com/Han-1413141/dsh-cost-meter/issues/313). @codeforker654's [401 report](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) documents the original authentication failure.
8
+
9
+ ### Conversation costs
10
+
11
+ - The offline catalog contains 35 token-priced models checked on **2026-10-15**, from the [official public API](https://amr-api.open-design.ai/api/v1/public/model-prices). Prices are **USD per 1M tokens**, with cache read/write rates and long-context tiers where provided. The long tier applies to the entire request only above its input threshold, including cached input.
12
+ - Provider IDs `opendesign`, `open-design`, `open-design-api` and `amr-link.open-design.ai`, including DSH's `llm-` prefix, use this separate catalog. A custom price under the original alias takes priority. Other provider IDs can use the existing explicit price mapping and plan-assignment controls.
13
+ - OpenDesign prices never serve as fallback prices for another provider. Unknown OpenDesign models stay unpriced; the plugin does not borrow a direct-vendor price.
14
+ - **Settings → Cost → Prices → Sync official prices** also refreshes the public OpenDesign catalog. A used/enabled OpenDesign channel refreshes at startup and hourly. No key or model request is needed. User-edited prices and removed models stay intact. Saved price versions preserve existing details when rates change; recalculation is explicit and retains the original amounts. A historical price version that was never captured cannot be reconstructed.
15
+
16
+ OpenDesign uses shared subscription allowances and can fall back to its wallet; see its [model-credit rules](https://open-design.ai/model-credits/). Calls default to **Plan-equivalent cost**, which is not a subscription payment or a cash bill. Set wallet-funded calls to **API** in the billing-classification controls, or assign individual models explicitly. DSH's standard usage response does not identify each request's funding source, account-specific discount, image charge or automatic top-up. Those amounts are not invented from the list price or balance movement.
17
+
18
+ ### Quota queries
19
+
20
+ **DSH-only use:** you do not need to install the OpenDesign app to use its model API in DSH or track conversation costs. Remote quota reads additionally need the workspace ID and Control Key from your OpenDesign Cloud account. An inference API key cannot supply these credentials. If you only have an inference key, leave this quota card disabled; price matching and conversation costs continue to work.
21
+
22
+ 1. Open **Settings → Cost → Quotas**, find **OpenDesign**, and expand its settings.
23
+ 2. Enter the exact **workspace ID** from your OpenDesign Cloud workspace.
24
+ 3. Configure a **Control Key** in the credential editor, or supply `OPENDESIGN_CONTROL_KEY` / `VELA_CONTROL_KEY` to the DSH host. An inference key from the Cloud API Keys page is a different credential and cannot be used for this query. The existing OpenDesign/Vela login keeps control credentials in its own profile; the plugin does not read or rewrite that profile automatically.
25
+ 4. Enable the card and refresh. Select its location to also show it in the sidebar or quota strip.
26
+
27
+ The host issues only these authenticated GET requests to the fixed official HTTPS origin:
28
+
29
+ ```text
30
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # direct Bearer-only window query
31
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # wallet, read independently
32
+ ```
33
+
34
+ #### Endpoint permissions and 401 troubleshooting
35
+
36
+ - `/billing/preflight` and `/wallet/balance` run in parallel with `Authorization: Bearer ...` and `x-vela-workspace-id`. The plugin no longer queries the browser-session-only `coding-plan-usage` route. Preflight nests the quota windows under `codingPlan`; both layers' workspace and member identities are validated before unwrapping.
37
+ - The wallet endpoint remains an independent query with its `billingScopeVersion: 2` contract. A valid wallet response is authoritative. When it cannot be read, a validated preflight result may display its `balanceUsd` as a fallback. Failure on one side preserves the other; no missing value becomes a fabricated zero. The refresh trace records the failing side.
38
+ - The workspace ID is `items[].workspaceId` from `GET https://amr-api.open-design.ai/api/v1/workspaces`, not `profiles.prod.user.id` from `~/.amr/config.json`.
39
+ - For a 401/403, check that the Control Key is current, belongs to the selected workspace and can read that workspace. An inference key or a user ID in the workspace field will not work. If the account rejects preflight too, use the OpenDesign Cloud console to check quota; a readable wallet is still shown separately.
40
+
41
+ Quota and wallet responses must match the requested workspace. The wallet must identify its member; if the quota response provides a member identity, both must match. A preflight response that omits the redundant outer `workspaceId` is accepted only after the requested workspace has scoped the request; a body naming a different workspace is rejected. Credentials are never forwarded through a redirect and no cookie is attached. They use the existing DSH credential store and are excluded from the ledger and client snapshot.
42
+
43
+ Each returned allowance window has its own used percentage and reset time. Simultaneous windows are not added together or called unlimited. Wallet credit remains a separate USD-equivalent value, including a real zero. Quota and wallet are fetched independently, so a failure on one side keeps the other side visible; an `eligible: false` / empty-window answer is reported as **no active subscription** instead of a credential failure. Invalid, unauthorized or missing responses never fabricate a zero allowance; when both sides fail, the card shows an error/unavailable state. The workspace setting is kept across restarts and invalidates the previous query when changed.
44
+
45
+ ### Evidence and limits
46
+
47
+ The public catalog was fetched without authentication. The authenticated adapter, direct Bearer-only `billing/preflight` reads and bilingual settings were verified with synthetic responses, including large credit counts, zero balances, mismatched identities, authorization failures on either side, a preflight-shaped `codingPlan` body, and price-refresh persistence. **No live account query or paid model request was made.** Production Control Key permissions and response availability still require a configured account.
48
+
49
+ Endpoint provenance: the official Cloud bundles `cloud-root-B21Emo2w.js` and `pricing-refund-policy-BDFJHl33.js` served on 2026-10-15; the [workspace-wallet contract](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts) and [Vela billing adapter](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts) at the inspected commit. The exact `billing/preflight` shape (`codingPlan`-nested windows, `workspaceMemberId`, `balanceUsd`) comes from @yunjuanhuakai's [#274 comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566); the 401 reproduction and attached report come from @codeforker654's [comment](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870). The [official guide](https://open-design.ai/zh/model-credits/) explicitly lists DSH as a supported API client; the issue has a usable integration request. Its short promotional wording alone does not establish advertising or spam.
50
+
51
+ ## 中文
52
+
53
+ 本版本实现了 @playgithub 在 [#274](https://github.com/Han-1413141/dsh-cost-meter/issues/274) 提出的接入需求,随 1.8.27 发布。同时采用 #274 后续评论中 @yunjuanhuakai 发现的纯 Bearer preflight 端点([评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566)),并以 @codeforker654 的 [401 复现报告](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870) 为验证案例。@unifilitence 在 [#313](https://github.com/Han-1413141/dsh-cost-meter/issues/313) 补充了独立钱包契约与本地验证。不会安装 OpenDesign、注册账户或改变模型路由。
54
+
55
+ ### 会话计费
56
+
57
+ - 从[官方公开价表](https://amr-api.open-design.ai/api/v1/public/model-prices)加入 **35 个模型**,核对日期为 **2026-10-15**。单位为 **美元/百万 Token**,包含已公布的缓存读取、缓存写入和长上下文价格。超过输入阈值后,整次请求使用长档,输入阈值包含缓存输入。
58
+ - `opendesign`、`open-design`、`open-design-api`、`amr-link.open-design.ai` 及其 `llm-` 前缀使用独立目录;原渠道中手工配置的价格优先。其他自定义名称可通过既有价格映射和套餐归属入口关联。
59
+ - 未收录的 OpenDesign 模型标为未定价,不借用直连厂商价格;其他渠道也不会使用 OpenDesign 价作为兜底。
60
+ - **设置 → 费用 → 价格 → 同步官方价格**会同步公开目录。已使用或开启 OpenDesign 时,启动和每小时也会刷新;不需要密钥,不调用模型。自定义价格、取消挂载和已保存价格版本的历史明细保留。历史重算需要主动确认并保留原金额;未保存过的历史价格版本无法还原。
61
+
62
+ OpenDesign 的 API 与客户端共用套餐,套餐用尽后可以继续扣钱包,详见[官方额度规则](https://open-design.ai/zh/model-credits/)。因此默认计入 **Plan 等值费用**,不把额度当成现金支出。钱包付款可在计费分类中设为 **API**,也可逐模型配置。DSH 的标准用量回执没有逐次扣款来源、账户折扣、图片费用或自动充值金额,这些金额不会通过公开单价或余额变化猜算。
63
+
64
+ ### 额度查询
65
+
66
+ **只使用 DSH 的情况:**在 DSH 调用 OpenDesign 模型 API、统计会话费用,都不需要安装 OpenDesign 应用。远端额度查询另外需要 OpenDesign Cloud 账户的工作区 ID 和 Control Key,推理 API Key 不能代替。如果只有推理密钥,可以关闭额度卡片,价格匹配和会话计费照常工作。
67
+
68
+ 1. 在 **设置 → 费用 → 额度**找到并展开 **OpenDesign**。
69
+ 2. 填入 OpenDesign Cloud 中对应的**工作区 ID**。
70
+ 3. 在凭据编辑器中配置 **Control Key**,或向 DSH 宿主提供 `OPENDESIGN_CONTROL_KEY` / `VELA_CONTROL_KEY`。Cloud API Keys 页生成的推理密钥与查询凭据不同,不能混用。已有 OpenDesign/Vela 登录将控制端凭据保存在其自身配置中,本插件不会自动读取或修改那个配置。
71
+ 4. 开启并刷新,可选择在侧栏或额度横条显示。
72
+
73
+ 查询只访问以下固定官方 HTTPS GET 端点,并在凭据/工作区校验之后才发起:
74
+
75
+ ```text
76
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/billing/preflight # 直接使用纯 Bearer 查询窗口
77
+ https://amr-api.open-design.ai/api/v1/workspaces/{workspaceId}/wallet/balance # 钱包端点,独立读取
78
+ ```
79
+
80
+ #### 端点权限与 401 排查
81
+
82
+ - `/billing/preflight` 和 `/wallet/balance` 使用 `Authorization: Bearer ...` 与 `x-vela-workspace-id` 并行读取,不再请求需要浏览器会话的 `coding-plan-usage`。preflight 把窗口放在 `codingPlan` 内;解析前会核对内外两层工作区和成员身份。
83
+ - 钱包保留独立查询,按 `billingScopeVersion: 2` 契约校验。成功读取的钱包金额优先;钱包不可读时,经校验的 preflight 响应可提供 `balanceUsd` 作为余额。一侧失败保留另一侧,缺失数据不会变成零,失败原因保留在刷新记录中。
84
+ - 工作区 ID 来自 `GET https://amr-api.open-design.ai/api/v1/workspaces` 的 `items[].workspaceId`,不能填 `~/.amr/config.json` 中的 `profiles.prod.user.id`。
85
+ - 遇到 401/403,检查 Control Key 是否有效、是否属于所填工作区、是否有读取权限。推理 API Key 不能代替 Control Key,用户 ID 不能代替工作区 ID。如果该账户连 preflight 也拒绝,可在 OpenDesign Cloud 控制台查看额度;可读的钱包仍单独显示。
86
+
87
+ 查询只访问上文列出的固定官方 HTTPS GET 端点;核对工作区,钱包必须提供成员身份,额度响应提供成员身份时再核对二者一致。preflight 响应省略外层冗余 `workspaceId` 时,在已由请求范围校验工作区的前提下仍接受;若响应指向不同工作区则拒绝。凭据由 DSH 凭据库管理,不回显、不写入账本,不跟随重定向,也不附带浏览器 Cookie。
88
+
89
+ 所有实际返回的窗口分别显示已用百分比和重置时间,不相加、不标成无限。钱包作为独立的美元等值额度显示,真实零余额保留。额度与钱包独立查询:一侧失败时另一侧仍照常显示;`eligible: false`/空窗口回执会明确报告为**无生效订阅**,不再与凭据失效混为一谈。认证失败、缺失回执或身份不匹配不显示虚构的零额度,两侧都失败时才显示错误/不可用状态。工作区配置跨重启保留,改变后清理原查询缓存。
90
+
91
+ 公开价表已经直接读取;认证查询、直接读取 Bearer-only `preflight`与中英文设置使用模拟数据验证,覆盖大整数、零余额、串工作区/成员、单侧认证失败、preflight 形状的 `codingPlan` 回执、价格持久化等情况。**没有真实账户验证,没有调用付费模型。**真实账户的 Control Key 权限与服务端响应需要在配置后核对。
92
+
93
+ 端点来源:官方 Cloud bundle `cloud-root-B21Emo2w.js` 与 `pricing-refund-policy-BDFJHl33.js`(2026-10-15 读取);[工作区钱包契约](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/packages/contracts/src/api/collab.ts)与 [Vela 计费适配器](https://github.com/nexu-io/open-design/blob/7abd6fc2b11987c3940eb4ffc461478ff37c0b33/apps/daemon/src/integrations/vela-billing.ts)(上述 commit)。`billing/preflight` 的准确回执形状(`codingPlan` 内嵌窗口、`workspaceMemberId`、`balanceUsd`)来自 @yunjuanhuakai 的 [#274 评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236591566);401 复现与附件来自 @codeforker654 的 [评论](https://github.com/Han-1413141/dsh-cost-meter/issues/274#issuecomment-6236228870)。官方明确支持 DSH,说明这条 issue 有可执行的接入需求;仅凭“便宜、可能流行”的一句话,不能认定为广告。