PerslyPersly API
API Reference

Rerank

Rerank documents by medical relevance to a query.

POST https://api.persly.ai/v1/rerank

Reranks a list of documents by their relevance to a given query. Optimized for medical content, this API significantly improves search result quality for healthcare applications.

Request Body

ParameterTypeRequiredDefaultDescription
modelstringYesMust be persly-rerank-v1
querystringYesThe search query to rank documents against. Must be non-empty.
documentsarrayYesDocuments to rerank. 1–1,000 items. Each item is a string or {"text": "..."} object.
top_ninteger | nullNonullReturn only the top N results. If null, all documents are returned. Must be ≥ 1.
return_documentsbooleanNotrueInclude the document text in the response

Response Body

FieldTypeDescription
idstringUnique request ID in rrk_{hex} format
objectstringAlways "rerank"
createdintegerUnix timestamp
modelstring"persly-rerank-v1"
resultsarrayRanked results, sorted by relevance (highest first)
results[].indexintegerOriginal index in the input documents array
results[].relevance_scorenumberRelevance score (0.0–1.0)
results[].documentobject | nullDocument text (when return_documents: true)
results[].document.textstringThe document text
usageobjectUsage information
usage.search_countintegerNumber of search units billed (⌈documents / 100⌉)
usage.documents_countintegerNumber of documents processed

Examples

Basic Reranking

curl https://api.persly.ai/v1/rerank \
  -H "Authorization: Bearer $PERSLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "persly-rerank-v1",
    "query": "treatment options for rheumatoid arthritis",
    "documents": [
      "Methotrexate is the anchor drug in RA treatment, typically started at 7.5-15mg weekly.",
      "Osteoarthritis is a degenerative joint disease primarily affecting weight-bearing joints.",
      "Biologic DMARDs such as TNF inhibitors are used when conventional DMARDs fail.",
      "Physical therapy and exercise are important adjuncts in managing inflammatory arthritis."
    ],
    "top_n": 3
  }'
import requests

response = requests.post(
    "https://api.persly.ai/v1/rerank",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "model": "persly-rerank-v1",
        "query": "treatment options for rheumatoid arthritis",
        "documents": [
            "Methotrexate is the anchor drug in RA treatment, typically started at 7.5-15mg weekly.",
            "Osteoarthritis is a degenerative joint disease primarily affecting weight-bearing joints.",
            "Biologic DMARDs such as TNF inhibitors are used when conventional DMARDs fail.",
            "Physical therapy and exercise are important adjuncts in managing inflammatory arthritis.",
        ],
        "top_n": 3,
    },
)

data = response.json()
for result in data["results"]:
    print(f"[{result['relevance_score']:.3f}] {result['document']['text'][:80]}...")
const response = await fetch("https://api.persly.ai/v1/rerank", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "persly-rerank-v1",
    query: "treatment options for rheumatoid arthritis",
    documents: [
      "Methotrexate is the anchor drug in RA treatment, typically started at 7.5-15mg weekly.",
      "Osteoarthritis is a degenerative joint disease primarily affecting weight-bearing joints.",
      "Biologic DMARDs such as TNF inhibitors are used when conventional DMARDs fail.",
      "Physical therapy and exercise are important adjuncts in managing inflammatory arthritis.",
    ],
    top_n: 3,
  }),
});

const data = await response.json();
for (const result of data.results) {
  console.log(`[${result.relevance_score.toFixed(3)}] ${result.document.text.slice(0, 80)}...`);
}

Response

{
  "id": "rrk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "object": "rerank",
  "created": 1709000000,
  "model": "persly-rerank-v1",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": {"text": "Methotrexate is the anchor drug in RA treatment, typically started at 7.5-15mg weekly."}
    },
    {
      "index": 2,
      "relevance_score": 0.89,
      "document": {"text": "Biologic DMARDs such as TNF inhibitors are used when conventional DMARDs fail."}
    },
    {
      "index": 3,
      "relevance_score": 0.72,
      "document": {"text": "Physical therapy and exercise are important adjuncts in managing inflammatory arthritis."}
    }
  ],
  "usage": {
    "search_count": 1,
    "documents_count": 4
  }
}

Using Object Documents

Documents can be passed as objects with a text field:

{
  "model": "persly-rerank-v1",
  "query": "diabetes management",
  "documents": [
    {"text": "Insulin therapy is essential for type 1 diabetes management."},
    {"text": "Regular eye exams are recommended for diabetic patients."}
  ]
}

Pricing

Billing is based on search units: 1 search unit = up to 100 documents.

DocumentsSearch UnitsCost
1–1001$0.002
101–2002$0.004
901–1,00010$0.020

Errors

StatusCodeCause
400model_not_foundInvalid model (must be persly-rerank-v1)
400invalid_requestEmpty query, empty documents, or invalid document format
400documents_limit_exceededMore than 1,000 documents
401authentication_errorInvalid API key
429quota_exceededFree credits exhausted
429spending_limit_exceededMonthly spending limit reached

On this page