AnyRouter

Rerank API

POST /api/v1/rerank — score how relevant each document is to a query. Cohere-compatible request and response.

Score how relevant each document is to a query, then sort them. Use it as a second stage after vector or keyword search: fetch 50–100 candidates, rerank, and keep the top few. The body is compatible with Cohere's Rerank API.

Authenticate with an LLM API key (sk-ar-v1-…) from /dashboard/keys, sent 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

Rerank models are priced per 1M input tokens, like the rest of the catalog. AnyRouter counts tokens over the query plus every document (about 4 characters per token), because rerank providers do not return token counts. Each provider search unit (one query with up to 100 documents) bills at least 1,000 tokens, so a very small request costs the same as one search.

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

Models

Rerank models appear 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.