Endpoints - TypeScript SDK

Endpoints method reference

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

(endpoints)

Overview

Endpoint information

Available Operations

  • list - List all endpoints for a model
  • listZdrEndpoints - Preview the impact of ZDR on the available endpoints

list

List all endpoints for a model

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.endpoints.list({
9 author: "<value>",
10 slug: "<value>",
11 });
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 { endpointsList } from "@openrouter/sdk/funcs/endpointsList.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 endpointsList(openRouter, {
12 author: "<value>",
13 slug: "<value>",
14 });
15 if (res.ok) {
16 const { value: result } = res;
17 console.log(result);
18 } else {
19 console.log("endpointsList failed:", res.error);
20 }
21}
22
23run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

1import {
2 // Query hooks for fetching data.
3 useEndpointsList,
4 useEndpointsListSuspense,
5
6 // Utility for prefetching data during server-side rendering and in React
7 // Server Components that will be immediately available to client components
8 // using the hooks.
9 prefetchEndpointsList,
10
11 // Utilities to invalidate the query cache for this query in response to
12 // mutations and other user actions.
13 invalidateEndpointsList,
14 invalidateAllEndpointsList,
15} from "@openrouter/sdk/react-query/endpointsList.js";

Parameters

ParameterTypeRequiredDescription
requestoperations.ListEndpointsRequest✔️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.ListEndpointsResponse>

Errors

Error TypeStatus CodeContent Type
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

listZdrEndpoints

Preview the impact of ZDR on the available endpoints

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.endpoints.listZdrEndpoints();
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 { endpointsListZdrEndpoints } from "@openrouter/sdk/funcs/endpointsListZdrEndpoints.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 endpointsListZdrEndpoints(openRouter);
12 if (res.ok) {
13 const { value: result } = res;
14 console.log(result);
15 } else {
16 console.log("endpointsListZdrEndpoints failed:", res.error);
17 }
18}
19
20run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

1import {
2 // Query hooks for fetching data.
3 useEndpointsListZdrEndpoints,
4 useEndpointsListZdrEndpointsSuspense,
5
6 // Utility for prefetching data during server-side rendering and in React
7 // Server Components that will be immediately available to client components
8 // using the hooks.
9 prefetchEndpointsListZdrEndpoints,
10
11 // Utility to invalidate the query cache for this query in response to
12 // mutations and other user actions.
13 invalidateAllEndpointsListZdrEndpoints,
14} from "@openrouter/sdk/react-query/endpointsListZdrEndpoints.js";

Parameters

ParameterTypeRequiredDescription
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.ListEndpointsZdrResponse>

Errors

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