Skip to content

fix(providers): register openrouter rerank provider (#6574)#6681

Open
diegosouzapw wants to merge 1 commit into
release/v3.8.47from
fix/6574-rerank-openrouter
Open

fix(providers): register openrouter rerank provider (#6574)#6681
diegosouzapw wants to merge 1 commit into
release/v3.8.47from
fix/6574-rerank-openrouter

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

openrouter was never registered in RERANK_PROVIDERS (open-sse/config/rerankRegistry.ts), so parseRerankModel('openrouter/cohere/rerank-4-pro') returned provider: null and src/app/api/v1/rerank/route.ts threw a generic 400 Invalid rerank model before ever attempting an upstream fetch. Same failure class as #5332 (siliconflow/deepinfra) — the slash-splitting logic in parseRerankModel() was already correct and multi-segment-safe; the fix is purely an additive static registry entry.

Fixes #6574.

Root cause

open-sse/config/rerankRegistry.ts's RERANK_PROVIDERS object had no openrouter key. OpenRouter's live /api/v1/models catalog does not expose rerank models (confirmed via direct curl — 345 models returned, 0 contain rerank), even though OpenRouter genuinely serves rerank models through a separate POST /api/v1/rerank endpoint (confirmed live: openrouter.ai/cohere/rerank-4-pro, /cohere/rerank-4-fast, /cohere/rerank-v3.5). Because there's no discovery feed, these models must be statically seeded into the registry, the same way cohere/together/nvidia/fireworks/voyage-ai/jina-ai/siliconflow/deepinfra already are.

Fix

Added an openrouter entry to RERANK_PROVIDERS (Cohere-compatible passthrough format, baseUrl: https://openrouter.ai/api/v1/rerank), seeded with the three model ids independently confirmed live on openrouter.ai:

  • cohere/rerank-4-pro
  • cohere/rerank-4-fast
  • cohere/rerank-v3.5

(nvidia/llama-nemotron-rerank-vl-1b-v2:free, named by the reporter, was not included — only confirmed on HuggingFace/NVIDIA's build hub, not independently verified live on openrouter.ai per the triage plan-file.)

Test plan (TDD, Hard Rule #18)

  • tests/unit/rerank-openrouter-6574.test.ts — proven RED on origin/release/v3.8.47 tip before the fix (3/3 failing: parseRerankModel returns provider:null, getRerankProvider('openrouter') returns null, openrouter/cohere/rerank-4-pro missing from getAllRerankModels()), GREEN after the registry entry landed.
  • Sibling regression test tests/unit/rerank-providers-5332.test.ts (same failure class, siliconflow/deepinfra) re-run — 7/7 still passing, no regression.
  • node scripts/check/check-file-size.mjs — OK (rerankRegistry.ts stayed under its cap).
  • node scripts/check/check-complexity.mjs — OK (2052 violations vs baseline 2053, no regression).
  • node scripts/check/check-cognitive-complexity.mjs — OK (884 vs baseline 884, no regression).
  • npm run typecheck:core — clean except the pre-existing unrelated omniglyph module-resolution error.
  • npx eslint --suppressions-location config/quality/eslint-suppressions.json open-sse/config/rerankRegistry.ts tests/unit/rerank-openrouter-6574.test.ts — clean.
  • node scripts/check/check-changelog-integrity.mjs — OK.

⚠️ Pre-merge: needs live smoke test

This fix registers the provider + seeds the model catalog, and is validated by the unit-level TDD repro test above (which proves registration + provider/model parsing). It does not validate the actual live OpenRouter /api/v1/rerank request/response shape against our default Cohere-compatible transform in open-sse/handlers/rerank.ts, because I do not have a live OpenRouter API key.

Before merging, the operator should run a real smoke test with a valid OPENROUTER_API_KEY:

curl -s https://openrouter.ai/api/v1/rerank \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "What is the capital of France?",
    "documents": ["Paris is the capital of France.", "Berlin is the capital of Germany."]
  }'

If the response shape differs from the default Cohere passthrough (e.g. field names/nesting), add a dedicated openrouter format adapter in transformResponseFromProvider() in open-sse/handlers/rerank.ts, the same way nvidia/deepinfra already have one, before merging — or after merging as an immediate fast-follow if the shape is close enough to ship and iterate.

Citations

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request registers OpenRouter as a rerank provider in the registry and adds corresponding unit tests. The reviewer identified an issue where OpenRouter's response format for usage metrics differs from Cohere's standard, which would cause cost calculations to fail and fall back to zero. They suggested adding a custom format configuration to enable proper response transformation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +98 to +108
openrouter: {
id: "openrouter",
baseUrl: "https://openrouter.ai/api/v1/rerank",
authType: "apikey",
authHeader: "bearer",
models: [
{ id: "cohere/rerank-4-pro", name: "Cohere Rerank 4 Pro (via OpenRouter)" },
{ id: "cohere/rerank-4-fast", name: "Cohere Rerank 4 Fast (via OpenRouter)" },
{ id: "cohere/rerank-v3.5", name: "Cohere Rerank v3.5 (via OpenRouter)" },
],
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Based on OpenRouter's official documentation, the response format for their /api/v1/rerank endpoint returns usage metrics under usage.search_units instead of Cohere's standard meta.billed_units.search_units:

{
  "id": "gen-rerank-1234567890-abc",
  "model": "cohere/rerank-v3.5",
  "results": [...],
  "usage": {
    "search_units": 1,
    "total_tokens": 150
  }
}

Because of this difference, result?.meta?.billed_units?.search_units in open-sse/handlers/rerank.ts (line 184) will resolve to undefined, causing the cost calculation to fall back to 0.

To address this, we should define a custom format: "openrouter" here, and then implement a corresponding response transformer in open-sse/handlers/rerank.ts to map usage.search_units to meta.billed_units.search_units.

Suggested change
openrouter: {
id: "openrouter",
baseUrl: "https://openrouter.ai/api/v1/rerank",
authType: "apikey",
authHeader: "bearer",
models: [
{ id: "cohere/rerank-4-pro", name: "Cohere Rerank 4 Pro (via OpenRouter)" },
{ id: "cohere/rerank-4-fast", name: "Cohere Rerank 4 Fast (via OpenRouter)" },
{ id: "cohere/rerank-v3.5", name: "Cohere Rerank v3.5 (via OpenRouter)" },
],
},
openrouter: {
id: "openrouter",
baseUrl: "https://openrouter.ai/api/v1/rerank",
authType: "apikey",
authHeader: "bearer",
format: "openrouter",
models: [
{ id: "cohere/rerank-4-pro", name: "Cohere Rerank 4 Pro (via OpenRouter)" },
{ id: "cohere/rerank-4-fast", name: "Cohere Rerank 4 Fast (via OpenRouter)" },
{ id: "cohere/rerank-v3.5", name: "Cohere Rerank v3.5 (via OpenRouter)" },
],
},

@diegosouzapw

Copy link
Copy Markdown
Owner Author

⏸️ Merge on hold pending a live smoke test. The fix (registering OpenRouter as a rerank provider) is unit-tested and green, but the request/response shape of OpenRouter's rerank endpoint hasn't been validated against the live API — per Hard Rule #18 we don't merge a provider integration on docs alone. Merge unblocks once a real POST https://openrouter.ai/api/v1/rerank (e.g. model cohere/rerank-v3.5) confirms the default Cohere-compatible transform matches; if it diverges, an openrouter adapter goes in transformResponseFromProvider() first. See the PR body for the exact command.

@diegosouzapw diegosouzapw added the hold-vps PR verde, merge aguardando validação live (release-drain) label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hold-vps PR verde, merge aguardando validação live (release-drain)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant