API reference
Rerank API
Parameters, request and response examples for POST /v1/rerank — score and sort candidate documents by relevance to a query, typically right after retrieval in knowledge-base RAG. Uses the common query, documents and top_n format. Requests are relayed as-is.
POST /v1/rerank takes a query and a list of candidate documents, gives each document a relevance score and returns them sorted from most to least relevant. In knowledge-base RAG you typically retrieve a few dozen passages with vector search, then rerank them and pass only the best few to the chat model: answers get more accurate and the chat model reads less irrelevant text. The request uses the common query, documents and top_n fields and is relayed to the model service as-is.
https://open.tutujin.com/v1/rerankHeaders
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer sk-..., an API key from the console |
Content-Type | Yes | application/json |
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name, e.g. qwen3-reranker-8b |
query | string | Yes | The query, usually the user's question |
documents | array | Yes | Candidate documents, as an array of strings |
top_n | integer | No | Return only the N highest-scoring documents; omit to return all |
return_documents | boolean | No | true includes each document's text in the results |
Request example
curl https://open.tutujin.com/v1/rerank \
-H "Authorization: Bearer $TUTUJIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-reranker-8b",
"query": "Can I return an item after opening it?",
"documents": [
"Unopened items can be returned within 7 days of delivery, no reason needed.",
"Orders ship within 48 hours of payment; holidays push this back.",
"Opened items without a quality issue cannot be returned without a reason."
],
"top_n": 2
}'import os
import requests
docs = [
"Unopened items can be returned within 7 days of delivery, no reason needed.",
"Orders ship within 48 hours of payment; holidays push this back.",
"Opened items without a quality issue cannot be returned without a reason.",
]
r = requests.post(
"https://open.tutujin.com/v1/rerank",
headers={"Authorization": f"Bearer {os.environ['TUTUJIN_API_KEY']}"},
json={
"model": "qwen3-reranker-8b",
"query": "Can I return an item after opening it?",
"documents": docs,
"top_n": 2,
},
timeout=30,
)
r.raise_for_status()
for item in r.json()["results"]:
print(round(item["relevance_score"], 3), docs[item["index"]])const docs = [
'Unopened items can be returned within 7 days of delivery, no reason needed.',
'Orders ship within 48 hours of payment; holidays push this back.',
'Opened items without a quality issue cannot be returned without a reason.',
]
const r = await fetch('https://open.tutujin.com/v1/rerank', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.TUTUJIN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'qwen3-reranker-8b',
query: 'Can I return an item after opening it?',
documents: docs,
top_n: 2,
}),
})
if (!r.ok) throw new Error(await r.text())
const { results } = await r.json()
for (const item of results) console.log(item.relevance_score.toFixed(3), docs[item.index])Response example
{
"results": [
{ "index": 2, "relevance_score": 0.93 },
{ "index": 0, "relevance_score": 0.71 }
],
"usage": { "prompt_tokens": 96, "total_tokens": 96 }
}| Field | Description |
|---|---|
results[].index | Position of the document in documents, starting at 0 |
results[].relevance_score | Relevance score; higher is more relevant. Ranges differ by model, so compare scores within one request only |
results[].document | Present when return_documents is true; contains the document text |
usage | Billed usage; some models bill by tokens, some per request |
Notes
- This endpoint is relayed as-is and has not been verified separately on this site; check the response shape with a little traffic first.
- Results are already sorted by score; use
indexto look up the original text. - More and longer candidates mean more usage. Retrieving 20 to 50 passages and keeping a
top_nof 3 to 8 is usually enough. - Tune any score threshold on your own data. Scores mean different things on different models, so re-tune after switching models.
- The full flow with vector search is in Enterprise knowledge base and RAG.
Models that support this endpoint
| Model | Vendor | Cheapest group | Input ¥/1M | Output ¥/1M | Per request ¥ |
|---|---|---|---|---|---|
| qwen3-reranker-4b | Qwen | Standard | — | — | ¥0.002 |
| qwen3-reranker-0.6b | Qwen | Standard | — | — | ¥0.002 |
| qwen3-reranker-8b | Qwen | China Models | ¥0.00308 | ¥0.00308 | — |
| jina-reranker-v2-base-multilingual | Other | Standard | ¥0.4 | ¥0.4 | — |
| netease-youdao/bce-reranker-base_v1 | Other | Standard | ¥0.4 | ¥0.4 | — |
| BAAI/bge-reranker-v2-m3 | Other | Standard | ¥0.4 | ¥0.4 | — |
Prices in CNY, cheapest group for each model; updated Nov 12, 2026, 8:17 PM.
Still stuck? Add our WeChat support JsnonoChat and send the request id from the error message, and we will look into it.