feat: Add OpenRouter provider for credit-based usage tracking#298
feat: Add OpenRouter provider for credit-based usage tracking#298chountalas wants to merge 2 commits intosteipete:mainfrom
Conversation
Adds OpenRouter as a new provider that tracks credit usage via their API. Features: - Fetches credits from /api/v1/credits endpoint - Shows credit usage percentage and remaining balance - Supports OPENROUTER_API_KEY environment variable - Settings UI for API key configuration New files: - OpenRouterProviderDescriptor.swift - Provider descriptor + fetch strategy - OpenRouterUsageStats.swift - API fetcher + response models - OpenRouterSettingsReader.swift - Environment variable reader - OpenRouterProviderImplementation.swift - UI implementation - OpenRouterSettingsStore.swift - Settings extension - ProviderIcon-openrouter.svg - Provider icon - docs/openrouter.md - Provider documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75d528dc3b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| private static func resolveToken(environment: [String: String]) -> String? { | ||
| ProviderTokenResolver.openRouterToken(environment: environment) |
There was a problem hiding this comment.
Use stored API key for OpenRouter fetch
This strategy only resolves the token from context.env via ProviderTokenResolver.openRouterToken, which reads OPENROUTER_API_KEY. The UI stores the key in config.json (OpenRouterSettingsStore), but ProviderConfigEnvironment.applyAPIKeyOverride doesn’t map .openrouter, so the saved key never reaches context.env. As a result, users who configure the API key in Settings (and don’t export the env var) will see the provider marked available but every fetch fails with missingToken.
Useful? React with 👍 / 👎.
Added .openrouter case to all switch statements that iterate over UsageProvider to fix compilation errors: - CostUsageScanner.swift (returns empty report) - TokenAccountCLI.swift (returns nil settings) - CodexBarWidgetProvider.swift (not yet supported in widgets) - CodexBarWidgetViews.swift (short label + color) - ProviderImplementationRegistry.swift (implementation registration) - UsageStore.swift (debug log output) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Adds OpenRouter as a new provider that tracks credit usage via their API.
/api/v1/creditsendpointOPENROUTER_API_KEYenvironment variableNew Files
CodexBarCore:
Providers/OpenRouter/OpenRouterProviderDescriptor.swift- Provider descriptor + fetch strategyProviders/OpenRouter/OpenRouterUsageStats.swift- API fetcher + response modelsProviders/OpenRouter/OpenRouterSettingsReader.swift- Environment variable readerCodexBar:
Providers/OpenRouter/OpenRouterProviderImplementation.swift- UI implementationProviders/OpenRouter/OpenRouterSettingsStore.swift- Settings extensionResources/ProviderIcon-openrouter.svg- Provider iconDocs:
docs/openrouter.md- Provider documentationModified Files
Providers.swift- Addedopenroutercase to enumsProviderDescriptor.swift- Registered descriptorProviderTokenResolver.swift- Added token resolutionUsageFetcher.swift- AddedopenRouterUsagepropertyLogCategories.swift- Added log categoryREADME.md&docs/providers.md- Updated provider listsTest plan
swift buildOPENROUTER_API_KEYenv varcodexbar --provider openrouter🤖 Generated with Claude Code