fix: add runtime reranking model support#509
Conversation
There was a problem hiding this comment.
Perry's Review
Adds runtime support for rerankingModel() on the OpenRouter provider — a new RerankingModelV3 implementation, its response schema, settings type, provider wiring, and unit tests.
Verdict: 💬 Comments / questions
Details
Risk: 🟡 Medium
CI: all passing ✅ (verified locally: tsc --noEmit clean, 430/430 vitest pass incl. 3 new reranking tests, biome clean)
Findings (see inline comments):
- 🟡 src/reranking/index.ts:90 — provider metadata hardcoded to empty string; sibling embedding model reads it from the response
- 🟡 .changeset/reranking-runtime-provider.md:2 — patch bump for a new public API; repo precedent (#479 videoModel) used minor
Blast radius: purely additive. New src/reranking/ module + one provider wiring line + one barrel re-export. No existing request path, auth flow, or billing logic touched. Implementation mirrors the embedding/image/video siblings 1:1 (config shape, postJsonToApi call, metadata parse, warnings: []). Verified RerankingModelV3 and ProviderV3.rerankingModel exist in @ai-sdk/provider 3.0.8 and the doRerank return shape matches the interface.
Security: no concerns — no new auth/credential handling; reuses the shared getHeaders + extraBody passthrough.
Test coverage: good — covers provider method exposure, instance creation, and a full doRerank round-trip asserting URL, request body mapping (top_n, documents), ranking transform, and cost metadata.
Unresolved threads: none
Review: tier=medium · model=claude-opus-latest · score=5.6
| })), | ||
| providerMetadata: { | ||
| openrouter: OpenRouterProviderMetadataSchema.parse({ | ||
| provider: '', |
There was a problem hiding this comment.
[suggestion] provider: '' hardcodes the provider name to empty — the sibling embedding model reads it from the response instead.
| provider: '', | |
| provider: responseValue.provider ?? '', |
Details
Why: Every other model in this provider surfaces the upstream provider slug in providerMetadata.openrouter.provider (e.g. src/embedding/index.ts:95 does provider: responseValue.provider ?? ''). Here it is pinned to '', so callers can never tell which upstream provider (cohere, jina, etc.) actually served the rerank — useful signal that the rest of the SDK exposes consistently.
The rerank response schema (src/reranking/schemas.ts) uses .passthrough(), so a provider field returned by the API is already preserved on responseValue at runtime; the only missing piece is surfacing it. If the API does not return provider on /rerank, the ?? '' fallback keeps current behaviour, so the change is safe either way. Optionally add provider: z.string().optional() to the schema to make the field explicit.
Reviewed at bd948de
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@openrouter/ai-sdk-provider": patch | |||
There was a problem hiding this comment.
[suggestion] Changeset is marked patch — a new public API method is conventionally a minor bump.
| "@openrouter/ai-sdk-provider": patch | |
| "@openrouter/ai-sdk-provider": minor |
Details
Why: This PR adds a brand-new public surface — provider.rerankingModel() and the exported OpenRouterRerankingModel / OpenRouterRerankingSettings types. Per semver, new backwards-compatible API additions are minor, not patch. The most recent comparable change in this repo — #479, which added provider.videoModel() — shipped as a Minor changeset (see CHANGELOG.md). Marking this patch means the new method lands in a patch release, which under-signals the feature to consumers pinning on ~ ranges.
Non-blocking: if the maintainers intentionally batch feature additions into patch releases for this package, disregard.
Reviewed at bd948de
Summary
rerankingModel()factory tocreateOpenRouter()OpenRouterRerankingModelfor AI SDK v3 reranking calls/rerankresponses into AI SDKrankingresultsCloses #500
Testing
pnpm typecheckpnpm vitest --config vitest.node.config.ts --run src/reranking/index.test.tspnpm stylecheckpnpm build