API Reference

Rerank

Improve search and retrieval quality by reranking document relevance using models from Cohere, Jina AI, and other providers through a single endpoint.

Endpoint

http
POST https://api.onerouter.app/v1/rerank

Request Parameters

ParameterTypeRequiredDescription
modelstringYesRerank model ID (e.g., cohere-rerank-v3, jina-reranker-v2)
querystringYesThe search query to evaluate documents against
documentsarrayYesList of document strings or objects to rerank
top_nintegerNoReturn only the top N results. Default: returns all
return_documentsbooleanNoInclude document text in response. Default: true

Example

Send a query with a list of candidate documents and receive relevance-scored results:

python
import requests

response = requests.post(
    "https://api.onerouter.app/v1/rerank",
    headers={
        "Authorization": "Bearer sk-your-key",
        "Content-Type": "application/json",
    },
    json={
        "model": "cohere-rerank-v3",
        "query": "What is the capital of France?",
        "documents": [
            "Paris is the capital of France.",
            "Berlin is the capital of Germany.",
            "France is a country in Europe.",
        ],
        "top_n": 2,
    },
)

for result in response.json()["results"]:
    print(f"Score: {result['relevance_score']:.3f}{result['document']['text']}")

Common Use Cases

  • RAG pipelines — Rerank retrieved chunks before passing to the LLM for more accurate answers
  • Hybrid search — Combine keyword (BM25) and vector search results, then rerank for best relevance
  • Multi-stage retrieval — Coarse retrieval → rerank → generation pipeline

Available Models

Supported reranking models include Cohere Rerank v3, Jina Reranker v2, and BGE-Reranker. See the Models page for the full catalog and per-model pricing.