Analytics - TypeScript SDK

Analytics method reference

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

(analytics)

Overview

Analytics and usage endpoints

Available Operations

getUserActivity

Returns user activity data grouped by endpoint for the last 30 (completed) UTC days

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
5});
6
7async function run() {
8 const result = await openRouter.analytics.getUserActivity();
9
10 console.log(result);
11}
12
13run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { analyticsGetUserActivity } from "@openrouter/sdk/funcs/analyticsGetUserActivity.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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const res = await analyticsGetUserActivity(openRouter);
12 if (res.ok) {
13 const { value: result } = res;
14 console.log(result);
15 } else {
16 console.log("analyticsGetUserActivity failed:", res.error);
17 }
18}
19
20run();

Parameters

ParameterTypeRequiredDescription
requestoperations.GetUserActivityRequest✔️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.GetUserActivityResponse>

Errors

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