#12417: feat(ui): Add Native Token Optimization Dashboard
stale
Cluster:
Usage Cost Enhancements
## Description\nThis PR integrates a native Token Optimization Dashboard into the Gateway UI. It helps users visualize token consumption across system prompts, conversation history, and tool results, and provides clear metrics on cost savings achieved through pruning and compaction.\n\n## Key Features\n- **Visual Dashboard**: Integrated charts showing token distribution and trends.\n- **Cost Metrics**: Real-time feedback on savings from prompt caching and local embedding usage.\n- **User Guidance**: Direct visibility into token usage, helping users optimize their configurations.\n\n## Preview\nPrototype available at: https://github.com/oneles/openclaw-token-optimization\n\nThis feature addresses the need for better cost management and transparency in API usage, as discussed in issue #12412.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new Gateway UI view (`ui/src/ui/views/token-usage.ts`) implementing a native Token Optimization Dashboard. The view appears to visualize token consumption across different prompt components (system prompt, conversation/history, tool results) and surfaces cost/savings metrics intended to help users understand and tune token usage.
Within the UI codebase, this fits as an additional view module under `ui/src/ui/views/`, likely routed/registered alongside other dashboard-style views, and should follow existing patterns for view registration, data sourcing from the gateway/backend, and shared chart/metric components if those exist.
<h3>Confidence Score: 3/5</h3>
- This PR looks moderately safe to merge, but needs validation around data wiring and runtime behavior of the new view.
- Only a single new UI view file is introduced, which limits blast radius, but without verifying routing/registration, data contracts, and component behavior it’s hard to be fully confident there are no runtime issues (e.g., missing exports, undefined data, chart assumptions).
- ui/src/ui/views/token-usage.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#10192: feat(tui): display daily token cost in footer
by Dalton-AI-open · 2026-02-06
79.7%
#6352: fix(ux): update gateway token error message UI location
by Glucksberg · 2026-02-01
77.6%
#6616: Control UI: daily activity dashboard
by georgeykalangi · 2026-02-01
76.2%
#7316: fix: /chat dashboard performance
by felipcsousa · 2026-02-02
75.9%
#15965: feat(ui): show inline token input on Chat page when auth fails
by alextnetto · 2026-02-14
74.9%
#9440: fix(security): warn users when gateway token appears in URLs
by zenchantlive · 2026-02-05
74.9%
#10093: fix: import gateway token from URL param into localStorage
by devjiro76 · 2026-02-06
73.2%
#8522: feat(control-ui): Add Model Requests panel for real-time API monito...
by GiantAxeWhy · 2026-02-04
73.2%
#12168: feat: integrate Mission Control dashboard into Control UI
by riftagent-git · 2026-02-08
73.0%
#6440: feat(ui): add model picker dialog with provider filtering
by igorls · 2026-02-01
73.0%