dsh-ollama-usage
August 21, 2026 · View on GitHub
Usage tracking for Ollama Cloud inside DeepSeek Harness (DSH) — a Cordis plugin that combines the account's cloud quota windows with locally tracked per-model token usage, and renders the full stats view (watcher-style) in the DSH Settings UI.
Built for DSH 0.1.0-rc.8 (@deepseek-ai packages 0.1.0-rc.8).
Features
- Cloud quota — session + weekly usage bars with reset countdowns and
per-model request counts, read from
GET https://ollama.com/api/usage(the credential never leaves the Host). - Local ledger — per-call token usage captured from the DSH session event
bus (
request/header+assistant/chunkusage events) into an append-only JSONL ledger. Tracks input/output tokens plus cache-read/cache-write and reasoning tokens when the provider reports them. - Watcher-style stats (ported from
Kosello/ollama-cloud-watch):
- Plan economics: monthly price, weekly equivalent, effective $/request
- Per-model request share, cache hit %, estimated token volumes
- API-equivalent cost per model (/1M effective, window totals, price coverage) — prices from OpenRouter (24h cache) with a builtin fallback table, plus official DeepSeek peak/off-peak rates
- Plan vs API per-model comparison (subscription allocation vs pay-per-token estimate)
- Cache break-even — the cache-hit rate at which pay-per-token becomes cheaper than the subscription, per model
- Weekly history — deduped per ISO week, kept locally (52 weeks)
- 5h session log — snapshots per session window
- Warn/crit alert state — fires once per week at 75% / 90%
Install
cd /path/to/deepseek-harness
pnpm dsh plugin --profile web add /path/to/dsh-ollama-usage
sudo systemctl restart dsh-web.service # or your DSH service
The plugin needs the OLLAMA_CLOUD_API_KEY credential resolvable through
the credentials seam (or the launching environment) — the same key the
llm-pi-ai ollama-cloud provider route uses.
Usage
Open Settings → Ollama Usage in the DSH web UI (loopback-only, like the rest of Settings). The card shows:
- Limits (session/weekly bars + resets)
- Session & weekly per-model tables (requests, share, cache hit %, API cost)
- API equivalent cost + plan vs API
- Cache break-even
- Local ledger token averages
- Weekly history
Data files
Everything is written under $DSH_HOME/ollama-usage/ (0600):
| File | Contents |
|---|---|
ledger.jsonl | one JSON line per LLM call (ts, sessionId, provider, model, token counts) |
history.jsonl | weekly snapshots (deduped per ISO week) |
sessions.jsonl | 5h-window snapshots (capped at 1000) |
price-cache.json | OpenRouter price snapshot (24h TTL) |
alert-state.json | weekly alert latch |
plan.txt | optional plan override: {"plan": "pro"} (default pro) |
RPC endpoints
Private Connection channel /ollama-usage:
cloud/read— parsed cloud snapshotself/stats— ledger aggregatesstats— full computed statistics view (what the card renders)combined— cloud + self in one payload
All endpoints are loopback authority only; the browser never sees a
credential value.
Development
pnpm install
pnpm typecheck
pnpm build # tsdown → lib/ (host) + lib/client.js (browser bundle)
License
MIT