The Cohere adapter is rerank-focused. It exposes one capability:
It does not support text chat(), summarize(), embeddings, or media — use OpenAI, Anthropic, or Gemini for those. The adapter talks to Cohere's /v2/rerank endpoint directly over fetch (no SDK dependency).
npm install @tanstack/ai-coherePeer dependency:
npm install @tanstack/aiimport { rerank } from '@tanstack/ai'
import { cohereRerank } from '@tanstack/ai-cohere'
const { rerankedDocuments } = await rerank({
adapter: cohereRerank('rerank-v3.5'),
query: 'talk about rain',
documents: ['sunny day at the beach', 'rainy afternoon in the city'],
})
console.log(rerankedDocuments[0]) // 'rainy afternoon in the city'For the full reranking guide — object documents, RAG pipelines, options, and the result shape — see Reranking.
| Model | Description |
|---|---|
| rerank-v3.5 | Latest multilingual reranker (recommended) |
| rerank-english-v3.0 | English-optimized reranker |
| rerank-multilingual-v3.0 | Multilingual reranker |
cohereRerank(model, config?) reads COHERE_API_KEY from the environment. config accepts:
| Option | Type | Default | Description |
|---|---|---|---|
| baseUrl | string | https://api.cohere.com | Override the API base URL |
| headers | Record<string, string> | — | Extra headers merged into requests |
Per-request options are passed via modelOptions on rerank():
import { rerank } from '@tanstack/ai'
import { cohereRerank } from '@tanstack/ai-cohere'
const { ranking } = await rerank({
adapter: cohereRerank('rerank-v3.5'),
query: 'refund policy',
documents: ['Returns accepted within 30 days.', 'Free shipping over $50.'],
modelOptions: {
maxTokensPerDoc: 512, // Cap tokens kept per document (Cohere default: 4096)
},
})
console.log(ranking)To pass an API key directly instead of reading the environment:
import { createCohereRerank } from '@tanstack/ai-cohere'
const adapter = createCohereRerank('rerank-v3.5', 'your-cohere-api-key')COHERE_API_KEY=your-cohere-api-key| Variable | Required | Description |
|---|---|---|
| COHERE_API_KEY | Yes | Your Cohere API key |
Get your API key from the Cohere dashboard.
Creates a Cohere rerank adapter for use with rerank(), reading COHERE_API_KEY from the environment.
Same as cohereRerank, but takes an explicit API key.