Skip to content

Conversation

@chountalas
Copy link

Summary

Adds OpenRouter as a new provider that tracks credit usage via their API.

  • 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

CodexBarCore:

  • Providers/OpenRouter/OpenRouterProviderDescriptor.swift - Provider descriptor + fetch strategy
  • Providers/OpenRouter/OpenRouterUsageStats.swift - API fetcher + response models
  • Providers/OpenRouter/OpenRouterSettingsReader.swift - Environment variable reader

CodexBar:

  • Providers/OpenRouter/OpenRouterProviderImplementation.swift - UI implementation
  • Providers/OpenRouter/OpenRouterSettingsStore.swift - Settings extension
  • Resources/ProviderIcon-openrouter.svg - Provider icon

Docs:

  • docs/openrouter.md - Provider documentation

Modified Files

  • Providers.swift - Added openrouter case to enums
  • ProviderDescriptor.swift - Registered descriptor
  • ProviderTokenResolver.swift - Added token resolution
  • UsageFetcher.swift - Added openRouterUsage property
  • LogCategories.swift - Added log category
  • README.md & docs/providers.md - Updated provider lists

Test plan

  • Build the project with swift build
  • Enable OpenRouter in Settings → Providers
  • Configure API key via Settings or OPENROUTER_API_KEY env var
  • Verify credit balance and usage percentage display correctly
  • Test CLI: codexbar --provider openrouter

🤖 Generated with Claude Code

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>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +68 to +69
private static func resolveToken(environment: [String: String]) -> String? {
ProviderTokenResolver.openRouterToken(environment: environment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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>
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.

1 participant