Repository navigation
Description
Area
Dashboard
What are you trying to accomplish?
Operators running one OpenCodex instance for several clients (Codex CLI, Claude Code, Cursor, OMP, Hermes, OpenClaw, third-party agents, plain curl) need to attribute spend and traffic to the credential that produced it. The Usage page already filters by time range and by client surface (codex / claude / grok), but there is no way to answer "how many tokens did API key ocx_data_ab12cd34 spend this week, and on which models".
The backend already records and accepts everything needed: usage.jsonl rows carry apiKeyId and admissionKind (src/usage/log.ts), GET /api/usage?apiKeyId=... filters on it (src/server/management/logs-usage-routes.ts), ocx usage --api-key-id exposes it on the CLI, and GET /api/keys already returns a per-key requests7d / totalRequests / lastUsedAt rollup. Only the Dashboard Usage page never exposes the filter.
What prevents this today?
gui/src/pages/Usage.tsx renders exactly two filter controls: the range segmented control and the surface segmented control (UsageFilters, surface state).
The only apiKeyId the page ever sends is the connected client's own key — if (connected && scope === "machine" && apiKeyId) query.set("apiKeyId", apiKeyId) — which is a self-scope, not a filter: on a standalone hub the parameter is never sent at all, and on a connected client it cannot be changed to another key.
Consequences:
- On a hub serving several clients, per-key cost and token attribution requires the CLI (
ocx usage --api-key-id <id>) or hand-editing a URL, because the Dashboard has no control for it. - The API Keys page shows a 7-day request count per key but offers no drill-down into that key's usage report.
admissionKind: "environment"and"loopback"traffic is invisible as a category: those rows carry noapiKeyIdby design (admissionFields()insrc/server/auth-cors.ts), so "which part of my spend is unattributed?" cannot be answered from the UI.
What should OpenCodex do?
Add an API-key filter to the Usage page, alongside the existing range and surface controls:
- Key selector. A dropdown listing the configured keys from
GET /api/keys(id,name, maskedprefix) plus explicit entries for the two unattributed admission kinds:environmentandloopback. Default stays "All keys", so the current report is unchanged until the operator picks one. - Server-side filtering, not client-side. The selection is sent as the existing
apiKeyIdquery parameter onGET /api/usage, so the filtered read keeps using the full-scan singleflight path that already exists for filtered requests and never enters therange:surfacecache. For the unattributed kinds, extend the parameter with an explicit admission-kind value (for exampleapiKeyId=@environment) rather than inventing a sentinel key id —apiKeyIdis a lookup key and a synthetic value would collide with a hand-edited config entry. - Honest echo and empty state. The existing
filterecho ({ apiKeyId, matched, ... }) should drive a visible chip naming the active key, and an empty result must read as "no readable rows for this key in this range" rather than as a zero-spend key.usageIncompletemust keep its current meaning. - Connected-client behavior. On a connected client, "this machine's key" remains the only selectable key (the hub's
/api/hub/usageroute pins the caller's own identity and rejects any other), so the control should render read-only there and explain why, instead of offering a selection the hub will refuse. - Entry point from the API Keys page. The per-key usage column should link into Usage with that key preselected, so the existing
requests7dnumber has somewhere to lead.
Example usage or interface
Dashboard, Usage → Report:
Range: [Today] [7d] [30d] [All]
Client: [All] [Codex] [Claude] [Grok]
Key: [All keys ▾] ← new
All keys
ci-agent ocx_data_ab12cd34… 1,204 req
laptop-codex ocx_data_77ff01ab… 318 req
unattributed (environment)
unattributed (loopback)
Equivalent CLI calls that already work today and define the expected numbers:
ocx usage --range 7d --api-key-id ci-agent
ocx usage --range 7d --surface codex --api-key-id ci-agentThe Dashboard filter must return the same totals as these two commands for the same window.
Alternatives or workarounds
ocx usage --api-key-id <id>on the hub host. Correct, but terminal-only and unavailable to an operator working in the Dashboard.- Reading
usage.jsonldirectly or building the URL by hand (/api/usage?range=7d&apiKeyId=...). Works, but nothing in the UI hints the parameter exists, and the cache-key and echo behavior are easy to get wrong by hand. - Per-key isolation via separate OpenCodex instances with their own
OPENCODEX_HOME. That is the workaround described in the closed per-key spend-scope request (feat(spend): per-API-key spend scope (spend.apiKey) and opt-in keys on loopback #6156, closed as not-planned because it was not filed through a template); it multiplies ledgers and processes instead of answering the attribution question in one place.
Additional context
- Backend surface that already exists:
apiKeyIdinPersistedUsageEntry, the filtered aggregate path insrc/server/management/usage-aggregate-cache.ts, and theUsageFilterEchoreturned byprojectUsageSummary. - Related but distinct: [Feature]: Interactive model playground and verification workbench in Hub Dashboard #7288 (interactive model Playground) is about testing a model; this request is about reporting on who spent what. [Feature] Add relay model diagnostics for connectivity, latency, and identity consistency #2834 (relay model diagnostics) is provider connectivity, not per-key attribution.
- The API Keys page and the Usage page are the two surfaces that already know about keys; keeping the selector sourced from
GET /api/keysavoids a second, drifting key roster in the GUI.
Checks
- I searched existing issues and documentation.
- This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
- I removed secrets and personal data.
Activity
Ingwannu commentedon Oct 18, 2026
This needs a small UI/API design before implementation. Reuse the existing API-key attribution/filtering contract and preserve the connected caller's server-enforced key scope; a dashboard selector must not widen it. Keep “all permitted keys”, one concrete key, and unattributed admission kinds as distinct typed states, not string sentinels that can collide with real key IDs. Specify deleted/renamed keys, mixed attributed/unattributed records, combined date/provider/model filters, CSV/export parity, and connected versus standalone behavior. Please attach the proposed interaction and empty/loading/error states for owner review. No data-plane or identity migration is needed for the initial filter.
lidge-jun commentedon Oct 22, 2026
Thank you for the detailed proposal. We're closing this as not planned: it is outside the current priorities, and keeping it open would suggest work that isn't scheduled. The discussion stays here for reference. If you'd like to pursue it, please reopen this or open a new issue with a narrow, opt-in first slice.