Presets - TypeScript SDK

Presets method reference

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

Overview

Presets endpoints

Available Operations

list

Lists all presets for the authenticated user, ordered by most recently updated first.

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.presets.list();
12
13 for await (const page of result) {
14 console.log(page);
15 }
16}
17
18run();

Standalone function

The standalone function version of this method:

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

Parameters

ParameterTypeRequiredDescription
requestoperations.ListPresetsRequest✔️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.ListPresetsResponse>

Errors

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

get

Retrieves a preset by its slug with its currently designated version inline.

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.presets.get({
12 slug: "my-preset",
13 });
14
15 console.log(result);
16}
17
18run();

Standalone function

The standalone function version of this method:

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

Parameters

ParameterTypeRequiredDescription
requestoperations.GetPresetRequest✔️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.GetPresetResponse>

Errors

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

createPresetsChatCompletions

Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. messages, stream, prompt) are silently ignored.

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.presets.createPresetsChatCompletions({
12 slug: "my-preset",
13 chatRequest: {
14 messages: [
15 {
16 content: "You are a helpful assistant.",
17 role: "system",
18 },
19 {
20 content: "Hello!",
21 role: "user",
22 },
23 ],
24 model: "openai/gpt-5.4",
25 temperature: 0.7,
26 },
27 });
28
29 console.log(result);
30}
31
32run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { presetsCreatePresetsChatCompletions } from "@openrouter/sdk/funcs/presetsCreatePresetsChatCompletions.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 presetsCreatePresetsChatCompletions(openRouter, {
15 slug: "my-preset",
16 chatRequest: {
17 messages: [
18 {
19 content: "You are a helpful assistant.",
20 role: "system",
21 },
22 {
23 content: "Hello!",
24 role: "user",
25 },
26 ],
27 model: "openai/gpt-5.4",
28 temperature: 0.7,
29 },
30 });
31 if (res.ok) {
32 const { value: result } = res;
33 console.log(result);
34 } else {
35 console.log("presetsCreatePresetsChatCompletions failed:", res.error);
36 }
37}
38
39run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreatePresetsChatCompletionsRequest✔️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.CreatePresetFromInferenceResponse>

Errors

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

createPresetsMessages

Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. messages, stream, prompt) are silently ignored.

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.presets.createPresetsMessages({
12 slug: "my-preset",
13 messagesRequest: {
14 maxTokens: 1024,
15 messages: [
16 {
17 content: "Hello!",
18 role: "user",
19 },
20 ],
21 model: "anthropic/claude-4.6-sonnet",
22 system: "You are a helpful assistant.",
23 },
24 });
25
26 console.log(result);
27}
28
29run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { presetsCreatePresetsMessages } from "@openrouter/sdk/funcs/presetsCreatePresetsMessages.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 presetsCreatePresetsMessages(openRouter, {
15 slug: "my-preset",
16 messagesRequest: {
17 maxTokens: 1024,
18 messages: [
19 {
20 content: "Hello!",
21 role: "user",
22 },
23 ],
24 model: "anthropic/claude-4.6-sonnet",
25 system: "You are a helpful assistant.",
26 },
27 });
28 if (res.ok) {
29 const { value: result } = res;
30 console.log(result);
31 } else {
32 console.log("presetsCreatePresetsMessages failed:", res.error);
33 }
34}
35
36run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreatePresetsMessagesRequest✔️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.CreatePresetFromInferenceResponse>

Errors

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

createPresetsResponses

Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. messages, stream, prompt) are silently ignored.

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.presets.createPresetsResponses({
12 slug: "my-preset",
13 responsesRequest: {
14 input: "Hello!",
15 instructions: "You are a helpful assistant.",
16 model: "openai/gpt-5.4",
17 },
18 });
19
20 console.log(result);
21}
22
23run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { presetsCreatePresetsResponses } from "@openrouter/sdk/funcs/presetsCreatePresetsResponses.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 presetsCreatePresetsResponses(openRouter, {
15 slug: "my-preset",
16 responsesRequest: {
17 input: "Hello!",
18 instructions: "You are a helpful assistant.",
19 model: "openai/gpt-5.4",
20 },
21 });
22 if (res.ok) {
23 const { value: result } = res;
24 console.log(result);
25 } else {
26 console.log("presetsCreatePresetsResponses failed:", res.error);
27 }
28}
29
30run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreatePresetsResponsesRequest✔️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.CreatePresetFromInferenceResponse>

Errors

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

listVersions

Lists all versions of a preset, ordered by version number ascending (oldest first).

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.presets.listVersions({
12 slug: "my-preset",
13 });
14
15 for await (const page of result) {
16 console.log(page);
17 }
18}
19
20run();

Standalone function

The standalone function version of this method:

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

Parameters

ParameterTypeRequiredDescription
requestoperations.ListPresetVersionsRequest✔️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.ListPresetVersionsResponse>

Errors

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

getVersion

Retrieves a specific version of a preset by its slug and version number.

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.presets.getVersion({
12 slug: "my-preset",
13 version: "1",
14 });
15
16 console.log(result);
17}
18
19run();

Standalone function

The standalone function version of this method:

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

Parameters

ParameterTypeRequiredDescription
requestoperations.GetPresetVersionRequest✔️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.GetPresetVersionResponse>

Errors

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