Rerank - TypeScript SDK

Rerank method reference

The TypeScript SDK and docs are currently in beta. Report issues on GitHub.

Overview

Reranking endpoints

Available Operations

  • rerank - Submit a rerank request

rerank

Submits a rerank request to the rerank router

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 httpReferer: "<value>",
5 appTitle: "<value>",
6 appCategories: "<value>",
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const result = await openRouter.rerank.rerank({
12 requestBody: {
13 model: "cohere/rerank-v3.5",
14 query: "What is the capital of France?",
15 documents: [
16 "Paris is the capital of France.",
17 "Berlin is the capital of Germany.",
18 ],
19 },
20 });
21
22 console.log(result);
23}
24
25run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { rerankRerank } from "@openrouter/sdk/funcs/rerankRerank.js";
3
4// Use `OpenRouterCore` for best tree-shaking performance.
5// You can create one instance of it to use across an application.
6const openRouter = new OpenRouterCore({
7 httpReferer: "<value>",
8 appTitle: "<value>",
9 appCategories: "<value>",
10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
11});
12
13async function run() {
14 const res = await rerankRerank(openRouter, {
15 requestBody: {
16 model: "cohere/rerank-v3.5",
17 query: "What is the capital of France?",
18 documents: [
19 "Paris is the capital of France.",
20 "Berlin is the capital of Germany.",
21 ],
22 },
23 });
24 if (res.ok) {
25 const { value: result } = res;
26 console.log(result);
27 } else {
28 console.log("rerankRerank failed:", res.error);
29 }
30}
31
32run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreateRerankRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CreateRerankResponse>

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.PaymentRequiredResponseError402application/json
errors.NotFoundResponseError404application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.BadGatewayResponseError502application/json
errors.ServiceUnavailableResponseError503application/json
errors.EdgeNetworkTimeoutResponseError524application/json
errors.ProviderOverloadedResponseError529application/json
errors.OpenRouterDefaultError4XX, 5XX*/*