feat(openrouter): switch model usage stats from Anthropic Admin API to OpenRouter (closes #25) - #33
Open
NOVA-Openclaw wants to merge 2 commits into
Open
feat(openrouter): switch model usage stats from Anthropic Admin API to OpenRouter (closes #25)#33NOVA-Openclaw wants to merge 2 commits into
NOVA-Openclaw wants to merge 2 commits into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: Newupdate_openrouterfunction replacesupdate_anthropic. FetchesGET /api/v1/creditsusingOPENROUTER_API_KEY. Appends snapshots tologs/openrouter-snapshots.jsonland derives MTD + daily series from snapshot deltas. Output isopenrouter.jsonwith ananthropic.jsonback-compat copy.dashboard/index.html: Section title renamed to "OpenRouter";loadAnthropic()fetchesopenrouter.json(function name kept for minimal churn).tests/test-update-dashboard.sh: Flipped optional-output check fromanthropic.jsontoopenrouter.json.Test plan
bash tests/test-update-dashboard.shon the branch: 19 passed, 0 failed.openrouter.jsonwithtotalSpend=3361.28from/credits.Notes / follow-ups
/creditsonly 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./activity, but that requires an OpenRouter management key. Can be added later without a schema break (null fields are already in place forinputTokens,outputTokens,cacheHitRate).scripts/update-anthropic-dashboard.shis left in place for one release but is no longer invoked by cron.