Skip to content

feat(provider): add openrouter#63

Merged
bzp2010 merged 1 commit into
mainfrom
bzp/feat-openrouter-provider
Apr 26, 2026
Merged

feat(provider): add openrouter#63
bzp2010 merged 1 commit into
mainfrom
bzp/feat-openrouter-provider

Conversation

@bzp2010
Copy link
Copy Markdown
Collaborator

@bzp2010 bzp2010 commented Apr 26, 2026

Summary by CodeRabbit

  • New Features
    • Added OpenRouter as a new supported provider type, allowing users to configure OpenRouter for model management and API interactions.
    • OpenRouter provider configurations now support API key authentication and optional custom base URLs.
    • Updated provider selection menus in both model and provider management interfaces to include OpenRouter.
    • Added OpenRouter translations in English and Chinese language packs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

📝 Walkthrough

Walkthrough

The pull request adds support for a new "openrouter" provider type across the backend and UI layers, including JSON schema updates, Rust configuration models, provider gateway implementation, proxy authentication handling, and localization strings in English and Chinese.

Changes

Cohort / File(s) Summary
Schema & Type Definitions
src/config/entities/providers-schema.json, src/config/entities/providers.rs
Extended JSON schema and Rust ProviderConfig enum to recognize "openrouter" as a valid provider type, routed to OpenAI-compatible configuration validation. Added enum variant and provider type matching.
Provider Gateway Implementation
src/gateway/providers/openrouter.rs, src/gateway/providers/mod.rs
Created new OpenRouter provider module with IDENTIFIER constant, config struct with api_key and optional api_base, and provider! macro setup. Updated provider module registry to expose and register OpenRouter alongside existing providers.
Proxy Authentication
src/proxy/provider.rs
Extended provider_auth_and_base_url helper to handle ProviderConfig::OpenRouter, extracting API key and parsing optional base URL override.
UI Type Definitions
ui/src/lib/api/types.ts
Refactored ProviderType from hardcoded union to dynamic const array (PROVIDER_TYPE_VARIANTS) that includes 'openrouter'. Added OpenRouter discriminated union variant to Provider type with ApiBaseProviderConfig.
UI Components & Forms
ui/src/components/providers/provider-form.tsx
Updated provider type selector to source options from PROVIDER_TYPE_VARIANTS array instead of hardcoded list.
Localization
ui/src/i18n/locales/en.json, ui/src/i18n/locales/zh-CN.json
Added "OpenRouter" display strings in English and Chinese locales under model form providers and provider form types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Security Check ❌ Error OpenRouterProviderConfig derives Debug without custom redaction for the api_key field, while BedrockProviderConfig demonstrates the correct pattern with credential redaction. Implement custom impl fmt::Debug for OpenRouterProviderConfig to redact the api_key field, following the established pattern in BedrockProviderConfig.
E2e Test Quality Review ⚠️ Warning PR contains assertion formatting violations and lacks comprehensive E2E test coverage for actual API operations. Convert assert_eq! to pretty_assertions::assert_eq! in specified files and add E2E integration tests for complete request-response cycles, error handling, and edge cases.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(provider): add openrouter' accurately summarizes the main change—adding OpenRouter provider support across multiple layers of the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/feat-openrouter-provider

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/gateway/providers/mod.rs (1)

41-50: Add tracing to this public function.

default_provider_registry is public but currently missing #[fastrace::trace].

Suggested patch
+#[fastrace::trace]
 pub fn default_provider_registry() -> Result<ProviderRegistry> {

As per coding guidelines "src/**/*.rs: Use #[fastrace::trace] decorator for distributed tracing on public functions".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gateway/providers/mod.rs` around lines 41 - 50, The public function
default_provider_registry is missing the #[fastrace::trace] attribute required
for distributed tracing; add the #[fastrace::trace] attribute directly above the
pub fn default_provider_registry() -> Result<ProviderRegistry> declaration
(keeping the function public and unchanged) so the function and its
builder/register calls (AnthropicDef, AzureDef, BedrockDef, DeepSeek, GoogleDef,
OpenAIDef, OpenRouter, and ProviderRegistry::builder) are traced; ensure the
fastrace crate is available in scope (crate features/imports) if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/gateway/providers/mod.rs`:
- Line 67: Replace the standard assert_eq! used in the test with
pretty_assertions::assert_eq! so test failures show unified diffs; specifically
change the assertion comparing registry.get("openrouter").unwrap().name() to use
pretty_assertions::assert_eq! (or add a top-level `use
pretty_assertions::assert_eq;` and keep the call as assert_eq!) to locate the
improved macro while leaving the rest of the test unchanged.

In `@src/proxy/provider.rs`:
- Around line 206-220: Replace the two standard assert_eq! calls inside the test
function
provider_auth_and_base_url_returns_openrouter_api_key_and_optional_base_url with
pretty_assertions::assert_eq! so the test uses pretty_assertions for better diff
output (update both assertions that compare auth.api_key_for("openrouter") and
base_url_override.as_ref().map(Url::as_str) accordingly).

---

Nitpick comments:
In `@src/gateway/providers/mod.rs`:
- Around line 41-50: The public function default_provider_registry is missing
the #[fastrace::trace] attribute required for distributed tracing; add the
#[fastrace::trace] attribute directly above the pub fn
default_provider_registry() -> Result<ProviderRegistry> declaration (keeping the
function public and unchanged) so the function and its builder/register calls
(AnthropicDef, AzureDef, BedrockDef, DeepSeek, GoogleDef, OpenAIDef, OpenRouter,
and ProviderRegistry::builder) are traced; ensure the fastrace crate is
available in scope (crate features/imports) if needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 764ab87f-c8f3-45c4-9bf9-bd25cde9a5b0

📥 Commits

Reviewing files that changed from the base of the PR and between 1a6acb4 and efbc18f.

📒 Files selected for processing (9)
  • src/config/entities/providers-schema.json
  • src/config/entities/providers.rs
  • src/gateway/providers/mod.rs
  • src/gateway/providers/openrouter.rs
  • src/proxy/provider.rs
  • ui/src/components/providers/provider-form.tsx
  • ui/src/i18n/locales/en.json
  • ui/src/i18n/locales/zh-CN.json
  • ui/src/lib/api/types.ts

Comment thread src/gateway/providers/mod.rs
Comment thread src/proxy/provider.rs
@bzp2010 bzp2010 merged commit f792b7e into main Apr 26, 2026
10 checks passed
@bzp2010 bzp2010 deleted the bzp/feat-openrouter-provider branch April 26, 2026 12:30
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