Skip to main content
POST
/
v1
/
rerank
Rerank
curl --request POST \
  --url https://openp.ai/v1/rerank
import requests

url = "https://openp.ai/v1/rerank"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://openp.ai/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://openp.ai/v1/rerank",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://openp.ai/v1/rerank"

	req, _ := http.NewRequest("POST", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://openp.ai/v1/rerank")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://openp.ai/v1/rerank")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
Re-rank a set of candidate documents by relevance to a query, commonly used for precise ranking after RAG recall. Fully compatible with the Cohere / Jina Rerank protocol.

Request

curl https://openp.ai/v1/rerank \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-multilingual-v3.0",
    "query": "What is a vector database?",
    "documents": [
      "A vector database stores high-dimensional vectors for similarity search.",
      "Postgres is a relational database.",
      "FAISS / Milvus are common vector-index solutions."
    ],
    "top_n": 2,
    "return_documents": true
  }'

Parameters

FieldTypeRequiredDescription
modelstringRerank model ID
querystringThe query string
documentsarrayArray of documents, either strings or { text } objects
top_nintegerReturn the top N, default all
return_documentsbooleanWhether to return the original text in the response (default false, returning only index + score)
max_chunks_per_docintegerCohere v3, chunk overly long documents
Model IDVendorContext
rerank-multilingual-v3.0Cohere4096
rerank-english-v3.0Cohere4096
jina-reranker-v2-base-multilingualJina1024
bge-reranker-v2-m3BAAI8192
bge-reranker-largeBAAI512

Response

{
  "id": "rerank-...",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.98,
      "document": {"text": "A vector database stores high-dimensional vectors for similarity search."}
    },
    {
      "index": 2,
      "relevance_score": 0.83,
      "document": {"text": "FAISS / Milvus are common vector-index solutions."}
    }
  ],
  "meta": {
    "api_version": "1",
    "billed_units": {"search_units": 1}
  }
}
results is sorted descending by relevance_score, and index points to the position in the original documents array.

Python (raw HTTP)

import requests

resp = requests.post(
    "https://openp.ai/v1/rerank",
    headers={"Authorization": "Bearer sk-..."},
    json={
        "model": "bge-reranker-v2-m3",
        "query": "What is a vector database?",
        "documents": ["...", "...", "..."],
        "top_n": 5,
    },
).json()
print(resp["results"])

Cohere SDK

import cohere
client = cohere.Client(api_key="sk-...", base_url="https://openp.ai/v1")

resp = client.rerank(
    model="rerank-multilingual-v3.0",
    query="...",
    documents=["...", "..."],
    top_n=3,
)

Billing

Charged by the total tokens of query + all documents; the specific multiplier depends on the model.