Add local token usage dashboard with SQLite storage#236
Open
tdu-naifen wants to merge 1 commit intoericc-ch:masterfrom
Open
Add local token usage dashboard with SQLite storage#236tdu-naifen wants to merge 1 commit intoericc-ch:masterfrom
tdu-naifen wants to merge 1 commit intoericc-ch:masterfrom
Conversation
Track per-request input/output token usage in a local SQLite database
and expose a live dashboard at /dashboard on the running server.
Features:
- SQLite store (bun:sqlite) at ~/.local/share/copilot-api/token-usage.db
- 30-day auto-prune, 1-minute bucket resolution
- Atomic upsert per (timestamp_min, model) composite key
- Token capture for both /chat/completions and /v1/messages endpoints
- Non-streaming: reads response.usage from Copilot API response
- Streaming: injects stream_options.include_usage=true so Copilot
returns usage in the final SSE chunk; falls back to local tokenizer estimate
- GET /token-usage?range=1h|6h|24h|7d|30d JSON API
- GET /dashboard — shadcn-inspired dark UI with:
- Stat cards (total requests, input tokens, output tokens)
- Area chart (Chart.js via CDN, input vs output over time)
- Per-model breakdown table
- Copilot Budget section: fetches /usage and renders progress bars for
premium_interactions, chat, completions quota with color thresholds
(green <80%, yellow 80-95%, red >=95%, gray for unlimited)
- 30-second auto-refresh
- Unit tests for budget color/percent helpers (9 tests)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Track per-request input/output token usage in a local SQLite database and expose a live dashboard at /dashboard on the running server.
Features: