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 playgroundOrder 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
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | yes | A rerank model id, e.g. cohere/rerank-v3.5. |
query | string | yes | The search query. |
documents | string[] | yes | Candidate texts to score. |
top_n | integer | no | Return only the best N results. Defaults to all. |
return_documents | boolean | no | Include 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
| Status | Code | When |
|---|---|---|
| 400 | model_required / invalid_json | Missing model or malformed body. |
| 402 | insufficient_balance | Your USD balance is $0. |
| 403 | model_not_allowed | Key allowlist excludes the model. |
| 404 | model_not_found | Unknown or disabled model id. |
| 429 | rate_limited | Requests per minute exceeded. |
See Errors.