gate.dashboard: Unified dashboard#
Unified spend, usage, and quota view for myGate. Builds the dashboard data layer
on top of gate.cost (LiteLLM spend API), gate.quota (quota tracking + econ
estimation), and gate.ledger (session transcript parsing). Orchestrates data
collection, renders CLI tables, serializes JSON, and optionally launches a
pyratatui-based TUI dashboard.
Data layer#
- gate.dashboard.build_dashboard_data(*, base_url: str, token: str, since: datetime, until: datetime, include_quota: bool = True, include_sessions: bool = True) DashboardData#
Collect all dashboard data sources, gracefully handling failures.
- Parameters:
base_url – LiteLLM gateway root URL.
token – LiteLLM virtual key (may be empty; spend calls will return empty).
since – Window start.
until – Window end.
include_quota – Whether to attempt quota snapshot collection.
include_sessions – Whether to attempt session parsing.
- Returns:
A DashboardData with whatever could be collected; None for any component that failed.
- class gate.dashboard.DashboardData(fetched_at: datetime, spend_summary: SpendSummary | None = None, spend_window: SpendWindow | None = None, quota_snapshot: QuotaSnapshot | None = None, session_summary: SessionSummary | None = None, time_range: tuple[datetime, datetime] | None = None)#
Aggregated data for one dashboard view.
- spend_summary#
Aggregated spend by model/project (from cost.py), or None on failure.
- Type:
SpendSummary | None
- spend_window#
Raw gateway spend window (from cost.py), or None on failure.
- Type:
SpendWindow | None
- quota_snapshot#
Fleet quota snapshot (from quota.py), or None on failure.
- Type:
QuotaSnapshot | None
- session_summary#
Aggregated session summary (from ledger.py), or None on failure.
- Type:
SessionSummary | None
CLI rendering#
- gate.dashboard.render_spend_table(data: DashboardData) str#
Render a formatted text table of per-model and per-project spend.
- Parameters:
data – The dashboard data containing a spend summary.
- Returns:
A multi-line string with formatted spend tables.
- gate.dashboard.render_usage_table(data: DashboardData) str#
Render a usage overview table from session summaries.
- Parameters:
data – The dashboard data containing a session summary.
- Returns:
A multi-line string with the usage overview.
- gate.dashboard.render_quota_table(data: DashboardData) str#
Render quota window status by delegating to quota.render_table.
- Parameters:
data – The dashboard data containing a quota snapshot.
- Returns:
A multi-line string with the quota table, or a note if unavailable.
- gate.dashboard.render_full_dashboard(data: DashboardData) str#
Combine all dashboard tables into a single output with section headers.
- Parameters:
data – The dashboard data to render.
- Returns:
A multi-line string with the full dashboard.
JSON serialization#
- gate.dashboard.render_json(data: DashboardData) str#
Serialize DashboardData to a JSON string.
- Parameters:
data – The dashboard data to serialize.
- Returns:
A pretty-printed JSON string.
TUI mode#
- gate.dashboard.render_tui(data: DashboardData) None#
Launch an interactive TUI dashboard (requires pyratatui).
Shows a split layout with spend, usage, and quota views. Keyboard navigation: Tab to switch views, q to quit.
This function imports pyratatui lazily so the module loads without it.
The TUI mode requires the optional pyratatui dependency. Install it with:
uv pip install pyratatui
If pyratatui is not installed, the dashboard falls back to CLI table/JSON output.