Datasets - TypeScript SDK

Datasets method reference

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

Overview

Datasets endpoints

Available Operations

getRankingsDaily

Returns the top 50 public models per day by total token usage on OpenRouter, plus a single aggregated other row per day that sums every model outside that top 50. Token totals are prompt_tokens + completion_tokens, matching the public rankings chart on openrouter.ai/rankings.

Each row is a distinct (date, model_permaslug) pair. The other row uses the reserved permaslug other and is always returned last within its date, so callers can compute top-50 traffic / total daily traffic without a second request.

Authenticate with any valid OpenRouter API key (same key used for inference). Rate-limited to 30 requests/minute per key and 500 requests/day per account.

When republishing or quoting this dataset, OpenRouter must be cited as: “Source: OpenRouter (openrouter.ai/rankings), as of {as_of}.”

Token counts come from each upstream provider’s own tokenizer (Anthropic counts are as reported by Anthropic, OpenAI counts are as reported by OpenAI, etc.), so a token in one row is not directly comparable to a token in another row from a different provider.

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.datasets.getRankingsDaily();
12
13 console.log(result);
14}
15
16run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { datasetsGetRankingsDaily } from "@openrouter/sdk/funcs/datasetsGetRankingsDaily.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 datasetsGetRankingsDaily(openRouter);
15 if (res.ok) {
16 const { value: result } = res;
17 console.log(result);
18 } else {
19 console.log("datasetsGetRankingsDaily failed:", res.error);
20 }
21}
22
23run();

Parameters

ParameterTypeRequiredDescription
requestoperations.GetRankingsDailyRequest✔️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<models.RankingsDailyResponse>

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*