Introduction¶
When using DeepSeek Harness (DSH) for model inference, existing plugins can usually only answer “how much did this call actually cost?” Developers often also need to know: “How much would this traffic cost if it were routed to another model or vendor?” This is the gap that the dsh-switch-cost plugin addresses.
Plugin Overview¶
The plugin answers the above question by pricing the workload twice: once for the currently active route, and again for all other routes in the pricing catalog. It is mainly used to compare API costs across different models and vendors.
- Plugin name:
dsh-switch-cost - Author: xyzs996
- Category: Model inference
- License: MIT
- Core value: Locally compute cost comparisons for the same session across multiple routes, without manual estimation.
Installation and Configuration¶
Install the plugin with the following command:
dsh plugin add dsh-switch-cost
Runtime Requirements¶
This plugin depends on the sessionProjections projection registry. Make sure your Assembly (assembler) correctly injects this dependency; otherwise, the plugin will not be able to provide its functionality.
// 示例注入代码
ctx.inject(['sessionProjections'], ...)
Configuration¶
Set the number of alternative routes to compare in the configuration file.
switch-cost:
alternatives: 8 # 排序后显示的备选路由数量,默认为 8
Features¶
- Time-based pricing: Aggregates session usage by route and UTC hour, supporting time-of-day pricing (e.g., peak and off-peak hours).
- Cache pricing: Bills cache reads and cache writes separately.
- Route comparison: Outputs the actual cost for the current route and lists the costs for all alternative routes, along with the percentage difference versus the actual route.
- Pricing export: Exports the current pricing catalog via the
/pricesendpoint.
Projection State¶
The plugin registers a projection unit named switchCost. Its state contains route usage buckets grouped by hour, including four token categories: input, cacheRead, cacheWrite, and output.
Tool Interface¶
The plugin registers a tool named switch_cost. This tool takes no parameters and returns the total token count for the current session, the cost for the actual route, and a cost comparison for all alternative routes.
Example return data structure:
{
tokens: 100, // 整个会话的桶总计数
actual: [{ route, tokens, cost, costText, ratesApplied, pricedAs, source, checkedAt, layer }],
actualTotal, actualTotalText,
alternatives: [{ route, cost, costText, versusActual, source, checkedAt, layer }],
unpriced?: [{ route, tokens }],
caveats: string[]
}
Pricing Source¶
The pricing catalog includes two layers, with priority given to Vendor:
1. layer: 'vendor': Reads the vendor’s official pricing page directly at the moment of checkedAt.
2. layer: 'models.dev': Sourced from the community catalog (usually delayed and may not support time-based pricing).
Usage Example¶
In the Agent’s tool list, the switch_cost tool automatically provides session cost comparison results. The model can read the tool output and present it to the user.
Example output text (rendered by the model):
Ran on deepseek-official/deepseek-v4-flash: $0.0416 (peak and off-peak hours both billed)
Same tokens, other routes:
deepseek-official/deepseek-v4-flash-vision-exp $0.0416 +0%
openai/gpt-5.6-luna $0.0513 +23%
deepseek-official/deepseek-v4-pro $0.1260 +203%
Exporting the Price List¶
Access dsh-switch-cost/prices via an HTTP request to obtain the detailed pricing catalog. Each row includes source (origin) and checkedAt (check date).
Notes¶
- Token count source: Token counts come from the actual model used, not from predicted model counts. Different models use different tokenizers, so the token count for Model A cannot simply be applied to Model B’s pricing for prediction.
- Cache pricing differences: Different vendors have different caching strategies and pricing, so cache pricing is for reference only.
- Billing mode: Prices are based only on Pay-as-you-go list prices and do not include subscription plans, prepaid packages, or free tiers.
- Data freshness: Pricing data is a snapshot reflecting prices at release time. Verify the source date before use.
Conclusion¶
The dsh-switch-cost plugin enables DSH users to locally compute multi-model cost comparisons, making it especially suitable for optimizing inference costs or benchmarking vendors. It encapsulates complex pricing logic inside the plugin through projections and tools, allowing models to retrieve cost information without needing to understand the implementation details.
- GitHub repository: https://github.com/xyzs996/dsh-switch-cost
- Community catalog: https://www.skillhub.cn/plugins/xyzs996/dsh-switch-cost