Rerank (Cohere-compatible)
POST /v1/rerankRerank documents against a query over x402 - the Cohere /rerank wire ({query, documents[], top_n} -> results with relevance_score), served by cohere/rerank-v3.5, $0.002 per call in USDC, no API key, no signup. Up to 50 documents (1,600 chars each, 40k total) and a 500-char query per call. Deterministic, so a byte-identical repeat within 10 minutes is served FREE from cache (X-Cache: hit; opt out with cache:false). The retrieval companion to /v1/embeddings - embed and recall, then rerank the top candidates.
Input
| Field | Type | Description |
|---|---|---|
query * | string | The search query (max 500 chars) |
documents * | array | Documents to rank (1-50 strings, 1,600 chars each, 40k total) |
top_n | integer | Optional - return only the top N results |
cache | boolean | Optional - false disables the default-on response cache |
Example output
{
"id": "gen-rerank-…",
"model": "rerank-v3.5",
"results": [
{
"index": 0,
"relevance_score": 0.89,
"document": {
"text": "Paris is the capital of France."
}
},
{
"index": 1,
"relevance_score": 0.15,
"document": {
"text": "Berlin is the capital of Germany."
}
}
],
"usage": {
"search_units": 1
}
}
Try it - see the 402 challenge (free)
curl -i -X POST https://agent402.tools/v1/rerank \
-H "Content-Type: application/json" \
-d '{"query":"What is the capital of France?","documents":["Paris is the capital of France.","Berlin is the capital of Germany.","Madrid is in Spain."],"top_n":2}'
The response is HTTP 402 Payment Required with exact payment requirements. Any x402 v2 client pays automatically and retries:
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/rerank", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"query": "What is the capital of France?",
"documents": [
"Paris is the capital of France.",
"Berlin is the capital of Germany.",
"Madrid is in Spain."
],
"top_n": 2
}),
});
Related tools
Chat completions - nano tier
POST /v1/nano/chat/completionsOpenAI-compatible chat completions, nano tier: gpt-4.1-nano, gpt-5-nano, gemini flash-lite, small llama/ministral/qwen, …
try in playground →Chat completions - auto tier (eval-ranked routing)
POST /v1/auto/chat/completionsOpenAI-compatible chat completions with server-side model choice: omit "model" (or send "auto") and the gateway routes t…
try in playground →Grounded chat (web search, OpenAI-compatible)
POST /v1/grounded/chat/completionsOpenAI-compatible chat completions GROUNDED in a live web search on every call: the gateway runs an Exa search (up to 5 …
try in playground →