Back to home

LeslieWylie

dsh-gateway-billing

Per-conversation LLM billing display for the DSH web composer, for anyone self-hosting a New API / One API-compatible gateway.

Stars
0
Language
JavaScript
Created
Aug 16, 2026
Updated
Aug 16, 2026

Introduction

dsh-gateway-billing · 逐对话模型计费显示

English

这是什么

一个逐对话模型计费显示 skill。从内部一个「网关计费」看板脱敏泛化而来,在 DSH Web 对话输入栏下方实时显示当前对话调用各模型产生的费用——适用于任何自建的、暴露 New API / One API 兼容 /pricing 接口的 LLM 网关。

核心能力

模块内容
价格表拉取从你配置的网关地址拉取 New API / One API 格式的价格表,每 10 分钟自动刷新
双计费模式按 token 计价(quota_type=0)与固定单价(quota_type=1)两种模式均支持
逐对话折算遍历当前对话的所有模型调用节点,按 usage(input/output/cache token)与价格表折算总费用
Composer Dock 展示一行显示:💰 总费用 · 最近调用模型×次数 · 输入/输出/cache token;多模型对话自动展开分行
未配置/失败态区分未配置价格表地址与拉取失败(网络错误等)展示不同提示;前者不提供「点击重试」——因为重试不能解决没配置的问题
未定价模型提示价格表中找不到对应条目的模型调用会单独计数高亮,不会被静默计为 $0

安装

方式一:通过 profile 安装(推荐)

# 1. 克隆仓库到本地
git clone https://github.com/LeslieWylie/dsh-gateway-billing.git ~/Desktop/01-Projects/dsh-gateway-billing

# 2. 在 profile 目录添加依赖
cd ~/.dsh/profiles/<your-profile>

# 编辑 package.json,在 dependencies 中添加:
# "dsh-gateway-billing": "link:~/Desktop/01-Projects/dsh-gateway-billing"

# 3. 编辑 cordis.patch.yml,添加一行,并填入你自己网关的价格表地址:
# - id: gateway-billing
#   name: 'dsh-gateway-billing'
#   config:
#     pricingUrl: 'https://your-gateway.example.com/api/pricing'

# 4. 安装依赖
pnpm install

# 5. 重启 dsh 进程

方式二:dsh plugin add(待发布到 npm 后可用)

dsh plugin add dsh-gateway-billing

所需配置

本 skill 需要在你自己 profile 的 cordis.patch.yml 中为 gateway-billing 这一条目提供 config

配置项说明示例
pricingUrl你的网关的价格表接口地址,需返回 New API / One API 格式的 {data: [{model_name, quota_type, model_ratio, completion_ratio, model_price}, ...]}https://your-gateway.example.com/api/pricing

不配置 pricingUrl 时,composer dock 会明确提示「未配置」,不会报错,也不会显示误导性的计费数字。

设计原则

  • 网关无关:不内置任何具体网关地址,价格表来源完全由使用者配置
  • 失败可见:拉取失败与未配置是两种不同的状态,各自展示对应的提示文案,不静默吞掉
  • 单次刷新,多处消费:价格表在服务端每 10 分钟刷新一次并缓存,composer dock 通过 RPC 读取快照,不会为每个对话重复拉取

脱敏声明

本插件从内部一个网关计费看板脱敏泛化而来。原实现将价格表接口地址硬编码在源码中,且没有「未配置」状态——脱敏时把地址改为必填的 config.pricingUrl,并补上了未配置态与拉取失败态的区分展示。已移除所有内部机构名称、内部网关域名等具体引用。

更新日志

CHANGELOG.md

许可证

MIT