For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • Python SDK
    • Overview
  • Go SDK
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Overview
  • Available Operations
  • createPresetsChatCompletions
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
TypeScript SDKAPI Reference

Presets - TypeScript SDK

Presets method reference
Was this page helpful?
Previous

Providers - TypeScript SDK

Providers method reference
Next
Built with

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

Overview

Presets endpoints

Available Operations

  • createPresetsChatCompletions - Create a preset from a chat-completions request body

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-4o",
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-4o",
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.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖Options 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.retriesRetryConfig➖Enables 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*/*