Overview
Guardrail Policies endpointsAvailable Operations
- listAccountPolicies - List workspace-wide policies
- createAccountPolicy - Create a workspace-wide policy
- deleteAccountPolicy - Delete a workspace-wide policy
- updateAccountPolicy - Update a workspace-wide policy
- getApiKeyPolicyAssignment - Get an API key policy assignment
- changeApiKeyPolicyAssignment - Change an API key policy assignment
- getMemberPolicyAssignment - Get a member policy assignment
- changeMemberPolicyAssignment - Change a member policy assignment
- listBudgetPolicies - List budget policies
- createBudgetPolicy - Create a budget policy
- deleteBudgetPolicy - Delete a budget policy
- getBudgetPolicy - Get a budget policy
- updateBudgetPolicy - Update a budget policy
- listModelAvailabilityPolicies - List model availability policies
- createModelAvailabilityPolicy - Create a model availability policy
- deleteModelAvailabilityPolicy - Delete a model availability policy
- getModelAvailabilityPolicy - Get a model availability policy
- updateModelAvailabilityPolicy - Update a model availability policy
- listModerationPolicies - List moderation policies
- createModerationPolicy - Create a moderation policy
- deleteModerationPolicy - Delete a moderation policy
- getModerationPolicy - Get a moderation policy
- updateModerationPolicy - Update a moderation policy
listAccountPolicies
List the workspace-wide policies that apply across workspaces in the account. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.listAccountPolicies();
for await (const page of result) {
console.log(page);
}
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesListAccountPolicies } from "@openrouter/sdk/funcs/guardrailPoliciesListAccountPolicies.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesListAccountPolicies(openRouter);
if (res.ok) {
const { value: result } = res;
for await (const page of result) {
console.log(page);
}
} else {
console.log("guardrailPoliciesListAccountPolicies failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListAccountPoliciesRequest | ✔️ | 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.ListAccountPoliciesResponse>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 | */* |
createAccountPolicy
Create a workspace-wide budget, moderation, or model availability policy. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.createAccountPolicy({
accountGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesCreateAccountPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesCreateAccountPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesCreateAccountPolicy(openRouter, {
accountGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesCreateAccountPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateAccountPolicyRequest | ✔️ | 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.AccountGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
deleteAccountPolicy
Delete a workspace-wide policy. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.deleteAccountPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesDeleteAccountPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesDeleteAccountPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesDeleteAccountPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesDeleteAccountPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteAccountPolicyRequest | ✔️ | 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.DeleteGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
updateAccountPolicy
Replace a workspace-wide policy and its workspace coverage. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.updateAccountPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
accountGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesUpdateAccountPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesUpdateAccountPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesUpdateAccountPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
accountGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesUpdateAccountPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateAccountPolicyRequest | ✔️ | 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.AccountGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
getApiKeyPolicyAssignment
Get the policies of one type that apply to an API key in a workspace. Requires a management key with write access. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.getApiKeyPolicyAssignment({
hash: "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
policyType: "budget",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesGetApiKeyPolicyAssignment } from "@openrouter/sdk/funcs/guardrailPoliciesGetApiKeyPolicyAssignment.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesGetApiKeyPolicyAssignment(openRouter, {
hash: "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
policyType: "budget",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesGetApiKeyPolicyAssignment failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetApiKeyPolicyAssignmentRequest | ✔️ | 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.GuardrailPolicyAssignmentResponse>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 | */* |
changeApiKeyPolicyAssignment
Assign or unassign one policy for an API key. Fails with 409 whenexpected_assignment no longer matches the stored state. Management key required.
Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.changeApiKeyPolicyAssignment({
hash: "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
changeGuardrailPolicyAssignmentRequest: {
assigned: true,
expectedAssignment: {
optedOut: false,
policyIds: [],
workspaceDefaultPolicyIds: [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
},
policyId: "550e8400-e29b-41d4-a716-446655440000",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesChangeApiKeyPolicyAssignment } from "@openrouter/sdk/funcs/guardrailPoliciesChangeApiKeyPolicyAssignment.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesChangeApiKeyPolicyAssignment(openRouter, {
hash: "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
changeGuardrailPolicyAssignmentRequest: {
assigned: true,
expectedAssignment: {
optedOut: false,
policyIds: [],
workspaceDefaultPolicyIds: [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
},
policyId: "550e8400-e29b-41d4-a716-446655440000",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesChangeApiKeyPolicyAssignment failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ChangeApiKeyPolicyAssignmentRequest | ✔️ | 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.ChangeGuardrailPolicyAssignmentResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
getMemberPolicyAssignment
Get the policies of one type that apply to a member in a workspace. Requires a management key with write access. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.getMemberPolicyAssignment({
memberId: "user_2abcDEFghiJKLmnoPQRstu",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
policyType: "budget",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesGetMemberPolicyAssignment } from "@openrouter/sdk/funcs/guardrailPoliciesGetMemberPolicyAssignment.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesGetMemberPolicyAssignment(openRouter, {
memberId: "user_2abcDEFghiJKLmnoPQRstu",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
policyType: "budget",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesGetMemberPolicyAssignment failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetMemberPolicyAssignmentRequest | ✔️ | 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.GuardrailPolicyAssignmentResponse>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 | */* |
changeMemberPolicyAssignment
Assign or unassign one policy for a member. Fails with 409 whenexpected_assignment no longer matches the stored state. Management key required.
Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.changeMemberPolicyAssignment({
memberId: "user_2abcDEFghiJKLmnoPQRstu",
changeGuardrailPolicyAssignmentRequest: {
assigned: true,
expectedAssignment: {
optedOut: false,
policyIds: [],
workspaceDefaultPolicyIds: [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
},
policyId: "550e8400-e29b-41d4-a716-446655440000",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesChangeMemberPolicyAssignment } from "@openrouter/sdk/funcs/guardrailPoliciesChangeMemberPolicyAssignment.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesChangeMemberPolicyAssignment(openRouter, {
memberId: "user_2abcDEFghiJKLmnoPQRstu",
changeGuardrailPolicyAssignmentRequest: {
assigned: true,
expectedAssignment: {
optedOut: false,
policyIds: [],
workspaceDefaultPolicyIds: [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
},
policyId: "550e8400-e29b-41d4-a716-446655440000",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesChangeMemberPolicyAssignment failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ChangeMemberPolicyAssignmentRequest | ✔️ | 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.ChangeGuardrailPolicyAssignmentResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
listBudgetPolicies
List the budget policies in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.listBudgetPolicies({
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
for await (const page of result) {
console.log(page);
}
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesListBudgetPolicies } from "@openrouter/sdk/funcs/guardrailPoliciesListBudgetPolicies.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesListBudgetPolicies(openRouter, {
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
for await (const page of result) {
console.log(page);
}
} else {
console.log("guardrailPoliciesListBudgetPolicies failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListBudgetPoliciesRequest | ✔️ | 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.ListBudgetPoliciesResponse>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 | */* |
createBudgetPolicy
Create a budget policy in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.createBudgetPolicy({
createBudgetGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesCreateBudgetPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesCreateBudgetPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesCreateBudgetPolicy(openRouter, {
createBudgetGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
policyType: "budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesCreateBudgetPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateBudgetPolicyRequest | ✔️ | 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.BudgetGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
deleteBudgetPolicy
Delete a budget policy. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.deleteBudgetPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesDeleteBudgetPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesDeleteBudgetPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesDeleteBudgetPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesDeleteBudgetPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteBudgetPolicyRequest | ✔️ | 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.DeleteGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
getBudgetPolicy
Get a budget policy with its member and API key assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.getBudgetPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesGetBudgetPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesGetBudgetPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesGetBudgetPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesGetBudgetPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetBudgetPolicyRequest | ✔️ | 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.BudgetGuardrailPolicyDetailResponse>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 | */* |
updateBudgetPolicy
Replace a budget policy’s name and config, and optionally its assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.updateBudgetPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
updateBudgetGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesUpdateBudgetPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesUpdateBudgetPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesUpdateBudgetPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
updateBudgetGuardrailPolicyRequest: {
config: {
includeByokInBudgets: false,
limitUsd: 200,
resetInterval: "monthly",
},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesUpdateBudgetPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateBudgetPolicyRequest | ✔️ | 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.BudgetGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
listModelAvailabilityPolicies
List the model availability policies in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.listModelAvailabilityPolicies({
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
for await (const page of result) {
console.log(page);
}
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesListModelAvailabilityPolicies } from "@openrouter/sdk/funcs/guardrailPoliciesListModelAvailabilityPolicies.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesListModelAvailabilityPolicies(openRouter, {
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
for await (const page of result) {
console.log(page);
}
} else {
console.log("guardrailPoliciesListModelAvailabilityPolicies failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListModelAvailabilityPoliciesRequest | ✔️ | 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.ListModelAvailabilityPoliciesResponse>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 | */* |
createModelAvailabilityPolicy
Create a model availability policy in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.createModelAvailabilityPolicy({
createModelAvailabilityGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
policyType: "model_availability",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesCreateModelAvailabilityPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesCreateModelAvailabilityPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesCreateModelAvailabilityPolicy(openRouter, {
createModelAvailabilityGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
policyType: "model_availability",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesCreateModelAvailabilityPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateModelAvailabilityPolicyRequest | ✔️ | 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.ModelAvailabilityGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
deleteModelAvailabilityPolicy
Delete a model availability policy. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.deleteModelAvailabilityPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesDeleteModelAvailabilityPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesDeleteModelAvailabilityPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesDeleteModelAvailabilityPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesDeleteModelAvailabilityPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteModelAvailabilityPolicyRequest | ✔️ | 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.DeleteGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
getModelAvailabilityPolicy
Get a model availability policy with its member and API key assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.getModelAvailabilityPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesGetModelAvailabilityPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesGetModelAvailabilityPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesGetModelAvailabilityPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesGetModelAvailabilityPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetModelAvailabilityPolicyRequest | ✔️ | 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.ModelAvailabilityGuardrailPolicyDetailResponse>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 | */* |
updateModelAvailabilityPolicy
Replace a model availability policy’s name and config, and optionally its assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.updateModelAvailabilityPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
updateModelAvailabilityGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesUpdateModelAvailabilityPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesUpdateModelAvailabilityPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesUpdateModelAvailabilityPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
updateModelAvailabilityGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesUpdateModelAvailabilityPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateModelAvailabilityPolicyRequest | ✔️ | 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.ModelAvailabilityGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
listModerationPolicies
List the moderation policies in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.listModerationPolicies({
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
for await (const page of result) {
console.log(page);
}
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesListModerationPolicies } from "@openrouter/sdk/funcs/guardrailPoliciesListModerationPolicies.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesListModerationPolicies(openRouter, {
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
for await (const page of result) {
console.log(page);
}
} else {
console.log("guardrailPoliciesListModerationPolicies failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListModerationPoliciesRequest | ✔️ | 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.ListModerationPoliciesResponse>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 | */* |
createModerationPolicy
Create a moderation policy in a workspace. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.createModerationPolicy({
createModerationGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
policyType: "moderation",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesCreateModerationPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesCreateModerationPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesCreateModerationPolicy(openRouter, {
createModerationGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
policyType: "moderation",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesCreateModerationPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateModerationPolicyRequest | ✔️ | 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.ModerationGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
deleteModerationPolicy
Delete a moderation policy. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.deleteModerationPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesDeleteModerationPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesDeleteModerationPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesDeleteModerationPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesDeleteModerationPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteModerationPolicyRequest | ✔️ | 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.DeleteGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
getModerationPolicy
Get a moderation policy with its member and API key assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.getModerationPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesGetModerationPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesGetModerationPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesGetModerationPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesGetModerationPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetModerationPolicyRequest | ✔️ | 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.ModerationGuardrailPolicyDetailResponse>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 | */* |
updateModerationPolicy
Replace a moderation policy’s name and config, and optionally its assignments. Management key required.Example Usage
import { OpenRouter } from "@openrouter/sdk";
const openRouter = new OpenRouter({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const result = await openRouter.guardrailPolicies.updateModerationPolicy({
id: "550e8400-e29b-41d4-a716-446655440000",
updateModerationGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:import { OpenRouterCore } from "@openrouter/sdk/core.js";
import { guardrailPoliciesUpdateModerationPolicy } from "@openrouter/sdk/funcs/guardrailPoliciesUpdateModerationPolicy.js";
// Use `OpenRouterCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openRouter = new OpenRouterCore({
httpReferer: "<value>",
appTitle: "<value>",
appCategories: "<value>",
apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
});
async function run() {
const res = await guardrailPoliciesUpdateModerationPolicy(openRouter, {
id: "550e8400-e29b-41d4-a716-446655440000",
updateModerationGuardrailPolicyRequest: {
config: {},
name: "Engineering monthly budget",
workspaceId: "0df9e665-d932-5740-b2c7-b52af166bc11",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("guardrailPoliciesUpdateModerationPolicy failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateModerationPolicyRequest | ✔️ | 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.ModerationGuardrailPolicyResponse>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.ConflictResponseError | 409 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |