POST /v3/rerank scores a list of documents against a query and returns the most relevant first. Use it after retrieving candidate passages, then pass the highest-ranked results into your model’s context.
Authenticate with a project API key. Reranking requires a paid plan.
Rerank documents
Send a model, a query, and up to 1,000 document strings. Settop_n to limit the results and return_documents to include their text.
results, a generation id, the model endpoint that served the request, and usage. Each result’s index points to its original position in your documents array, even after sorting. For this example, the password-reset passage at index 1 ranks first.
Choose a model
List available rerank models withGET /v3/models?type=rerank:
bge-reranker-v2-m3 or rerank-v3.5, selects from that model’s pooled endpoints. If an endpoint fails and another eligible endpoint exists, Opper tries the next one. A fully qualified ID, such as berget/bge-reranker-v2-m3 or aws/cohere/rerank-v3.5, pins one endpoint and does not fall back.
The project’s model access rules and provider entitlements apply to every candidate, including fallback endpoints. The response’s model identifies the endpoint that answered.
Usage and cost
usage.total_tokens contains the provider’s reported token count. Rerank tokens are recorded as input tokens; no output text tokens are generated. Providers that do not report tokens return 0, which does not mean the call is free.
Billing follows the selected endpoint’s catalog price: per input token for Berget BGE, or per call for Bedrock Cohere. usage.cost and the X-Generation-Cost response header report the cost in USD. A successful request is billed for the endpoint that served it. Limiting the returned results with top_n does not limit the candidate documents sent for scoring.
Errors
Use the rerank URL directly:
https://api.opper.ai/v3/rerank. The /v3/compat base URL used for chat completions does not expose a rerank route.
See the API reference for the complete request and response schema.