fix(providers): register openrouter rerank provider (#6574)#6681
fix(providers): register openrouter rerank provider (#6574)#6681diegosouzapw wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
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.
| 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)" }, | ||
| ], | ||
| }, |
There was a problem hiding this comment.
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.
| 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)" }, | |
| ], | |
| }, |
|
⏸️ 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 |
Summary
openrouterwas never registered inRERANK_PROVIDERS(open-sse/config/rerankRegistry.ts), soparseRerankModel('openrouter/cohere/rerank-4-pro')returnedprovider: nullandsrc/app/api/v1/rerank/route.tsthrew a generic 400Invalid rerank modelbefore ever attempting an upstream fetch. Same failure class as #5332 (siliconflow/deepinfra) — the slash-splitting logic inparseRerankModel()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'sRERANK_PROVIDERSobject had noopenrouterkey. OpenRouter's live/api/v1/modelscatalog does not expose rerank models (confirmed via direct curl — 345 models returned, 0 containrerank), even though OpenRouter genuinely serves rerank models through a separatePOST /api/v1/rerankendpoint (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 waycohere/together/nvidia/fireworks/voyage-ai/jina-ai/siliconflow/deepinfraalready are.Fix
Added an
openrouterentry toRERANK_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-procohere/rerank-4-fastcohere/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 onorigin/release/v3.8.47tip before the fix (3/3 failing:parseRerankModelreturnsprovider:null,getRerankProvider('openrouter')returnsnull,openrouter/cohere/rerank-4-promissing fromgetAllRerankModels()), GREEN after the registry entry landed.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 unrelatedomniglyphmodule-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.This fix registers the provider + seeds the model catalog, and is validated by the unit-level TDD repro test above (which proves registration +
provider/modelparsing). It does not validate the actual live OpenRouter/api/v1/rerankrequest/response shape against our default Cohere-compatible transform inopen-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:If the response shape differs from the default Cohere passthrough (e.g. field names/nesting), add a dedicated
openrouterformat adapter intransformResponseFromProvider()inopen-sse/handlers/rerank.ts, the same waynvidia/deepinfraalready have one, before merging — or after merging as an immediate fast-follow if the shape is close enough to ship and iterate.Citations
open-sse/config/rerankRegistry.ts:11-107(RERANK_PROVIDERS— noopenrouterkey, pre-fix)src/app/api/v1/rerank/route.ts:181-184(the actual 400 throw site, reached with zerofetch()calls)tests/unit/rerank-providers-5332.test.ts(precedent regression test, same failure class)