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
  • list
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
  • create
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
  • delete
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
  • get
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
  • update
  • Example Usage
  • Standalone function
  • Parameters
  • Response
  • Errors
TypeScript SDKAPI Reference

Byok - TypeScript SDK

Byok method reference
Was this page helpful?
Previous

Chat - TypeScript SDK

Chat method reference
Next
Built with

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

Overview

BYOK endpoints

Available Operations

  • list - List BYOK provider credentials
  • create - Create a BYOK provider credential
  • delete - Delete a BYOK provider credential
  • get - Get a BYOK provider credential
  • update - Update a BYOK provider credential

list

List the bring-your-own-key (BYOK) provider credentials for the authenticated entity’s default workspace. Use the workspace_id query parameter to scope the result to a different workspace, or the provider query parameter to filter by upstream provider. Management key required.

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.byok.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 { byokList } from "@openrouter/sdk/funcs/byokList.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 byokList(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("byokList failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.ListBYOKKeysRequest✔️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<operations.ListBYOKKeysResponse>

Errors

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

create

Create a new bring-your-own-key (BYOK) provider credential. The raw key is encrypted at rest and never returned in API responses. Defaults to the authenticated entity’s default workspace; use the workspace_id body field to scope to a different workspace. Management key required.

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.byok.create({
12 createBYOKKeyRequest: {
13 key: "sk-proj-abc123...",
14 name: "Production OpenAI Key",
15 provider: "openai",
16 },
17 });
18
19 console.log(result);
20}
21
22run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { byokCreate } from "@openrouter/sdk/funcs/byokCreate.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 byokCreate(openRouter, {
15 createBYOKKeyRequest: {
16 key: "sk-proj-abc123...",
17 name: "Production OpenAI Key",
18 provider: "openai",
19 },
20 });
21 if (res.ok) {
22 const { value: result } = res;
23 console.log(result);
24 } else {
25 console.log("byokCreate failed:", res.error);
26 }
27}
28
29run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreateBYOKKeyRequest✔️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.CreateBYOKKeyResponse>

Errors

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

delete

Delete (soft-delete) a bring-your-own-key (BYOK) provider credential by its id. The encrypted key material is wiped and the record is marked as deleted. Management key required.

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.byok.delete({
12 id: "11111111-2222-3333-4444-555555555555",
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 { byokDelete } from "@openrouter/sdk/funcs/byokDelete.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 byokDelete(openRouter, {
15 id: "11111111-2222-3333-4444-555555555555",
16 });
17 if (res.ok) {
18 const { value: result } = res;
19 console.log(result);
20 } else {
21 console.log("byokDelete failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.DeleteBYOKKeyRequest✔️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.DeleteBYOKKeyResponse>

Errors

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

get

Get a single bring-your-own-key (BYOK) provider credential by its id. Management key required.

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.byok.get({
12 id: "11111111-2222-3333-4444-555555555555",
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 { byokGet } from "@openrouter/sdk/funcs/byokGet.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 byokGet(openRouter, {
15 id: "11111111-2222-3333-4444-555555555555",
16 });
17 if (res.ok) {
18 const { value: result } = res;
19 console.log(result);
20 } else {
21 console.log("byokGet failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.GetBYOKKeyRequest✔️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.GetBYOKKeyResponse>

Errors

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

update

Update an existing bring-your-own-key (BYOK) provider credential by its id. Include the key field to rotate the raw provider API key in-place (the previous key material is overwritten). Management key required.

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.byok.update({
12 id: "11111111-2222-3333-4444-555555555555",
13 updateBYOKKeyRequest: {
14 disabled: false,
15 name: "Updated OpenAI Key",
16 },
17 });
18
19 console.log(result);
20}
21
22run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { byokUpdate } from "@openrouter/sdk/funcs/byokUpdate.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 byokUpdate(openRouter, {
15 id: "11111111-2222-3333-4444-555555555555",
16 updateBYOKKeyRequest: {
17 disabled: false,
18 name: "Updated OpenAI Key",
19 },
20 });
21 if (res.ok) {
22 const { value: result } = res;
23 console.log(result);
24 } else {
25 console.log("byokUpdate failed:", res.error);
26 }
27}
28
29run();

Parameters

ParameterTypeRequiredDescription
requestoperations.UpdateBYOKKeyRequest✔️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.UpdateBYOKKeyResponse>

Errors

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