Rerank API

POST /api/v1/rerank scores each document's relevance to a query. Cohere-compatible.

Score and sort documents by relevance to a query, as a second stage after vector or keyword search (fetch 50–100 candidates, keep the top few). The body is compatible with Cohere's Rerank API.

Send an LLM API key (sk-ar-v1-…) from /dashboard/keys as Authorization: Bearer …. Management keys (ak_…) are not accepted.

Request

FieldTypeRequiredDescription
modelstringyesA rerank model id, e.g. cohere/rerank-v3.5. See Models.
querystringyesThe search query.
documents(string | {text: string})[]yesUp to 1,000 documents to score.
top_ninteger (≥ 1)noReturn only the best top_n results. Defaults to all documents.
return_documentsbooleannoWhen true, each result includes document.text. Defaults to false.
max_tokens_per_docinteger (≥ 1)noTruncate each document to this many tokens before scoring.
session_idstringnoGroups related requests in Request Logs.
curl https://anyrouter.dev/api/v1/rerank \
  -H "Authorization: Bearer $ANYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "What is the capital of France?",
    "documents": [
      "Paris is the capital and largest city of France.",
      "Berlin is the capital of Germany.",
      "Bananas are rich in potassium."
    ],
    "top_n": 2
  }'

Response

{
  "id": "162b4aa9-d997-4942-896a-ef65644ff544",
  "model": "cohere/rerank-v3.5",
  "results": [
    { "index": 0, "relevance_score": 0.892 },
    { "index": 1, "relevance_score": 0.073 }
  ],
  "usage": {
    "prompt_tokens": 1000,
    "total_tokens": 1000,
    "search_units": 1,
    "cost": 0.002
  }
}
FieldTypeDescription
idstringResponse id.
modelstringThe model id you requested.
results[]arraySorted by relevance_score, highest first.
results[].indexintegerPosition of the document in your documents array.
results[].relevance_scorenumberRelevance between 0 and 1. Compare scores within one request, not across models.
results[].document{text}Present only when return_documents is true.
usage.prompt_tokensintegerBilled tokens (see Pricing).
usage.search_unitsintegerProvider search units, when the provider reports them.
usage.costnumberUSD charged for this request.

Pricing

Priced per 1M input tokens. AnyRouter counts tokens over the query plus every document (about 4 characters per token), since providers return no counts. Each provider search unit (one query, up to 100 documents) bills at least 1,000 tokens.

Requests with your own Cohere key (BYOK) are not charged by AnyRouter.

Models

Listed under the Rerank tab at anyrouter.dev/models. Sending a chat or embedding model to this endpoint returns 400 model_not_rerank_compatible.

Errors

StatusCodeWhen
400missing_required_fieldsmodel, query, or documents is missing.
400invalid_requestA document is not a string or {text}, top_n is not a positive integer, or there are more than 1,000 documents.
400model_not_rerank_compatibleThe model is not a rerank model.
404model_unavailableNo route serves the model for your key.
502upstream_errorEvery provider for the model failed.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer