Skip to content

feat(openrouter): switch model usage stats from Anthropic Admin API to OpenRouter (closes #25) - #33

Open
NOVA-Openclaw wants to merge 2 commits into
mainfrom
feature/issue-25-openrouter-usage
Open

feat(openrouter): switch model usage stats from Anthropic Admin API to OpenRouter (closes #25)#33
NOVA-Openclaw wants to merge 2 commits into
mainfrom
feature/issue-25-openrouter-usage

Conversation

@NOVA-Openclaw

Copy link
Copy Markdown
Owner

Summary

Closes #25. Replaces the Anthropic Admin API data flow with an OpenRouter-based one, since all model traffic now routes through OpenRouter.

Changes

  • scripts/update-dashboard.sh: New update_openrouter function replaces update_anthropic. Fetches GET /api/v1/credits using OPENROUTER_API_KEY. Appends snapshots to logs/openrouter-snapshots.jsonl and derives MTD + daily series from snapshot deltas. Output is openrouter.json with an anthropic.json back-compat copy.
  • dashboard/index.html: Section title renamed to "OpenRouter"; loadAnthropic() fetches openrouter.json (function name kept for minimal churn).
  • tests/test-update-dashboard.sh: Flipped optional-output check from anthropic.json to openrouter.json.

Test plan

  • Ran bash tests/test-update-dashboard.sh on the branch: 19 passed, 0 failed.
  • Manual run against /tmp/dashboard-test/ produced valid openrouter.json with totalSpend=3361.28 from /credits.

Notes / follow-ups

  • /credits only gives cumulative totals, so MTD and the daily series start near 0 and fill in as the cron runs. After one month of snapshots it has parity with the old flow.
  • Richer per-day / per-model data is available via /activity, but that requires an OpenRouter management key. Can be added later without a schema break (null fields are already in place for inputTokens, outputTokens, cacheHitRate).
  • scripts/update-anthropic-dashboard.sh is left in place for one release but is no longer invoked by cron.

NOVA added 2 commits April 23, 2026 03:07
…o OpenRouter (closes #25)

We no longer hit the Anthropic API directly — all model usage is routed through
OpenRouter. This replaces the Anthropic cost-report data pipeline with an
OpenRouter-based one while keeping the existing dashboard layout and schema
mostly intact.

Script changes (scripts/update-dashboard.sh):
- Replace update_anthropic with update_openrouter.
- Fetch GET https://openrouter.ai/api/v1/credits (total_credits, total_usage)
  using the existing OPENROUTER_API_KEY env var (no 1Password / management
  key required).
- Append every successful update to logs/openrouter-snapshots.jsonl.
- Derive MTD spend and per-day daily series from the snapshot log by diffing
  total_usage between the first snapshot of each UTC day and the next day's
  first snapshot (current day diffs against the live total_usage).
- All-time spend comes straight from total_usage; totalCredits is added under
  allTime for visibility.
- Per-hour cost math (active + wall clock) is preserved using
  session-activity.jsonl.
- Output file is now openrouter.json. anthropic.json is also written as a
  byte-identical back-compat copy so anything still fetching it keeps working.
- Throttle and subshell isolation behavior unchanged (15-min self-throttle).

Frontend changes (dashboard/index.html):
- Section title: 'Anthropic API' → 'OpenRouter'.
- loadAnthropic() now fetches openrouter.json (back-compat file still present
  as a safety net). Function name preserved to keep the rest of the JS calling
  into the same symbol.

Tests (tests/test-update-dashboard.sh):
- Flipped the optional-output check from anthropic.json to openrouter.json,
  with updated skip-reason wording (OPENROUTER_API_KEY instead of 1Password +
  Admin API key).

Notes / limitations:
- The /credits endpoint only exposes cumulative usage. Until we have a history
  of snapshots, MTD and daily values start at 0 and fill in as the cron keeps
  running. After one month of snapshots the dashboard will have full daily
  resolution comparable to the old Anthropic flow.
- The /activity endpoint would give richer per-day/per-model breakdowns but
  requires an OpenRouter management key, which we don't currently provision
  from cron. Can be added later without a schema break (inputTokens /
  outputTokens / cacheHitRate are already present and nullable).
- The legacy scripts/update-anthropic-dashboard.sh is left in place for one
  release; it's no longer invoked from cron (the consolidated updater runs
  update_openrouter).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch model usage statistics collection from Anthropic to OpenRouter

1 participant