Rerank Documents
Rank documents by relevance to a query. Requests and responses follow OpenRouter's rerank schema whichever engine serves the model.
Body
application/jsonOpenRouter's rerank request. Every model receives only the query and plain-text documents; top_n and the document echo are applied by the API so they behave the same on every model. OpenRouter's provider, user, session_id and trace and Cohere v2's max_tokens_per_doc and priority are accepted and ignored.
-
model string required
The rerank model to use.
-
query string required
The search query to rank the documents against.
at least 1 characters -
documents array of (string or object)s required
The documents to rank, as plain strings or objects with a
textfield. Image documents are rejected.at least 1 items -
top_n integer
Return only the highest scoring
top_nresults. All results are returned when omitted.range 1–100 -
return_documents boolean
Extension to OpenRouter's schema. Set
falseto omitdocumentfrom each result.default true
Responses
OK
application/json · rerank-response-payload
The request body is not a JSON object, top_n is over 100, the model rejected the request, or the input is longer than the model's context length (metadata.error_type context_)
application/json · error-payload
The API key is missing, unknown or not active. Send it as Authorization: Bearer <key>.
application/json · error-payload
Model not found
application/json · error-payload
Rate limit exceeded
application/json · error-payload
The model could not be reached or returned an unusable response
application/json · error-payload
The model timed out
application/json · error-payload
The request body is over 16 MB
application/json · error-payload
curl https://api.vultrinference.com/v1/rerank \
-H "Authorization: Bearer $VULTR_INFERENCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
"Berlin is the capital of Germany.",
"Paris is the capital of France."
],
"top_n": 1
}'import os
import requests
response = requests.post(
"https://api.vultrinference.com/v1/rerank",
headers={"Authorization": f"Bearer {os.environ['VULTR_INFERENCE_API_KEY']}"},
json={
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
"Berlin is the capital of Germany.",
"Paris is the capital of France.",
],
"top_n": 1,
},
)
print(response.json())const response = await fetch("https://api.vultrinference.com/v1/rerank", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.VULTR_INFERENCE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
"Berlin is the capital of Germany.",
"Paris is the capital of France."
],
"top_n": 1
}),
});
console.log(await response.json());{
"id": "rerank-3f1c9a0d2b7e4c6a8d5e1f02",
"model": "bge-reranker-v2-m3",
"results": [
{
"index": 1,
"relevance_score": 0.9998499,
"document": {
"text": "Paris is the capital of France."
}
}
],
"usage": {
"total_tokens": 36
}
}