We use cookies. Cookies and browser storage keep you signed in and remember your preferences. With your permission we also measure how the site is used. You can any time. See our cookie policy.

Rerank

Endpoints

Rerank

Order a list of documents by relevance to a query with POST /rerank on api14, for search results, RAG pipelines and question answering.

Try it in the playground

Order a list of documents by relevance to a query. Rerankers are the second stage of a search pipeline: retrieve 50–200 candidates with embeddings or keyword search, then rerank and keep the top few for your prompt.

POST https://api14.com/api/v1/rerank

The official OpenAI SDKs have no rerank method, so call it with plain HTTP (every language example below does).

Request

ParameterTypeRequiredDescription
modelstringyesA rerank model id, e.g. cohere/rerank-v3.5.
querystringyesThe search query.
documentsstring[]yesCandidate texts to score.
top_nintegernoReturn only the best N results. Defaults to all.
return_documentsbooleannoInclude the document text in each result.

Example

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.post("/rerank", { body: {
  "model": "cohere/rerank-v3.5",
  "query": "What is the capital of France?",
  "documents": [
    "Paris is the capital of France.",
    "Berlin is in Germany."
  ],
  "top_n": 1
} });
console.log(result.results);
curl https://api14.com/api/v1/rerank \
  -H "Authorization: Bearer sk-api14-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/rerank-v3.5",
    "query": "How do I reset my password?",
    "documents": [
      "Billing happens on the first of each month.",
      "To reset your password, open Settings and choose Security.",
      "Our office is closed on public holidays."
    ],
    "top_n": 2
  }'

Response

{
  "id": "gen-1791100000-rr1",
  "model": "cohere/rerank-v3.5",
  "results": [
    { "index": 1, "relevance_score": 0.94 },
    { "index": 0, "relevance_score": 0.08 }
  ],
  "usage": { "search_units": 1, "cost": 0.002 }
}

index points into your documents array. Results are sorted by relevance_score, highest first.

Pricing

Rerank models are billed per search at the model's listed price, displayed as "$ / 1K searches". The cost is in usage.cost and debited from your USD balance.

Listing rerank models

curl "https://api14.com/api/v1/models?category=rerank"

Errors

StatusCodeWhen
400model_required / invalid_jsonMissing model or malformed body.
402insufficient_balanceYour USD balance is $0.
403model_not_allowedKey allowlist excludes the model.
404model_not_foundUnknown or disabled model id.
429rate_limitedRequests per minute exceeded.

See Errors.