Skip to main content
POST
/
rerank
Submit a rerank request
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

Authorization
string
header
required

API key as bearer token in Authorization header

Body

application/json

Rerank request input

documents
(string | object)[]
required

The list of documents to rerank. Documents may be plain strings, or structured objects with text and/or image for multimodal models.

Minimum array length: 1

A document to rerank. Either a plain string, or a structured object with optional text and/or image.

Example:
[
  "Paris is the capital of France.",
  "Berlin is the capital of Germany."
]
model
string
required

The rerank model to use

Example:

"cohere/rerank-v3.5"

query
string
required

The search query to rerank documents against

Example:

"What is the capital of France?"

provider
object | null

Provider routing preferences for the request.

Example:
{ "allow_fallbacks": true }
top_n
integer

Number of most relevant documents to return

Required range: x >= 1
Example:

3

Response

Rerank response

Rerank response containing ranked results

model
string
required

The model used for reranking

Example:

"cohere/rerank-v3.5"

results
object[]
required

List of rerank results sorted by relevance

Example:
[
  {
    "document": { "text": "Paris is the capital of France." },
    "index": 0,
    "relevance_score": 0.98
  }
]
id
string

Unique identifier for the rerank response (ORID format)

Example:

"gen-rerank-1234567890-abc"

provider
string

The provider that served the rerank request

Example:

"Cohere"

usage
object

Usage statistics

Example:
{ "search_units": 1, "total_tokens": 150 }