> ## Documentation Index > Fetch the complete documentation index at: https://openrouter.ai/docs/llms.txt > Use this file to discover all available pages before exploring further. # Guardrail Policies > Guardrail Policies endpoints ## Overview Guardrail Policies endpoints ### Available Operations * [list\_account\_policies](#list_account_policies) - List workspace-wide policies * [create\_account\_policy](#create_account_policy) - Create a workspace-wide policy * [delete\_account\_policy](#delete_account_policy) - Delete a workspace-wide policy * [update\_account\_policy](#update_account_policy) - Update a workspace-wide policy * [get\_api\_key\_policy\_assignment](#get_api_key_policy_assignment) - Get an API key policy assignment * [change\_api\_key\_policy\_assignment](#change_api_key_policy_assignment) - Change an API key policy assignment * [get\_member\_policy\_assignment](#get_member_policy_assignment) - Get a member policy assignment * [change\_member\_policy\_assignment](#change_member_policy_assignment) - Change a member policy assignment * [list\_budget\_policies](#list_budget_policies) - List budget policies * [create\_budget\_policy](#create_budget_policy) - Create a budget policy * [delete\_budget\_policy](#delete_budget_policy) - Delete a budget policy * [get\_budget\_policy](#get_budget_policy) - Get a budget policy * [update\_budget\_policy](#update_budget_policy) - Update a budget policy * [list\_model\_availability\_policies](#list_model_availability_policies) - List model availability policies * [create\_model\_availability\_policy](#create_model_availability_policy) - Create a model availability policy * [delete\_model\_availability\_policy](#delete_model_availability_policy) - Delete a model availability policy * [get\_model\_availability\_policy](#get_model_availability_policy) - Get a model availability policy * [update\_model\_availability\_policy](#update_model_availability_policy) - Update a model availability policy * [list\_moderation\_policies](#list_moderation_policies) - List moderation policies * [create\_moderation\_policy](#create_moderation_policy) - Create a moderation policy * [delete\_moderation\_policy](#delete_moderation_policy) - Delete a moderation policy * [get\_moderation\_policy](#get_moderation_policy) - Get a moderation policy * [update\_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](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[operations.ListAccountPoliciesResponse](../../operations/listaccountpoliciesresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## create\_account\_policy Create a workspace-wide budget, moderation, or model availability policy. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/accountguardrailpolicyrequest.mdx) | ✔️ | 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | ### Response **[components.AccountGuardrailPolicyResponse](../../components/accountguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## delete\_account\_policy Delete a workspace-wide policy. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.DeleteGuardrailPolicyResponse](../../components/deleteguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## update\_account\_policy Replace a workspace-wide policy and its workspace coverage. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/accountguardrailpolicyrequest.mdx) | ✔️ | 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.AccountGuardrailPolicyResponse](../../components/accountguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## 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](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../operations/getapikeypolicyassignmentpolicytype.mdx) | ✔️ | 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. | | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.GuardrailPolicyAssignmentResponse](../../components/guardrailpolicyassignmentresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## change\_api\_key\_policy\_assignment Assign or unassign one policy for an API key. Fails with 409 when `expected_assignment` no longer matches the stored state. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailpolicyassignmentstate.mdx) | ✔️ | N/A | | | `policy_id` | *str* | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 | | `policy_type` | [components.ChangeGuardrailPolicyAssignmentRequestPolicyType](../../components/changeguardrailpolicyassignmentrequestpolicytype.mdx) | ✔️ | 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. | | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ChangeGuardrailPolicyAssignmentResponse](../../components/changeguardrailpolicyassignmentresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## 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](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../operations/getmemberpolicyassignmentpolicytype.mdx) | ✔️ | 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. | | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.GuardrailPolicyAssignmentResponse](../../components/guardrailpolicyassignmentresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## change\_member\_policy\_assignment Assign or unassign one policy for a member. Fails with 409 when `expected_assignment` no longer matches the stored state. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailpolicyassignmentstate.mdx) | ✔️ | N/A | | | `policy_id` | *str* | ✔️ | Policy ID | 550e8400-e29b-41d4-a716-446655440000 | | `policy_type` | [components.ChangeGuardrailPolicyAssignmentRequestPolicyType](../../components/changeguardrailpolicyassignmentrequestpolicytype.mdx) | ✔️ | 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. | | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ChangeGuardrailPolicyAssignmentResponse](../../components/changeguardrailpolicyassignmentresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## list\_budget\_policies List the budget policies in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[operations.ListBudgetPoliciesResponse](../../operations/listbudgetpoliciesresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## create\_budget\_policy Create a budget policy in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailbudgetpolicyauthoringconfig.mdx) | ✔️ | N/A | \{ "include\_byok\_in\_budgets": false, "limit\_usd": 200, "reset\_interval": "monthly" } | | `name` | *str* | ✔️ | Policy name | Engineering monthly budget | | `policy_type` | [components.CreateBudgetGuardrailPolicyRequestPolicyType](../../components/createbudgetguardrailpolicyrequestpolicytype.mdx) | ✔️ | 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" ] | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.BudgetGuardrailPolicyResponse](../../components/budgetguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## delete\_budget\_policy Delete a budget policy. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.DeleteGuardrailPolicyResponse](../../components/deleteguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## get\_budget\_policy Get a budget policy with its member and API key assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.BudgetGuardrailPolicyDetailResponse](../../components/budgetguardrailpolicydetailresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## update\_budget\_policy Replace a budget policy's name and config, and optionally its assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailbudgetpolicyauthoringconfig.mdx) | ✔️ | 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.BudgetGuardrailPolicyResponse](../../components/budgetguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## list\_model\_availability\_policies List the model availability policies in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[operations.ListModelAvailabilityPoliciesResponse](../../operations/listmodelavailabilitypoliciesresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## create\_model\_availability\_policy Create a model availability policy in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailmodelavailabilitypolicyauthoringconfig.mdx) | ✔️ | 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](../../components/createmodelavailabilityguardrailpolicyrequestpolicytype.mdx) | ✔️ | 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" ] | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModelAvailabilityGuardrailPolicyResponse](../../components/modelavailabilityguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## delete\_model\_availability\_policy Delete a model availability policy. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.DeleteGuardrailPolicyResponse](../../components/deleteguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## get\_model\_availability\_policy Get a model availability policy with its member and API key assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModelAvailabilityGuardrailPolicyDetailResponse](../../components/modelavailabilityguardrailpolicydetailresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## update\_model\_availability\_policy Replace a model availability policy's name and config, and optionally its assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailmodelavailabilitypolicyauthoringconfig.mdx) | ✔️ | 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModelAvailabilityGuardrailPolicyResponse](../../components/modelavailabilityguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## list\_moderation\_policies List the moderation policies in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[operations.ListModerationPoliciesResponse](../../operations/listmoderationpoliciesresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## create\_moderation\_policy Create a moderation policy in a workspace. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter, components import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailmoderationpolicyconfig.mdx) | ✔️ | N/A | \{ "content\_filter\_builtins": \[ \{ "action": "block", "slug": "secrets" } ] } | | `name` | *str* | ✔️ | Policy name | Engineering monthly budget | | `policy_type` | [components.CreateModerationGuardrailPolicyRequestPolicyType](../../components/createmoderationguardrailpolicyrequestpolicytype.mdx) | ✔️ | 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" ] | | `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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModerationGuardrailPolicyResponse](../../components/moderationguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## delete\_moderation\_policy Delete a moderation policy. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.DeleteGuardrailPolicyResponse](../../components/deleteguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## get\_moderation\_policy Get a moderation policy with its member and API key assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModerationGuardrailPolicyDetailResponse](../../components/moderationguardrailpolicydetailresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## update\_moderation\_policy Replace a moderation policy's name and config, and optionally its assignments. [Management key](https://openrouter.ai/docs/client-sdks/python/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```python theme={null} from openrouter import OpenRouter, components import os with OpenRouter( http_referer="", x_open_router_title="", x_open_router_categories="", 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](../../components/guardrailmoderationpolicyconfig.mdx) | ✔️ | 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\]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response **[components.ModerationGuardrailPolicyResponse](../../components/moderationguardrailpolicyresponse.mdx)** ### Errors | Error Type | Status Code | Content Type | | - | - | - | | errors.BadRequestResponseError | 400 | application/json | | errors.UnauthorizedResponseError | 401 | application/json | | errors.ForbiddenResponseError | 403 | application/json | | errors.NotFoundResponseError | 404 | application/json | | errors.ConflictResponseError | 409 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* |