curl --request POST \
--url https://openrouter.ai/api/v1/rerank \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"documents": [
"Paris is the capital of France.",
"Berlin is the capital of Germany."
],
"model": "cohere/rerank-v3.5",
"query": "What is the capital of France?",
"top_n": 3
}
'import requests
url = "https://openrouter.ai/api/v1/rerank"
payload = {
"documents": ["Paris is the capital of France.", "Berlin is the capital of Germany."],
"model": "cohere/rerank-v3.5",
"query": "What is the capital of France?",
"top_n": 3
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
documents: ['Paris is the capital of France.', 'Berlin is the capital of Germany.'],
model: 'cohere/rerank-v3.5',
query: 'What is the capital of France?',
top_n: 3
})
};
fetch('https://openrouter.ai/api/v1/rerank', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'documents' => [
'Paris is the capital of France.',
'Berlin is the capital of Germany.'
],
'model' => 'cohere/rerank-v3.5',
'query' => 'What is the capital of France?',
'top_n' => 3
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/rerank"
payload := strings.NewReader("{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/rerank")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}"
response = http.request(request)
puts response.read_body{
"id": "gen-rerank-1234567890-abc",
"model": "cohere/rerank-v3.5",
"results": [
{
"document": {
"text": "Paris is the capital of France."
},
"index": 0,
"relevance_score": 0.98
}
],
"usage": {
"search_units": 1,
"total_tokens": 150
}
}{
"error": {
"code": 400,
"message": "Invalid request parameters"
}
}{
"error": {
"code": 401,
"message": "Missing Authentication header"
}
}{
"error": {
"code": 402,
"message": "Insufficient credits. Add more using https://openrouter.ai/credits"
}
}{
"error": {
"code": 404,
"message": "Resource not found"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded"
}
}{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}{
"error": {
"code": 502,
"message": "Provider returned error"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable"
}
}{
"error": {
"code": 524,
"message": "Request timed out. Please try again later."
}
}{
"error": {
"code": 529,
"message": "Provider returned error"
}
}Submit a rerank request
Submits a rerank request to the rerank router
curl --request POST \
--url https://openrouter.ai/api/v1/rerank \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"documents": [
"Paris is the capital of France.",
"Berlin is the capital of Germany."
],
"model": "cohere/rerank-v3.5",
"query": "What is the capital of France?",
"top_n": 3
}
'import requests
url = "https://openrouter.ai/api/v1/rerank"
payload = {
"documents": ["Paris is the capital of France.", "Berlin is the capital of Germany."],
"model": "cohere/rerank-v3.5",
"query": "What is the capital of France?",
"top_n": 3
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
documents: ['Paris is the capital of France.', 'Berlin is the capital of Germany.'],
model: 'cohere/rerank-v3.5',
query: 'What is the capital of France?',
top_n: 3
})
};
fetch('https://openrouter.ai/api/v1/rerank', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://openrouter.ai/api/v1/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'documents' => [
'Paris is the capital of France.',
'Berlin is the capital of Germany.'
],
'model' => 'cohere/rerank-v3.5',
'query' => 'What is the capital of France?',
'top_n' => 3
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://openrouter.ai/api/v1/rerank"
payload := strings.NewReader("{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/rerank")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://openrouter.ai/api/v1/rerank")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"documents\": [\n \"Paris is the capital of France.\",\n \"Berlin is the capital of Germany.\"\n ],\n \"model\": \"cohere/rerank-v3.5\",\n \"query\": \"What is the capital of France?\",\n \"top_n\": 3\n}"
response = http.request(request)
puts response.read_body{
"id": "gen-rerank-1234567890-abc",
"model": "cohere/rerank-v3.5",
"results": [
{
"document": {
"text": "Paris is the capital of France."
},
"index": 0,
"relevance_score": 0.98
}
],
"usage": {
"search_units": 1,
"total_tokens": 150
}
}{
"error": {
"code": 400,
"message": "Invalid request parameters"
}
}{
"error": {
"code": 401,
"message": "Missing Authentication header"
}
}{
"error": {
"code": 402,
"message": "Insufficient credits. Add more using https://openrouter.ai/credits"
}
}{
"error": {
"code": 404,
"message": "Resource not found"
}
}{
"error": {
"code": 429,
"message": "Rate limit exceeded"
}
}{
"error": {
"code": 500,
"message": "Internal Server Error"
}
}{
"error": {
"code": 502,
"message": "Provider returned error"
}
}{
"error": {
"code": 503,
"message": "Service temporarily unavailable"
}
}{
"error": {
"code": 524,
"message": "Request timed out. Please try again later."
}
}{
"error": {
"code": 529,
"message": "Provider returned error"
}
}Authorizations
API key as bearer token in Authorization header
Body
Rerank request input
The list of documents to rerank. Documents may be plain strings, or structured objects with text and/or image for multimodal models.
1A document to rerank. Either a plain string, or a structured object with optional text and/or image.
[
"Paris is the capital of France.",
"Berlin is the capital of Germany."
]
The rerank model to use
"cohere/rerank-v3.5"
The search query to rerank documents against
"What is the capital of France?"
Provider routing preferences for the request.
Show child attributes
Show child attributes
{ "allow_fallbacks": true }
Number of most relevant documents to return
x >= 13
Response
Rerank response
Rerank response containing ranked results
The model used for reranking
"cohere/rerank-v3.5"
List of rerank results sorted by relevance
Show child attributes
Show child attributes
[
{
"document": { "text": "Paris is the capital of France." },
"index": 0,
"relevance_score": 0.98
}
]
Unique identifier for the rerank response (ORID format)
"gen-rerank-1234567890-abc"
The provider that served the rerank request
"Cohere"
Usage statistics
Show child attributes
Show child attributes
{ "search_units": 1, "total_tokens": 150 }