Workspaces - TypeScript SDK

Workspaces method reference

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

Overview

Workspaces endpoints

Available Operations

list

List all workspaces for the authenticated user. 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.workspaces.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 { workspacesList } from "@openrouter/sdk/funcs/workspacesList.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 workspacesList(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("workspacesList failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.ListWorkspacesRequest✔️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.ListWorkspacesResponse>

Errors

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

create

Create a new workspace for the authenticated user. 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.workspaces.create({
12 createWorkspaceRequest: {
13 defaultImageModel: "openai/dall-e-3",
14 defaultProviderSort: "price",
15 defaultTextModel: "openai/gpt-4o",
16 description: "Production environment workspace",
17 name: "Production",
18 slug: "production",
19 },
20 });
21
22 console.log(result);
23}
24
25run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { workspacesCreate } from "@openrouter/sdk/funcs/workspacesCreate.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 workspacesCreate(openRouter, {
15 createWorkspaceRequest: {
16 defaultImageModel: "openai/dall-e-3",
17 defaultProviderSort: "price",
18 defaultTextModel: "openai/gpt-4o",
19 description: "Production environment workspace",
20 name: "Production",
21 slug: "production",
22 },
23 });
24 if (res.ok) {
25 const { value: result } = res;
26 console.log(result);
27 } else {
28 console.log("workspacesCreate failed:", res.error);
29 }
30}
31
32run();

Parameters

ParameterTypeRequiredDescription
requestoperations.CreateWorkspaceRequest✔️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.CreateWorkspaceResponse>

Errors

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

delete

Delete an existing workspace. The default workspace cannot be deleted. Workspaces with active API keys cannot be 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.workspaces.delete({
12 id: "production",
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 { workspacesDelete } from "@openrouter/sdk/funcs/workspacesDelete.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 workspacesDelete(openRouter, {
15 id: "production",
16 });
17 if (res.ok) {
18 const { value: result } = res;
19 console.log(result);
20 } else {
21 console.log("workspacesDelete failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.DeleteWorkspaceRequest✔️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.DeleteWorkspaceResponse>

Errors

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

get

Get a single workspace by ID or slug. 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.workspaces.get({
12 id: "production",
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 { workspacesGet } from "@openrouter/sdk/funcs/workspacesGet.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 workspacesGet(openRouter, {
15 id: "production",
16 });
17 if (res.ok) {
18 const { value: result } = res;
19 console.log(result);
20 } else {
21 console.log("workspacesGet failed:", res.error);
22 }
23}
24
25run();

Parameters

ParameterTypeRequiredDescription
requestoperations.GetWorkspaceRequest✔️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.GetWorkspaceResponse>

Errors

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

update

Update an existing workspace by ID or slug. 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.workspaces.update({
12 id: "production",
13 updateWorkspaceRequest: {
14 name: "Updated Workspace",
15 slug: "updated-workspace",
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 { workspacesUpdate } from "@openrouter/sdk/funcs/workspacesUpdate.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 workspacesUpdate(openRouter, {
15 id: "production",
16 updateWorkspaceRequest: {
17 name: "Updated Workspace",
18 slug: "updated-workspace",
19 },
20 });
21 if (res.ok) {
22 const { value: result } = res;
23 console.log(result);
24 } else {
25 console.log("workspacesUpdate failed:", res.error);
26 }
27}
28
29run();

Parameters

ParameterTypeRequiredDescription
requestoperations.UpdateWorkspaceRequest✔️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.UpdateWorkspaceResponse>

Errors

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

bulkAddMembers

Add multiple organization members to a workspace. Members are assigned the same role they hold in the organization. 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.workspaces.bulkAddMembers({
12 id: "production",
13 bulkAddWorkspaceMembersRequest: {
14 userIds: [
15 "user_abc123",
16 "user_def456",
17 ],
18 },
19 });
20
21 console.log(result);
22}
23
24run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { workspacesBulkAddMembers } from "@openrouter/sdk/funcs/workspacesBulkAddMembers.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 workspacesBulkAddMembers(openRouter, {
15 id: "production",
16 bulkAddWorkspaceMembersRequest: {
17 userIds: [
18 "user_abc123",
19 "user_def456",
20 ],
21 },
22 });
23 if (res.ok) {
24 const { value: result } = res;
25 console.log(result);
26 } else {
27 console.log("workspacesBulkAddMembers failed:", res.error);
28 }
29}
30
31run();

Parameters

ParameterTypeRequiredDescription
requestoperations.BulkAddWorkspaceMembersRequest✔️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.BulkAddWorkspaceMembersResponse>

Errors

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

bulkRemoveMembers

Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. 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.workspaces.bulkRemoveMembers({
12 id: "production",
13 bulkRemoveWorkspaceMembersRequest: {
14 userIds: [
15 "user_abc123",
16 "user_def456",
17 ],
18 },
19 });
20
21 console.log(result);
22}
23
24run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { workspacesBulkRemoveMembers } from "@openrouter/sdk/funcs/workspacesBulkRemoveMembers.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 workspacesBulkRemoveMembers(openRouter, {
15 id: "production",
16 bulkRemoveWorkspaceMembersRequest: {
17 userIds: [
18 "user_abc123",
19 "user_def456",
20 ],
21 },
22 });
23 if (res.ok) {
24 const { value: result } = res;
25 console.log(result);
26 } else {
27 console.log("workspacesBulkRemoveMembers failed:", res.error);
28 }
29}
30
31run();

Parameters

ParameterTypeRequiredDescription
requestoperations.BulkRemoveWorkspaceMembersRequest✔️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.BulkRemoveWorkspaceMembersResponse>

Errors

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