Workspaces - TypeScript SDK
Workspaces - TypeScript SDK
The TypeScript SDK and docs are currently in beta. Report issues on GitHub.
Overview
Workspaces endpoints
Available Operations
- list - List workspaces
- create - Create a workspace
- delete - Delete a workspace
- get - Get a workspace
- update - Update a workspace
- bulkAddMembers - Bulk add members to a workspace
- bulkRemoveMembers - Bulk remove members from a workspace
list
List all workspaces for the authenticated user. Management key required.
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.workspaces.list(); 12 13 for await (const page of result) { 14 console.log(page); 15 } 16 } 17 18 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 25 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListWorkspacesRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<operations.ListWorkspacesResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
create
Create a new workspace for the authenticated user. Management key required.
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async 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 25 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 32 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateWorkspaceRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.CreateWorkspaceResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 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
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.workspaces.delete({ 12 id: "production", 13 }); 14 15 console.log(result); 16 } 17 18 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 25 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteWorkspaceRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.DeleteWorkspaceResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
get
Get a single workspace by ID or slug. Management key required.
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.workspaces.get({ 12 id: "production", 13 }); 14 15 console.log(result); 16 } 17 18 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 25 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetWorkspaceRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.GetWorkspaceResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
update
Update an existing workspace by ID or slug. Management key required.
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async 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 22 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 29 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateWorkspaceRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.UpdateWorkspaceResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 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
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async 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 24 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 31 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.BulkAddWorkspaceMembersRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.BulkAddWorkspaceMembersResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
bulkRemoveMembers
Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. Management key required.
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async 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 24 run();
Standalone function
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { 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. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async 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 31 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.BulkRemoveWorkspaceMembersRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | 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.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<models.BulkRemoveWorkspaceMembersResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |