feat: add OpenRouter provider for credit/usage monitoring#44
Merged
prakersh merged 1 commit intoonllm-dev:mainfrom Mar 29, 2026
Merged
Conversation
Add OpenRouter as a new provider for tracking API credit usage, daily/weekly/monthly spending, and rate limits. Polls GET /api/v1/auth/key for usage data including: - Total usage (USD) - Daily/weekly/monthly usage breakdowns - Credit limit and remaining balance (when configured) - Rate limit info - Free tier detection Implementation follows the existing provider pattern (Z.ai/MiniMax): - internal/api/openrouter_client.go: HTTP client with Bearer auth - internal/api/openrouter_types.go: Response structs and snapshot type - internal/store/openrouter_store.go: SQLite storage and cycle tracking - internal/tracker/openrouter_tracker.go: Delta tracking and projections - internal/agent/openrouter_agent.go: Polling agent Integration points: - Config: OPENROUTER_API_KEY env var - Dashboard: Provider tab with usage cards and charts - Auto-detection: Uses env var (no local auth file) Env var: OPENROUTER_API_KEY
prakersh
approved these changes
Mar 29, 2026
Contributor
prakersh
left a comment
There was a problem hiding this comment.
Backend implementation is solid - follows existing provider patterns, parameterized SQL, proper API key redaction, bounded queries. Frontend needs OpenRouter-specific branches in dashboard.html and app.js - will fix in a follow-up.
6 tasks
Contributor
|
Thanks for this contribution @omnissiah-comelse! The backend implementation was solid - clean provider pattern, parameterized SQL, proper key redaction. We've added the frontend integration in #48 (Credits quota card, usage charts, cycle overview, and menubar support). If onWatch has been useful to you, we'd appreciate a star on the repo - it helps others discover the project! |
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
Adds OpenRouter as a new provider for tracking API credit usage, spending rates, and rate limits.
What it does
Polls
GET /api/v1/auth/keyto track:Why
OpenRouter is widely used by developers running multi-model setups (Claude, GPT, Llama, Mistral, etc.) through a single API. There's currently no way to monitor OpenRouter quota/spending in onWatch — this fills that gap.
Implementation
Follows the existing provider pattern (Z.ai / MiniMax):
internal/api/openrouter_client.gointernal/api/openrouter_types.gointernal/store/openrouter_store.gointernal/tracker/openrouter_tracker.gointernal/agent/openrouter_agent.goIntegration points modified:
internal/config/config.go—OPENROUTER_API_KEYenv var +HasProvider()internal/store/store.go— Schema tables + indexesinternal/web/handlers.go— Dashboard endpoints (current, history, cycles, insights, sessions)main.go— Client/tracker/agent wiring + banner display.env.example— New env var entryTesting
go build ./...— cleango vet ./...— cleanDashboard
The OpenRouter tab shows:
Configuration
No auto-detection — requires explicit API key in
.envor environment.