Skip to content

Add OpenRouter usage collector to the agents panel - #10824

Closed
Azonnali wants to merge 1 commit into
omacom:quattrofrom
Azonnali:feat/openrouter-usage-collector
Closed

Azonnali wants to merge 1 commit into
omacom:quattrofrom
Azonnali:feat/openrouter-usage-collector

Conversation

@Azonnali

@Azonnali Azonnali commented Sep 8, 2026

Copy link
Copy Markdown

Summary

The agents panel tracks per-subscription usage, but OpenRouter has no tab: the account behind every non-Anthropic, non-Codex backend (opencode, pi via openai-completions, ori) stays invisible, and the widget stays silent for those users (#8270).

This adds bin/omarchy-agent-usage-openrouter, which prints the shared record contract and is picked up automatically by omarchy-agent-usage-update - no panel changes needed.

What it does

  • Token history in two tiers, selected by key type instead of a setting:
    • Any API key: local opencode sessions on the OpenRouter provider (machine-local, with prompt counts, like claude and codex).
    • Management key (OPENROUTER_MANAGEMENT_KEY or managementKey in ~/.config/omarchy/agents/openrouter.json): account-global /activity billing API covering every machine and client (with scope: account and no prompt counts, like fireworks). A 403 falls back to tier 1 silently.
  • Live prepaid balance from GET /api/v1/credits (non-estimated ledger), plus a draining key-limit meter from GET /api/v1/key.
  • Docs: collector table row plus "OpenRouter balance and history" section in the agents README, providers default in manifest.json.
  • Test: test/shell.d/agent-usage-openrouter-scanner-test.sh (15 assertions).

Why related work is not enough

Why there is no OpenCode provider tab

  • Every opencode-provider row bills to cost zero: free and included models with no billing API, no key limits, and no ledger, so the tab could only count tokens while its meters stayed empty.
  • Its model ids are unstable aliases (e.g. big-pickle, hy3-free), which would rot the tokens-by-model breakdown.
  • A harness is not a billing account: the same tokens already surface under Codex and OpenRouter tabs, so a harness tab would double-count spend no sync scope could resolve.

Validation

  • New scanner test: 15 assertions green.
  • Existing suites green: agent-usage-update, agents-panel, plugin-validate, manifest-entrypoints.
  • git diff --check clean; live run verified (balance plus today tokens in the panel).

Built with Muse Spark 1.3 (Meta) in OpenCode against the OpenRouter API.

Problem:
- The agents panel tracks per-subscription usage, but OpenRouter
  has no tab.
- OpenRouter is the account behind every non-Anthropic, non-Codex
  backend (opencode, pi via openai-completions, ori), so its spend
  stays invisible and the widget stays silent for those users
  (omacom#8270).

What this adds:
- New collector bin/omarchy-agent-usage-openrouter, printing the
  shared record contract; picked up automatically by
  omarchy-agent-usage-update with no panel changes.
- Token history in two tiers, selected by key type instead of a
  setting:
  - Any API key: local opencode sessions (machine-local, with
    prompt counts, like claude and codex).
  - Management key: account-global /activity billing API (with
    scope account and no prompt counts, like fireworks).
- Live prepaid balance from /credits plus a draining key-limit
  meter from /key on keys that carry a limit.
- Docs: collector table row plus "OpenRouter balance and history"
  section in the agents README, providers default in manifest.json.
- Test: test/shell.d/agent-usage-openrouter-scanner-test.sh.

Why related work is not enough:
- Merged omacom#7709 (Ori as default agent) wires only the ori launcher
  (ori code) and ships no usage collector, so the panel still shows
  nothing for OpenRouter spend.
- Open omacom#8270 (pi on OpenRouter invisible) describes the symptom;
  this adds the missing account tab rather than pi attribution.
- Open omacom#10330 (dedicated pi collector) counts pi transcripts per
  backend locally, with no account balance and no cross-client
  history, which is what /activity provides here.
- Open omacom#8649 (Grok/OMP collectors) and closed omacom#6899 (Hermes
  collector) cover other harnesses and report no OpenRouter
  credits.

Why there is no OpenCode provider tab:
- Every opencode-provider row bills to cost zero: free and included
  models with no billing API, no key limits, and no ledger, so the
  tab could only count tokens while its meters stayed empty.
- Its model ids are unstable aliases (e.g. big-pickle, hy3-free),
  which would rot the tokens-by-model breakdown.
- A harness is not a billing account: the same tokens already
  surface under Codex and OpenRouter tabs, so a harness tab would
  double-count spend no sync scope could resolve.

Validation:
- test/shell.d/agent-usage-openrouter-scanner-test.sh:
  15 assertions green.
- Existing suites green: agent-usage-update, agents-panel,
  plugin-validate, manifest-entrypoints.
- git diff --check clean; live run verified (balance plus
  today tokens in the panel).

Built with Muse Spark 1.3 (Meta) in OpenCode against the
OpenRouter API.
@dhh

dhh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thank you! Brought in with your authorship in #14039, reindented to two spaces, with timeouts falling back to local stats and the last key-limit meter, and a management key alone now enough for history and balance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants