Overview
Guardrail Policies endpointsAvailable Operations
- list_account_policies - List workspace-wide policies
- create_account_policy - Create a workspace-wide policy
- delete_account_policy - Delete a workspace-wide policy
- update_account_policy - Update a workspace-wide policy
- get_api_key_policy_assignment - Get an API key policy assignment
- change_api_key_policy_assignment - Change an API key policy assignment
- get_member_policy_assignment - Get a member policy assignment
- change_member_policy_assignment - Change a member policy assignment
- list_budget_policies - List budget policies
- create_budget_policy - Create a budget policy
- delete_budget_policy - Delete a budget policy
- get_budget_policy - Get a budget policy
- update_budget_policy - Update a budget policy
- list_model_availability_policies - List model availability policies
- create_model_availability_policy - Create a model availability policy
- delete_model_availability_policy - Delete a model availability policy
- get_model_availability_policy - Get a model availability policy
- update_model_availability_policy - Update a model availability policy
- list_moderation_policies - List moderation policies
- create_moderation_policy - Create a moderation policy
- delete_moderation_policy - Delete a moderation policy
- get_moderation_policy - Get a moderation policy
- update_moderation_policy - Update a moderation policy
list_account_policies
List the workspace-wide policies that apply across workspaces in the account. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.list_account_policies()
while res is not None:
# Handle items
res = res.next()
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
offset | Optional[int] | ➖ | Number of records to skip for pagination. When both offset and limit are omitted, the full list is returned | 0 |
limit | Optional[int] | ➖ | Maximum number of records to return (max 100). When both offset and limit are omitted, the full list is returned | 50 |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
operations.ListAccountPoliciesResponseErrors
| 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 | */* |
create_account_policy
Create a workspace-wide budget, moderation, or model availability policy. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.create_account_policy(account_guardrail_policy_request={
"config": {
"include_byok_in_budgets": False,
"limit_usd": 200.0,
"reset_interval": "monthly",
},
"name": "Engineering monthly budget",
"policy_type": "budget",
})
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
account_guardrail_policy_request | components.AccountGuardrailPolicyRequest | ✔️ | N/A |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.AccountGuardrailPolicyResponseErrors
| 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 | */* |
delete_account_policy
Delete a workspace-wide policy. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.delete_account_policy(id="550e8400-e29b-41d4-a716-446655440000")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.DeleteGuardrailPolicyResponseErrors
| 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 | */* |
update_account_policy
Replace a workspace-wide policy and its workspace coverage. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.update_account_policy(id="550e8400-e29b-41d4-a716-446655440000", account_guardrail_policy_request={
"config": {
"include_byok_in_budgets": False,
"limit_usd": 200.0,
"reset_interval": "monthly",
},
"name": "Engineering monthly budget",
"policy_type": "budget",
})
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
account_guardrail_policy_request | components.AccountGuardrailPolicyRequest | ✔️ | N/A | |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.AccountGuardrailPolicyResponseErrors
| 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 | */* |
get_api_key_policy_assignment
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
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.get_api_key_policy_assignment(hash="c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11", policy_type="budget")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
hash | str | ✔️ | API key hash | c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
policy_type | operations.GetAPIKeyPolicyAssignmentPolicyType | ✔️ | Policy type the assignment is read or changed for | budget |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.GuardrailPolicyAssignmentResponseErrors
| 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 | */* |
change_api_key_policy_assignment
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
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.change_api_key_policy_assignment(hash="c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93", assigned=True, expected_assignment={
"opted_out": False,
"policy_ids": [],
"workspace_default_policy_ids": [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
}, policy_id="550e8400-e29b-41d4-a716-446655440000", policy_type="budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
hash | str | ✔️ | API key hash | c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93 |
assigned | bool | ✔️ | true assigns the policy to the subject, false removes it | true |
expected_assignment | components.GuardrailPolicyAssignmentState | ✔️ | N/A | |
policy_id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
policy_type | components.ChangeGuardrailPolicyAssignmentRequestPolicyType | ✔️ | Policy type the assignment is read or changed for | budget |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ChangeGuardrailPolicyAssignmentResponseErrors
| 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 | */* |
get_member_policy_assignment
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
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.get_member_policy_assignment(member_id="user_2abcDEFghiJKLmnoPQRstu", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11", policy_type="budget")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
member_id | str | ✔️ | Organization member user ID | user_2abcDEFghiJKLmnoPQRstu |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
policy_type | operations.GetMemberPolicyAssignmentPolicyType | ✔️ | Policy type the assignment is read or changed for | budget |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.GuardrailPolicyAssignmentResponseErrors
| 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 | */* |
change_member_policy_assignment
Assign or unassign one policy for a member. Fails with 409 whenexpected_assignment no longer matches the stored state. Management key required.
Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.change_member_policy_assignment(member_id="user_2abcDEFghiJKLmnoPQRstu", assigned=True, expected_assignment={
"opted_out": False,
"policy_ids": [],
"workspace_default_policy_ids": [
"2c6f1a4e-0b7d-4e59-9a61-3f8d2e7c1b90",
],
}, policy_id="550e8400-e29b-41d4-a716-446655440000", policy_type="budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
member_id | str | ✔️ | Organization member user ID | user_2abcDEFghiJKLmnoPQRstu |
assigned | bool | ✔️ | true assigns the policy to the subject, false removes it | true |
expected_assignment | components.GuardrailPolicyAssignmentState | ✔️ | N/A | |
policy_id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
policy_type | components.ChangeGuardrailPolicyAssignmentRequestPolicyType | ✔️ | Policy type the assignment is read or changed for | budget |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ChangeGuardrailPolicyAssignmentResponseErrors
| 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 | */* |
list_budget_policies
List the budget policies in a workspace. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.list_budget_policies(workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
while res is not None:
# Handle items
res = res.next()
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
offset | Optional[int] | ➖ | Number of records to skip for pagination. When both offset and limit are omitted, the full list is returned | 0 |
limit | Optional[int] | ➖ | Maximum number of records to return (max 100). When both offset and limit are omitted, the full list is returned | 50 |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
operations.ListBudgetPoliciesResponseErrors
| 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 | */* |
create_budget_policy
Create a budget policy in a workspace. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.create_budget_policy(config={
"include_byok_in_budgets": False,
"limit_usd": 200.0,
"reset_interval": "monthly",
}, name="Engineering monthly budget", policy_type="budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
config | components.GuardrailBudgetPolicyAuthoringConfig | ✔️ | N/A | { “include_byok_in_budgets”: false, “limit_usd”: 200, “reset_interval”: “monthly” } |
name | str | ✔️ | Policy name | Engineering monthly budget |
policy_type | components.CreateBudgetGuardrailPolicyRequestPolicyType | ✔️ | N/A | |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Make this the workspace default for its policy type. Defaults to false. | |
member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API keys that should not inherit the policy when it is the workspace default | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Members that should not inherit the policy when it is the workspace default | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.BudgetGuardrailPolicyResponseErrors
| 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 | */* |
delete_budget_policy
Delete a budget policy. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.delete_budget_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.DeleteGuardrailPolicyResponseErrors
| 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 | */* |
get_budget_policy
Get a budget policy with its member and API key assignments. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.get_budget_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.BudgetGuardrailPolicyDetailResponseErrors
| 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 | */* |
update_budget_policy
Replace a budget policy’s name and config, and optionally its assignments. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.update_budget_policy(id="550e8400-e29b-41d4-a716-446655440000", config={
"include_byok_in_budgets": False,
"limit_usd": 200.0,
"reset_interval": "monthly",
}, name="Engineering monthly budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
config | components.GuardrailBudgetPolicyAuthoringConfig | ✔️ | N/A | { “include_byok_in_budgets”: false, “limit_usd”: 200, “reset_interval”: “monthly” } |
name | str | ✔️ | Policy name | Engineering monthly budget |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | Complete new list of assigned API keys. Send together with member_ids, or omit both to keep the stored assignments. | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Omit to keep the stored default status; false unsets the policy as the workspace default. | |
member_ids | List[str] | ➖ | Complete new list of assigned members. Send together with api_key_hashes, or omit both to keep the stored assignments. | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.BudgetGuardrailPolicyResponseErrors
| 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 | */* |
list_model_availability_policies
List the model availability policies in a workspace. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.list_model_availability_policies(workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
while res is not None:
# Handle items
res = res.next()
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
offset | Optional[int] | ➖ | Number of records to skip for pagination. When both offset and limit are omitted, the full list is returned | 0 |
limit | Optional[int] | ➖ | Maximum number of records to return (max 100). When both offset and limit are omitted, the full list is returned | 50 |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
operations.ListModelAvailabilityPoliciesResponseErrors
| 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 | */* |
create_model_availability_policy
Create a model availability policy in a workspace. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.create_model_availability_policy(config={}, name="Engineering monthly budget", policy_type="model_availability", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
config | components.GuardrailModelAvailabilityPolicyAuthoringConfig | ✔️ | N/A | { “allowed_models”: [ “openai/gpt-4o”, “anthropic/claude-sonnet-4” ], “allowed_providers”: [ “openai”, “anthropic” ], “enforce_zdr_anthropic”: true, “enforce_zdr_openai”: true } |
name | str | ✔️ | Policy name | Engineering monthly budget |
policy_type | components.CreateModelAvailabilityGuardrailPolicyRequestPolicyType | ✔️ | N/A | |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Make this the workspace default for its policy type. Defaults to false. | |
member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API keys that should not inherit the policy when it is the workspace default | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Members that should not inherit the policy when it is the workspace default | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModelAvailabilityGuardrailPolicyResponseErrors
| 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 | */* |
delete_model_availability_policy
Delete a model availability policy. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.delete_model_availability_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.DeleteGuardrailPolicyResponseErrors
| 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 | */* |
get_model_availability_policy
Get a model availability policy with its member and API key assignments. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.get_model_availability_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModelAvailabilityGuardrailPolicyDetailResponseErrors
| 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 | */* |
update_model_availability_policy
Replace a model availability policy’s name and config, and optionally its assignments. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.update_model_availability_policy(id="550e8400-e29b-41d4-a716-446655440000", config={}, name="Engineering monthly budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
config | components.GuardrailModelAvailabilityPolicyAuthoringConfig | ✔️ | N/A | { “allowed_models”: [ “openai/gpt-4o”, “anthropic/claude-sonnet-4” ], “allowed_providers”: [ “openai”, “anthropic” ], “enforce_zdr_anthropic”: true, “enforce_zdr_openai”: true } |
name | str | ✔️ | Policy name | Engineering monthly budget |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | Complete new list of assigned API keys. Send together with member_ids, or omit both to keep the stored assignments. | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Omit to keep the stored default status; false unsets the policy as the workspace default. | |
member_ids | List[str] | ➖ | Complete new list of assigned members. Send together with api_key_hashes, or omit both to keep the stored assignments. | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModelAvailabilityGuardrailPolicyResponseErrors
| 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 | */* |
list_moderation_policies
List the moderation policies in a workspace. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.list_moderation_policies(workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
while res is not None:
# Handle items
res = res.next()
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
offset | Optional[int] | ➖ | Number of records to skip for pagination. When both offset and limit are omitted, the full list is returned | 0 |
limit | Optional[int] | ➖ | Maximum number of records to return (max 100). When both offset and limit are omitted, the full list is returned | 50 |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
operations.ListModerationPoliciesResponseErrors
| 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 | */* |
create_moderation_policy
Create a moderation policy in a workspace. Management key required.Example Usage
from openrouter import OpenRouter, components
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.create_moderation_policy(config=components.GuardrailModerationPolicyConfig(), name="Engineering monthly budget", policy_type="moderation", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
config | components.GuardrailModerationPolicyConfig | ✔️ | N/A | { “content_filter_builtins”: [ { “action”: “block”, “slug”: “secrets” } ] } |
name | str | ✔️ | Policy name | Engineering monthly budget |
policy_type | components.CreateModerationGuardrailPolicyRequestPolicyType | ✔️ | N/A | |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Make this the workspace default for its policy type. Defaults to false. | |
member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API keys that should not inherit the policy when it is the workspace default | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Members that should not inherit the policy when it is the workspace default | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModerationGuardrailPolicyResponseErrors
| 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 | */* |
delete_moderation_policy
Delete a moderation policy. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.delete_moderation_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.DeleteGuardrailPolicyResponseErrors
| 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 | */* |
get_moderation_policy
Get a moderation policy with its member and API key assignments. Management key required.Example Usage
from openrouter import OpenRouter
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.get_moderation_policy(id="550e8400-e29b-41d4-a716-446655440000", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModerationGuardrailPolicyDetailResponseErrors
| 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 | */* |
update_moderation_policy
Replace a moderation policy’s name and config, and optionally its assignments. Management key required.Example Usage
from openrouter import OpenRouter, components
import os
with OpenRouter(
http_referer="<value>",
x_open_router_title="<value>",
x_open_router_categories="<value>",
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.guardrail_policies.update_moderation_policy(id="550e8400-e29b-41d4-a716-446655440000", config=components.GuardrailModerationPolicyConfig(), name="Engineering monthly budget", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
id | str | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 |
config | components.GuardrailModerationPolicyConfig | ✔️ | N/A | { “content_filter_builtins”: [ { “action”: “block”, “slug”: “secrets” } ] } |
name | str | ✔️ | Policy name | Engineering monthly budget |
workspace_id | str | ✔️ | Workspace the policy belongs to | 0df9e665-d932-5740-b2c7-b52af166bc11 |
http_referer | Optional[str] | ➖ | The app identifier should be your app’s URL and is used as the primary identifier for rankings. This is used to track API usage per application. | |
x_open_router_title | Optional[str] | ➖ | The app display name allows you to customize how your app appears in OpenRouter’s dashboard. | |
x_open_router_categories | Optional[str] | ➖ | Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings. | |
api_key_hashes | List[str] | ➖ | Complete new list of assigned API keys. Send together with member_ids, or omit both to keep the stored assignments. | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
is_workspace_default | Optional[bool] | ➖ | Omit to keep the stored default status; false unsets the policy as the workspace default. | |
member_ids | List[str] | ➖ | Complete new list of assigned members. Send together with api_key_hashes, or omit both to keep the stored assignments. | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
opted_out_api_key_hashes | List[str] | ➖ | API key hashes | [ “c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93” ] |
opted_out_member_ids | List[str] | ➖ | Organization member user IDs | [ “user_2abcDEFghiJKLmnoPQRstu” ] |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ModerationGuardrailPolicyResponseErrors
| 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 | */* |