Skip to content

feat(gateway): add reranking model support#13890

Merged
R-Taneja merged 14 commits intomainfrom
feat/reranker-model-support
Apr 7, 2026
Merged

feat(gateway): add reranking model support#13890
R-Taneja merged 14 commits intomainfrom
feat/reranker-model-support

Conversation

@R-Taneja
Copy link
Copy Markdown
Contributor

@R-Taneja R-Taneja commented Mar 28, 2026

Summary

  • Add GatewayRerankingModel class implementing RerankingModelV4 for the @ai-sdk/gateway package
  • Add rerankingModel() and reranking() methods to GatewayProvider interface and implementation
  • Add GatewayRerankingModelId type (initially cohere/rerank-v3.5)
  • Export new types from package index

This enables users to call rerankers through the AI Gateway:

import { gateway } from '@ai-sdk/gateway';
import { rerank } from 'ai';

const result = await rerank({
  model: gateway.rerankingModel('cohere/rerank-v3.5'),
  query: 'search query',
  documents: ['doc1', 'doc2', 'doc3'],
});

Test plan

  • TypeScript compilation passes
  • GatewayRerankingModel sends requests to /reranking-model endpoint with correct headers
  • rerankingModel() and reranking() methods return valid RerankingModelV4 instances

…rovider support

Add `usage?: { tokens: number }` to the reranking provider spec (V3/V4)
and thread it through the core `rerank()` function and `RerankResult`.

Update Cohere provider to parse `meta.billed_units.input_tokens` and
Together AI provider to return `usage.total_tokens` from responses.

Add `GatewayRerankingModel` class and `rerankingModel()`/`reranking()`
methods to the gateway provider for AI Gateway integration.
@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/cohere Issues related to the @ai-sdk/cohere provider provider/gateway Issues related to the @ai-sdk/gateway provider provider/togetherai Issues related to the @ai-sdk/togetherai provider labels Mar 28, 2026
Cohere's rerank API bills by search_units, not input_tokens.
The response returns `meta.billed_units.search_units` for reranking.
Remove Together AI reranking usage change — keeping this PR focused
on Cohere and gateway provider changes only.
Gateway computes billing from request document count directly,
so provider-level usage extraction is not needed.
Gateway computes billing from request document count, so usage
tracking in the provider spec and core rerank function is not needed.
Align with provider spec which doesn't include usage.
@R-Taneja R-Taneja changed the title feat (reranking): add usage tracking and gateway provider support feat (gateway): add reranking model support Mar 28, 2026
@R-Taneja R-Taneja changed the title feat (gateway): add reranking model support feat(gateway): add reranking model support Mar 28, 2026
Copy link
Copy Markdown
Collaborator

@shaper shaper left a comment

Choose a reason for hiding this comment

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

add a changeset

Copy link
Copy Markdown

@ArshVermaGit ArshVermaGit left a comment

Choose a reason for hiding this comment

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

This PR adds reranking model support to the @ai-sdk/gateway package via the new GatewayRerankingModel implementation. The changes are well-scoped and extend the Gateway provider capabilities in a way that is consistent with existing model abstractions in the AI SDK.
Supporting rerankers through the gateway improves search relevance workflows and aligns with common RAG and retrieval optimization patterns.

…eset

- gateway-reranking-model.test.ts: headers, o11y, ranking extraction,
  request body, providerOptions, error handling, URL construction
- gateway-provider.test.ts: rerankingModel() and reranking() alias
  create correct model instances
- changeset for @ai-sdk/gateway patch
@R-Taneja R-Taneja requested a review from shaper March 30, 2026 17:59
@R-Taneja R-Taneja enabled auto-merge (squash) April 7, 2026 18:34
@R-Taneja R-Taneja merged commit 939171f into main Apr 7, 2026
19 checks passed
@R-Taneja R-Taneja deleted the feat/reranker-model-support branch April 7, 2026 18:37
@R-Taneja R-Taneja added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 7, 2026
vercel-ai-sdk bot pushed a commit that referenced this pull request Apr 7, 2026
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 7, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Apr 7, 2026

⚠️ Backport to release-v6.0 created but has conflicts: #14204

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Apr 7, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.71
@ai-sdk/angular 3.0.0-beta.71
@ai-sdk/gateway 4.0.0-beta.40
@ai-sdk/langchain 3.0.0-beta.71
@ai-sdk/llamaindex 3.0.0-beta.71
@ai-sdk/otel 1.0.0-beta.17
@ai-sdk/react 4.0.0-beta.71
@ai-sdk/rsc 3.0.0-beta.72
@ai-sdk/svelte 5.0.0-beta.71
@ai-sdk/vue 4.0.0-beta.71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/cohere Issues related to the @ai-sdk/cohere provider provider/gateway Issues related to the @ai-sdk/gateway provider provider/togetherai Issues related to the @ai-sdk/togetherai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants