Score documents by relevance to a query
https://api.stav.ai/v1/rerankScores documents by relevance to a query with a reranker and returns
them highest first. The request and answer shape are Cohere v2's,
Jina's and vLLM's: change only the base URL
(https://api.stav.ai/v1/rerank) and the key. Scope inference:rerank.
Name a model listed with the rerank surface on GET /v1/models;
auto and Routers are refused (router_not_supported). Any field
not listed here is refused by name (unsupported_parameter), and so
is stream. 1 to 1,000 documents per request, strings or {"text"}
objects (one form). top_n cuts the answer; return_documents
echoes each result's text from your request.
Billing: one unit per request, the provider's own — per query where
the endpoint is priced per query, else the input tokens the provider
reports; never output tokens. usage.cost is the charge in the
workspace currency, from Stav's own ledger (absent when the
workspace's own key served the call). A provider answer with an
out-of-range index or a score that is not a finite number is never
returned in part: the next Provider Endpoint is tried, else
502 upstream_invalid_answer. The query and the documents are never
stored outside a capture window the workspace opened.
Forespørselsinnhold
modelstringpåkrevdquerystringpåkrevdWhat the documents are scored against.
documentsarray of string | objectpåkrevdStrings, or objects with a
textfield — one form, not mixed.Vis 1 form
Form 1textstringpåkrevd
providerobjectStav extension, region per request. Narrows where this one request may run and which Inference Providers may serve it, on top of your workspace policy — it can only narrow, never widen. It filters Provider Endpoints: the serving endpoint and every failover stay inside it, and when no endpoint of the model passes, the request is refused (
403 endpoint_not_admissible, orprovider_blockedwhen every endpoint is on a provider you named inignore) and nothing is sent. A provider pinned in the model id (creator/model/provider) that the filter excludes is400 invalid_valuewithparamprovider.Any other key is refused by name (
400 unsupported_parameter,paramprovider.<key>). Never forwarded to a provider.Vis 4 underfelt
runs_instring | array of stringWhere the request may run:
"eu","eea", one ISO 3166 alpha-2 country code, or a list of country codes (["NO", "SE"]). One region or countries, not both in one list.globalendpoints satisfy no region, so most Claude and Gemini endpoints are excluded by"eu".regionstring | array of stringAlias of
runs_in, same meaning. Not a provider region code — those are chosen in the model id (creator/model/provider:<code>). Sending both with different values is400 invalid_value.onlyarray of stringOnly endpoints of these Inference Providers serve (slugs, as listed by
GET /v1/models/{model_id}/endpoints). Applies to the endpoint, whoever the model's provider of record is. An unknown slug is400 invalid_value.ignorearray of stringNo endpoint of these Inference Providers serves (slugs).
top_nintegerReturn only the best N documents (1 to the number of documents). Omit for every document, scored.
return_documentsbooleanEcho each result's text under
document.text, from your request.
Merknader
POST https://api.stav.ai/v1/rerank takes the same JSON as Cohere's v2 rerank API, Jina's and vLLM's /v1/rerank. A reranker reads a query and a list of documents and answers with each document's relevance score — the second step of retrieval, after your vector search returned candidates.
Coming from Cohere, Jina or a provider's own rerank API, change two things: the base URL (https://api.stav.ai/v1) and the key. With the Vercel AI SDK, use @ai-sdk/cohere with createCohere({ baseURL: "https://api.stav.ai/v1", apiKey }): its rerank() posts to {baseURL}/rerank.
Request
| Field | Type | Notes |
|---|---|---|
model | string | Required. A model listed with the rerank surface on GET /v1/models. auto and Routers do not apply. |
query | string | Required. What the documents are scored against. |
documents | array | Required. 1 to 1,000 documents: strings, or objects with a text field — one form, not mixed. |
top_n | integer | Return only the best N, 1 to the number of documents. Omit for every document, scored. |
return_documents | boolean | Echo each result's text under document.text — from your request, never the provider's copy. Default false. |
Any other field — stream, rank_fields, max_tokens_per_doc — is refused by name with 400 unsupported_parameter. Nothing is dropped silently.
Nothing is truncated either. A reranker reads the query with one document at a time, up to a token limit per model. Before the request leaves Stav, the query with its longest document is checked against that limit; if no Provider Endpoint of the model reads that much, the request is refused with 400 rerank_input_too_long and param names the document (documents[3]) or query. The check uses an estimate of about 4 bytes a token, so keep documents well below the limit: split long documents into passages.
Response
{
"id": "rr-3f9c…",
"model": "qwen/qwen3-reranker-8b",
"results": [
{"index": 0, "relevance_score": 0.97},
{"index": 2, "relevance_score": 0.12}
],
"usage": {"input_tokens": 41, "total_tokens": 41, "cost": 0.0000071, "cost_currency": "EUR"}
}
results is sorted by relevance_score, highest first, and cut to top_n. Each index is a position in the documents you sent. relevance_score is always between 0 and 1, so a threshold means the same on every Provider Endpoint and after a failover: where a provider scores on another scale (a raw logit), Stav maps its score to 0–1 with the logistic function, 1 / (1 + e^-score), and keeps the provider's order. usage.total_tokens equals usage.input_tokens: a reranker has no output tokens. On a provider priced per query, usage.search_units carries the provider's own unit count.
usage.cost is what your wallet is charged, in your workspace's currency, from Stav's own ledger — never the provider's own figure. It is absent when your workspace's own provider key (BYOK) served the call. The usual response headers come with it: the serving provider, its sovereignty level, the countries the documents may have been processed in, and X-Stav-Cost.
How it differs from chat
- Name the model.
autoand Routers serve the chat surfaces only. - Which models qualify. A model is callable here when a Provider Endpoint of it has been proven to rerank — Stav sends each endpoint one query and two documents with a known order and records whether the right document came first.
- The same policy wall. Compute country, zero data retention, no-training, the sovereignty floor and blocked providers apply exactly as on chat. Some rerankers are hosted in the US; a workspace whose policy excludes that is refused with the same codes as chat, and the refusal says why.
- Your key needs the
inference:rerankscope. Without it:403 insufficient_scope. A key with no scopes has full access. - Billing. One unit per request, the provider's own: per query where the provider prices per query, else the input tokens the provider reports — never output tokens, never an estimate. A token-priced endpoint whose provider reports no token count is not callable. A failed request is not charged. See Credits and billing.
- Your data. The query and the documents are not kept in the request log, which records the document count and
top_n. Inside a capture window you opened, the request and answer JSON are kept like a chat prompt.
Errors
| Status | When |
|---|---|
400 unsupported_parameter | An unknown field, stream, or a provider-specific extra (rank_fields, max_tokens_per_doc) |
400 invalid_value | A required field missing, an empty document, a mixed document form, top_n out of range — param names it (documents[3]) |
400 rerank_input_too_long | The query, or the query with one document, is longer than the model reads — param names it. Split the document |
400 router_not_supported | model was auto or a Router |
402 | Not enough credits, or a spend limit was reached |
403 insufficient_scope | The key lacks inference:rerank |
404 rerank_not_enabled | Rerank is not enabled on this deployment |
404 model_not_found | The model is not a rerank model, or has no Provider Endpoint on this surface priced in a unit Stav can measure |
501 rerank_not_supported | The model's Inference Provider has no /rerank door |
502 upstream_invalid_answer | No Provider Endpoint answered with one in-range, finite score per document |
| Provider status | The provider refused the request: provider_error, with the provider's status and its error code. The provider's own message is not passed on, because a provider may quote your query or a document in it |
Every error body has a top-level message beside error, with the same text as error.message. Cohere clients read the first, OpenAI clients the second.
Full catalogue: Errors.
On the model page
A reranker's page has a Try model button: a query, your documents (one per row, or pasted one per line), top_n, the documents re-ordered with a score bar each and their original position, the receipt with the cost, and Get code for the call you just ran.
Svarheadere
| Header | Betydning |
|---|---|
X-Stav-Request-Id | Unique request identifier, identical to the completion |
X-Stav-Model | The model that actually served the request — not necessarily the one you asked for, when routing or failover intervened. |
X-Stav-Provider | The provider that served the request. |
X-Stav-Sovereignty-Level | The sovereignty level of the serving Provider Endpoint. |
X-Stav-Compute-Region | Where the serving Provider Endpoint computes, as a region. Always
sent. |
X-Stav-Compute-Countries | Every country the documents may have been processed in, comma-separated ISO 3166-1 alpha-2, when known. |
X-Stav-Cost | The charge for this request in the workspace currency ( |
X-RateLimit-Limit | Per-minute request cap on this key. |
X-RateLimit-Remaining | Requests remaining in the current window. |
X-RateLimit-Reset | Unix timestamp (seconds) when the current window rolls over. |
Feil
| Status | Når |
|---|---|
| 400 |
|
| 401 | Missing or invalid API key. |
| 402 | The wallet or a spend limit refused the request. |
| 403 | API key lacks the required scope (e.g., |
| 404 |
|
| 429 | Per-key or per-IP rate limit exceeded. |
| 501 |
|
| 502 |
|
Alle feilkoder, hva de betyr og hva du gjør: Feil.