前言¶
DeepSeek Harness (DSH) 採用插件架構,旨在爲智能體開發提供靈活的擴展能力。在使用多模型、多廠商服務時,追蹤 token 消耗與費用是常見痛點。dsh-token-ledger-pro 是一個集服務端計費與客戶端實時展示於一體的插件,由原 dsh-custom-cost-meter(計費統計面板)與 dsh-spend(開銷統計)合併而來。它支持中英雙語,提供完整的費用統計、餘額查詢及預算告警功能。
核心功能¶
該插件提供以下核心能力:
- 自動採集:自動採集每次 LLM 請求的 token 用量(基於 DSH session 事件),按模型價格實時計費。
- 實時展示:在輸入框工具行右側(模型選擇器旁)實時顯示當前模型、賬戶餘額、會話/今日/本月消費及預算橫條。橫條顏色隨閾值變化:默認 ≥80% 轉橙、≥100% 轉紅。
- 餘額查詢:內置 DeepSeek / OpenAI / Anthropic / Kimi / 智譜 / 火山方舟(豆包)/ 阿里雲(千問)官方餘額 API。未內置廠商可用自定義 HTTP 端點 + JSONPath 提取。默認 1 分鐘緩存(
balanceCacheTtl)。 - 價格目錄:內置 16 家廠商、136 個模型價格目錄,覆蓋 DeepSeek、豆包/火山方舟、OpenAI、Anthropic、Gemini、通義千問、騰訊混元、Kimi、MiniMax、智譜 GLM、硅基流動、xAI、Mistral、Meta Llama、Cohere、OpenRouter。
- 智能匹配:按精確匹配 → 前綴匹配 → 廠商默認價回退 → 跨廠商全局匹配的順序查找價格。
- 未定價處理:模型不在目錄中時,自動回退廠商默認價並顯示“未定價”徽標,不再靜默顯示 ¥0。
- 特殊計價:支持 DeepSeek 峯谷計價(北京時間峯時 ×2;2026-08-23 起週末全天谷價);緩存價(cacheRead / cacheWrite)單獨計價。
- 數據持久化:聚合當日/本月/會話數據,並保留最近 2000 條明細(JSON 原子寫,重啓不丟)。
- 遠端同步:支持通過
priceSyncUrl從遠端同步價格目錄。
安裝與啓用¶
使用 DSH 官方命令行安裝:
dsh plugin --profile web add dsh-token-ledger-pro
安裝完成後重啓 DSH Web 服務,並在瀏覽器中強制刷新頁面(Ctrl+F5)。
配置說明¶
首次安裝後,編輯配置文件 ~/.dsh/profiles/web/cordis.patch.yml。在 dsh-token-ledger-pro 的 config 塊中添加 balance 配置以查詢餘額。
官方 API 配置示例¶
插件會根據當前選中模型的廠商自動匹配對應的餘額配置。
- id: dsh-token-ledger-pro
config:
monthlyBudget: 100
balance:
deepseek:
type: deepseek
apiKey: "sk-你的DeepSeek密鑰"
currency: "CNY"
openai:
type: openai
apiKey: "sk-你的OpenAI密鑰"
currency: "USD"
anthropic:
type: anthropic
apiKey: "sk-ant-xxx"
currency: "USD"
moonshot:
type: moonshot
apiKey: "sk-xxx"
currency: "CNY"
zhipu:
type: zhipu
apiKey: "xxx.xxx"
currency: "CNY"
hunyuan:
type: tencent
secretId: "AKID你的騰訊雲SecretId"
secretKey: "你的騰訊雲SecretKey"
currency: "CNY"
qwen:
type: aliyun
accessKeyId: "LTAI你的阿里雲AccessKeyId"
accessKeySecret: "你的阿里雲AccessKeySecret"
currency: "CNY"
balanceCacheTtl: 60
自定義 HTTP 端點¶
對於未內置廠商或中轉站,可使用自定義端點:
- id: dsh-token-ledger-pro
config:
balance:
myproxy:
type: custom
endpoint: "https://你的中轉站/api/balance"
headers:
Authorization: "Bearer sk-xxx"
valuePath: "data.balance"
currency: "CNY"
價格覆蓋¶
在插件目錄下創建 lib/prices.override.json 可覆蓋本地價格。
{
"deepseek": {
"default": { "input": 2, "output": 8, "cacheRead": 0.5, "cacheWrite": 2 },
"models": { "deepseek-chat": { "input": 2, "output": 8 } }
}
}
數據與 API¶
插件將數據持久化至本地 JSON 文件,並提供 HTTP API 進行查詢。
- 數據文件路徑:
~/.dsh/profiles/<profile>/data/dsh-token-ledger-pro.json - API 端點:
GET /dsh-token-ledger-pro/summary?session=<sessionId>:會話/今日/本月/預算/當前模型計價狀態。GET /dsh-token-ledger-pro/balance?provider=<provider>:賬戶餘額。GET /dsh-token-ledger-pro/prices:價格目錄。GET /dsh-token-ledger-pro/config/POST /dsh-token-ledger-pro/config:讀取/修改預算與未知模型策略。GET /dsh-token-ledger-pro/history?limit=50:最近明細。
注意事項¶
- 密鑰安全:密鑰以明文存儲在本地配置文件中,請勿泄露。
- 廠商支持:火山方舟/豆包(Volcano Ark)需要 AK/SK 簽名,暫未內置,建議使用自定義端點。
- 顯示狀態:面板顯示“餘額 –”表示未配置或請求失敗;顯示“未定價”表示模型不在目錄中但已按默認價估算。
- 生效條件:更換模型後無費用顯示,請確認 DSH 已重啓且插件在“設置 → 插件”中狀態爲 active。
- 計費時間:DeepSeek 峯值時段計費以北京時間(Asia/Shanghai)爲準。
結語¶
該插件通過服務端計費與客戶端實時展示,解決了多模型開發中的費用追蹤問題。其內置的價格目錄與智能匹配機制降低了配置門檻。更多細節與源碼請訪問項目倉庫。