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_scim_group_policy_assignments - List SCIM group policy assignments
- get_scim_group_policy_assignment - Get a SCIM group policy assignment
- update_scim_group_policy_assignment - Update a SCIM group policy assignment
- delete_scim_group_policy_opt_out - Restore a member to a SCIM group policy
- list_scim_group_policy_opt_outs - List opt-outs from a SCIM group 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_capacity_policies - List capacity policies
- create_capacity_policy - Create a capacity policy
- delete_capacity_policy - Delete a capacity policy
- get_capacity_policy - Get a capacity policy
- update_capacity_policy - Update a capacity 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", 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 |
policy_type | operations.GetAPIKeyPolicyAssignmentPolicyType | ✔️ | Policy type the assignment is read or changed for. rate_limit is an Enterprise private beta feature and requires an organization-scoped management key and an explicit workspace_id. | 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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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. rate_limit is an Enterprise private beta feature and requires an organization-scoped management key and an explicit workspace_id. | 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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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", 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 |
policy_type | operations.GetMemberPolicyAssignmentPolicyType | ✔️ | Policy type the assignment is read or changed for. rate_limit is an Enterprise private beta feature and requires an organization-scoped management key and an explicit workspace_id. | 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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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. rate_limit is an Enterprise private beta feature and requires an organization-scoped management key and an explicit workspace_id. | 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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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_scim_group_policy_assignments
List the guardrail policies attached to each SCIM group mapping in the organization. Requiresscim:view and guardrails:view. Enterprise private beta feature. 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_scim_group_policy_assignments()
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
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.ListScimGroupPolicyAssignmentsResponseErrors
| 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_scim_group_policy_assignment
Get the guardrail policies attached to one SCIM group mapping. Requiresscim:view and guardrails:view. Enterprise private beta feature. 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_scim_group_policy_assignment(mapping_id="af65e842-2eb2-4feb-bc51-929aca5a7147")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mapping_id | str | ✔️ | 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.ScimGroupPolicyAssignmentResponseErrors
| 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_scim_group_policy_assignment
Attach or remove guardrail policies on one SCIM group mapping, then update its members’ policies. Every type in the request is applied, or none is. Requiresscim:view, guardrails:view and guardrails:update. Enterprise private beta feature. 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_scim_group_policy_assignment(mapping_id="10d15a71-fe5b-43e7-a9cc-284d994de944")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mapping_id | str | ✔️ | 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. |
budget | OptionalNullable[str] | ➖ | N/A |
model_availability | OptionalNullable[str] | ➖ | N/A |
moderation | OptionalNullable[str] | ➖ | N/A |
rate_limit | OptionalNullable[str] | ➖ | N/A |
retries | Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
components.ScimGroupPolicyAssignmentResponseErrors
| 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_scim_group_policy_opt_out
Remove a member’s opt-out for one policy type, so the member receives their groups’ policy again right away. The member must be in the mapping’s group and the mapping must set a policy of that type. Requiresscim:view, guardrails:view and guardrails:update. Enterprise private beta feature. 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_scim_group_policy_opt_out(mapping_id="104dbbf4-a30b-427e-8207-76203c3fadc5", user_id="<id>", policy_type="rate_limit")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mapping_id | str | ✔️ | N/A |
user_id | str | ✔️ | N/A |
policy_type | operations.DeleteScimGroupPolicyOptOutPolicyType | ✔️ | 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.DeleteScimGroupOptOutResponseErrors
| 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_scim_group_policy_opt_outs
List the group’s members who opted out of a guardrail policy this mapping sets, per policy type. Opted-out members keep their own assignment (or none) instead of the group policy. Requiresscim:view and guardrails:view. Enterprise private beta feature. 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_scim_group_policy_opt_outs(mapping_id="732784db-8051-4b40-9258-0ffc259c47ec")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mapping_id | str | ✔️ | 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.ListScimGroupOptOutsResponseErrors
| 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 |
|---|---|---|---|---|
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 |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 | |
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” ] |
move_existing_assignments | Optional[bool] | ➖ | When creating a new workspace default, also move the replaced default policy’s explicit member and API key assignments onto this policy. Defaults to false. | |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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_capacity_policies
List the capacity policies in a workspace. Enterprise private beta feature. 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_capacity_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 capacity policy belongs to. Capacity policies require an organization-scoped management key. | 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.ListCapacityPoliciesResponseErrors
| 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_capacity_policy
Create a capacity policy in a workspace. Enterprise private beta feature. 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_capacity_policy(config={
"bucket_by": [
"member",
"model",
],
"limits": [
{
"limit": 100000,
"models": "all",
"unit": "tokens",
},
],
}, name="Engineering monthly budget", policy_type="rate_limit", workspace_id="0df9e665-d932-5740-b2c7-b52af166bc11")
# Handle response
print(res)
Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
config | components.GuardrailCapacityPolicyConfig | ✔️ | N/A | { “bucket_by”: [ “member”, “model” ], “limits”: [ { “limit”: 100000, “models”: “all”, “unit”: “tokens” } ] } |
name | str | ✔️ | Policy name | Engineering monthly budget |
policy_type | components.CreateCapacityGuardrailPolicyRequestPolicyType | ✔️ | N/A | |
workspace_id | str | ✔️ | Workspace the capacity policy belongs to. Capacity policies require an organization-scoped management key. | 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” ] |
move_existing_assignments | Optional[bool] | ➖ | When creating a new workspace default, also move the replaced default policy’s explicit member and API key assignments onto this policy. Defaults to false. | |
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.CapacityGuardrailPolicyResponseErrors
| 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_capacity_policy
Delete a capacity policy. Enterprise private beta feature. 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_capacity_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 capacity policy belongs to. Capacity policies require an organization-scoped management key. | 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_capacity_policy
Get a capacity policy with its member and API key assignments. Enterprise private beta feature. 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_capacity_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 capacity policy belongs to. Capacity policies require an organization-scoped management key. | 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.CapacityGuardrailPolicyDetailResponseErrors
| 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_capacity_policy
Replace a capacity policy’s name and config, and optionally its assignments. Enterprise private beta feature. 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_capacity_policy(id="550e8400-e29b-41d4-a716-446655440000", config={
"bucket_by": [
"member",
"model",
],
"limits": [
{
"limit": 100000,
"models": "all",
"unit": "tokens",
},
],
}, 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.GuardrailCapacityPolicyConfig | ✔️ | N/A | { “bucket_by”: [ “member”, “model” ], “limits”: [ { “limit”: 100000, “models”: “all”, “unit”: “tokens” } ] } |
name | str | ✔️ | Policy name | Engineering monthly budget |
workspace_id | str | ✔️ | Workspace the capacity policy belongs to. Capacity policies require an organization-scoped management key. | 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.CapacityGuardrailPolicyResponseErrors
| 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 |
|---|---|---|---|---|
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 |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 | |
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” ] |
move_existing_assignments | Optional[bool] | ➖ | When creating a new workspace default, also move the replaced default policy’s explicit member and API key assignments onto this policy. Defaults to false. | |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
|---|---|---|---|---|
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 |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 | |
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” ] |
move_existing_assignments | Optional[bool] | ➖ | When creating a new workspace default, also move the replaced default policy’s explicit member and API key assignments onto this policy. Defaults to false. | |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 |
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. | |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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")
# 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 |
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” ] |
workspace_id | Optional[str] | ➖ | Workspace the policy belongs to. Required for an organization management key; a workspace-scoped key defaults to its own workspace and gets 403 for any other. | 0df9e665-d932-5740-b2c7-b52af166bc11 |
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 | */* |