Phase 1 · Batch 1: Read-only Usage Core — runtime usage service, schemas, API endpoint #30

Closed
opened 2026-05-20 19:48:53 -05:00 by null · 1 comment
Owner

Outcome

Mission Control can compute model usage, cost, and time remaining from OpenClaw runtime data.

Scope

  • Add backend/app/services/openclaw/runtime_usage.py
  • Add backend/app/schemas/runtime_usage.py (response models)
  • Add API route: GET /api/v1/gateways/{gateway_id}/runtime-usage
  • Wire router in backend/app/main.py if new router file created
  • Add tests under backend/tests/test_runtime_usage*.py

Implementation Details

  • Provider/model normalization and cost calculation using typed Python helpers
  • Config-backed pricing with defaults + override file/env setting
  • Account/source normalization (multiple Claude, OpenAI, Ollama accounts kept separate)
  • Parse session JSONL defensively: skip malformed lines, ignore messages without usage, preserve unknown models as zero-cost with token counts
  • 5-hour and 7-day windows, per-model totals, current burn rate, reset time, top sessions
  • account_key derived from gateway config, environment/profile name, or explicit MC mapping
  • Never expose raw API keys or secrets in usage payloads
  • Mark unpriced local models as unpriced=false, cost_usd=0; mark unknown paid models as unpriced=true

Data Contract

See docs/runtime-usage-dashboard-plan.md → Proposed Data Contract section for the response schema.

Open Questions (must resolve before implementation)

  1. Gateway-scoped endpoint vs organization-wide aggregation?
  2. Where should pricing overrides live: backend settings, DB table, or checked-in JSON config?
  3. Should non-admin users see costs, or are costs admin-only?
  4. Time remaining tracks: output tokens only, total tokens, calls, cost, or provider-specific limit profile?
  5. Historical persistence in MC, or on-demand JSONL parsing sufficient for v1?

Reference

  • openclaw-dashboard server.js: DEFAULT_MODEL_PRICING, loadModelPricing, normalizeProvider, normalizeModel, estimateMsgCost, isSessionFile, extractSessionId, getSessionCost, getCostData, getUsageWindows
  • data/model_pricing_usd_per_million.json

Depends On

None — this is the first slice.

Labels

phase-1, backend, priority-high

## Outcome Mission Control can compute model usage, cost, and time remaining from OpenClaw runtime data. ## Scope - Add `backend/app/services/openclaw/runtime_usage.py` - Add `backend/app/schemas/runtime_usage.py` (response models) - Add API route: `GET /api/v1/gateways/{gateway_id}/runtime-usage` - Wire router in `backend/app/main.py` if new router file created - Add tests under `backend/tests/test_runtime_usage*.py` ## Implementation Details - Provider/model normalization and cost calculation using typed Python helpers - Config-backed pricing with defaults + override file/env setting - Account/source normalization (multiple Claude, OpenAI, Ollama accounts kept separate) - Parse session JSONL defensively: skip malformed lines, ignore messages without usage, preserve unknown models as zero-cost with token counts - 5-hour and 7-day windows, per-model totals, current burn rate, reset time, top sessions - `account_key` derived from gateway config, environment/profile name, or explicit MC mapping - Never expose raw API keys or secrets in usage payloads - Mark unpriced local models as `unpriced=false, cost_usd=0`; mark unknown paid models as `unpriced=true` ## Data Contract See `docs/runtime-usage-dashboard-plan.md` → Proposed Data Contract section for the response schema. ## Open Questions (must resolve before implementation) 1. Gateway-scoped endpoint vs organization-wide aggregation? 2. Where should pricing overrides live: backend settings, DB table, or checked-in JSON config? 3. Should non-admin users see costs, or are costs admin-only? 4. Time remaining tracks: output tokens only, total tokens, calls, cost, or provider-specific limit profile? 5. Historical persistence in MC, or on-demand JSONL parsing sufficient for v1? ## Reference - `openclaw-dashboard` `server.js`: DEFAULT_MODEL_PRICING, loadModelPricing, normalizeProvider, normalizeModel, estimateMsgCost, isSessionFile, extractSessionId, getSessionCost, getCostData, getUsageWindows - `data/model_pricing_usd_per_million.json` ## Depends On None — this is the first slice. ## Labels phase-1, backend, priority-high
Author
Owner

Verification complete. Issue #30 accurately reflects the Batch 1 scope from docs/runtime-usage-dashboard-plan.md. All files listed, data contract matches, open questions captured, dependencies correct. No discrepancies found.

✅ Verification complete. Issue #30 accurately reflects the Batch 1 scope from docs/runtime-usage-dashboard-plan.md. All files listed, data contract matches, open questions captured, dependencies correct. No discrepancies found.
null closed this issue 2026-05-20 20:14:21 -05:00
Sign in to join this conversation.
No description provided.