For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
  • Python SDK
    • Overview
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • Go SDK
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Overview
  • Available Operations
  • list
  • Example Usage
  • Parameters
  • Response
  • Errors
  • create
  • Example Usage
  • Parameters
  • Response
  • Errors
  • delete
  • Example Usage
  • Parameters
  • Response
  • Errors
  • get
  • Example Usage
  • Parameters
  • Response
  • Errors
  • update
  • Example Usage
  • Parameters
  • Response
  • Errors
  • list_guardrail_key_assignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • bulk_assign_keys
  • Example Usage
  • Parameters
  • Response
  • Errors
  • bulk_unassign_keys
  • Example Usage
  • Parameters
  • Response
  • Errors
  • list_guardrail_member_assignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • bulk_assign_members
  • Example Usage
  • Parameters
  • Response
  • Errors
  • bulk_unassign_members
  • Example Usage
  • Parameters
  • Response
  • Errors
  • list_key_assignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • list_member_assignments
  • Example Usage
  • Parameters
  • Response
  • Errors
Python SDKAPI Reference

Guardrails - Python SDK

Guardrails method reference
Was this page helpful?
Previous

Models - Python SDK

Models method reference
Next
Built with

The Python SDK and docs are currently in beta. Report issues on GitHub.

Overview

Guardrails endpoints

Available Operations

  • list - List guardrails
  • create - Create a guardrail
  • delete - Delete a guardrail
  • get - Get a guardrail
  • update - Update a guardrail
  • list_guardrail_key_assignments - List key assignments for a guardrail
  • bulk_assign_keys - Bulk assign keys to a guardrail
  • bulk_unassign_keys - Bulk unassign keys from a guardrail
  • list_guardrail_member_assignments - List member assignments for a guardrail
  • bulk_assign_members - Bulk assign members to a guardrail
  • bulk_unassign_members - Bulk unassign members from a guardrail
  • list_key_assignments - List all key assignments
  • list_member_assignments - List all member assignments

list

List all guardrails for the authenticated user. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.list()
12
13 while res is not None:
14 # Handle items
15
16 res = res.next()

Parameters

ParameterTypeRequiredDescriptionExample
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
offsetOptional[int]➖Number of records to skip for pagination0
limitOptional[int]➖Maximum number of records to return (max 100)50
workspace_idOptional[str]➖Filter guardrails by workspace ID. By default, guardrails in the default workspace are returned.0df9e665-d932-5740-b2c7-b52af166bc11
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

operations.ListGuardrailsResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

create

Create a new guardrail for the authenticated user. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.create(name="My New Guardrail", allowed_models=None, allowed_providers=[
12 "openai",
13 "anthropic",
14 "deepseek",
15 ], description="A guardrail for limiting API usage", enforce_zdr_anthropic=True, enforce_zdr_google=False, enforce_zdr_openai=True, enforce_zdr_other=False, ignored_models=None, ignored_providers=None, limit_usd=50, reset_interval="monthly")
16
17 # Handle response
18 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
namestr✔️Name for the new guardrailMy New Guardrail
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
allowed_modelsList[str]➖Array of model identifiers (slug or canonical_slug accepted)[
“openai/gpt-5.2”,
“anthropic/claude-4.5-opus-20251124”,
“deepseek/deepseek-r1-0528:free”
]
allowed_providersList[str]➖List of allowed provider IDs[
“openai”,
“anthropic”,
“deepseek”
]
content_filter_builtinsList[components.ContentFilterBuiltinEntry]➖Builtin content filters to apply. The “flag” action is only supported for “regex-prompt-injection”; PII slugs (email, phone, ssn, credit-card, ip-address, person-name, address) accept “block” or “redact” only.[
{"action": "block","slug": "regex-prompt-injection"}
]
content_filtersList[components.ContentFilterEntry]➖Custom regex content filters to apply to request messages[
{"action": "redact","label": "[API_KEY]","pattern": "\\b(sk-[a-zA-Z0-9]{48})\b”
}
]
descriptionOptionalNullable[str]➖Description of the guardrailA guardrail for limiting API usage
enforce_zdrOptionalNullable[bool]➖: warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

Deprecated. Use enforce_zdr_anthropic, enforce_zdr_openai, enforce_zdr_google, and enforce_zdr_other instead. When provided, its value is copied into any of those per-provider fields that are not explicitly specified on the request.
false
enforce_zdr_anthropicOptionalNullable[bool]➖Whether to enforce zero data retention for Anthropic models. Falls back to enforce_zdr when not provided.false
enforce_zdr_googleOptionalNullable[bool]➖Whether to enforce zero data retention for Google models. Falls back to enforce_zdr when not provided.false
enforce_zdr_openaiOptionalNullable[bool]➖Whether to enforce zero data retention for OpenAI models. Falls back to enforce_zdr when not provided.false
enforce_zdr_otherOptionalNullable[bool]➖Whether to enforce zero data retention for models that are not from Anthropic, OpenAI, or Google. Falls back to enforce_zdr when not provided.false
ignored_modelsList[str]➖Array of model identifiers to exclude from routing (slug or canonical_slug accepted)[
“openai/gpt-4o-mini”
]
ignored_providersList[str]➖List of provider IDs to exclude from routing[
“azure”
]
limit_usdOptionalNullable[float]➖Spending limit in USD50
reset_intervalOptionalNullable[components.GuardrailInterval]➖Interval at which the limit resets (daily, weekly, monthly)monthly
workspace_idOptional[str]➖The workspace to create the guardrail in. Defaults to the default workspace if not provided.0df9e665-d932-5740-b2c7-b52af166bc11
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.CreateGuardrailResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.ForbiddenResponseError403application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

delete

Delete an existing guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.delete(id="550e8400-e29b-41d4-a716-446655440000")
12
13 # Handle response
14 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail to delete550e8400-e29b-41d4-a716-446655440000
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.DeleteGuardrailResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

get

Get a single guardrail by ID. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.get(id="550e8400-e29b-41d4-a716-446655440000")
12
13 # Handle response
14 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail to retrieve550e8400-e29b-41d4-a716-446655440000
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.GetGuardrailResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

update

Update an existing guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.update(id="550e8400-e29b-41d4-a716-446655440000", description="Updated description", limit_usd=75, name="Updated Guardrail Name", reset_interval="weekly")
12
13 # Handle response
14 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail to update550e8400-e29b-41d4-a716-446655440000
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
allowed_modelsList[str]➖Array of model identifiers (slug or canonical_slug accepted)[
“openai/gpt-5.2”
]
allowed_providersList[str]➖New list of allowed provider IDs[
“openai”,
“anthropic”,
“deepseek”
]
content_filter_builtinsList[components.ContentFilterBuiltinEntry]➖Builtin content filters to apply. Set to null to remove. The “flag” action is only supported for “regex-prompt-injection”; PII slugs (email, phone, ssn, credit-card, ip-address, person-name, address) accept “block” or “redact” only.[
{"action": "block","slug": "regex-prompt-injection"}
]
content_filtersList[components.ContentFilterEntry]➖Custom regex content filters to apply. Set to null to remove.<nil>
descriptionOptionalNullable[str]➖New description for the guardrailUpdated description
enforce_zdrOptionalNullable[bool]➖: warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.

Deprecated. Use enforce_zdr_anthropic, enforce_zdr_openai, enforce_zdr_google, and enforce_zdr_other instead. When provided, its value is copied into any of those per-provider fields that are not explicitly specified on the request.
true
enforce_zdr_anthropicOptionalNullable[bool]➖Whether to enforce zero data retention for Anthropic models. Falls back to enforce_zdr when not provided.true
enforce_zdr_googleOptionalNullable[bool]➖Whether to enforce zero data retention for Google models. Falls back to enforce_zdr when not provided.true
enforce_zdr_openaiOptionalNullable[bool]➖Whether to enforce zero data retention for OpenAI models. Falls back to enforce_zdr when not provided.true
enforce_zdr_otherOptionalNullable[bool]➖Whether to enforce zero data retention for models that are not from Anthropic, OpenAI, or Google. Falls back to enforce_zdr when not provided.true
ignored_modelsList[str]➖Array of model identifiers to exclude from routing (slug or canonical_slug accepted)[
“openai/gpt-4o-mini”
]
ignored_providersList[str]➖List of provider IDs to exclude from routing[
“azure”
]
limit_usdOptionalNullable[float]➖New spending limit in USD75
nameOptional[str]➖New name for the guardrailUpdated Guardrail Name
reset_intervalOptionalNullable[components.GuardrailInterval]➖Interval at which the limit resets (daily, weekly, monthly)monthly
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.UpdateGuardrailResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

list_guardrail_key_assignments

List all API key assignments for a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.list_guardrail_key_assignments(id="550e8400-e29b-41d4-a716-446655440000")
12
13 while res is not None:
14 # Handle items
15
16 res = res.next()

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
offsetOptional[int]➖Number of records to skip for pagination0
limitOptional[int]➖Maximum number of records to return (max 100)50
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

operations.ListGuardrailKeyAssignmentsResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

bulk_assign_keys

Assign multiple API keys to a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.bulk_assign_keys(id="550e8400-e29b-41d4-a716-446655440000", key_hashes=[
12 "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
13 ])
14
15 # Handle response
16 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
key_hashesList[str]✔️Array of API key hashes to assign to the guardrail[
“c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93”
]
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.BulkAssignKeysResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

bulk_unassign_keys

Unassign multiple API keys from a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.bulk_unassign_keys(id="550e8400-e29b-41d4-a716-446655440000", key_hashes=[
12 "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
13 ])
14
15 # Handle response
16 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
key_hashesList[str]✔️Array of API key hashes to unassign from the guardrail[
“c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93”
]
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.BulkUnassignKeysResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

list_guardrail_member_assignments

List all organization member assignments for a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.list_guardrail_member_assignments(id="550e8400-e29b-41d4-a716-446655440000")
12
13 while res is not None:
14 # Handle items
15
16 res = res.next()

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
offsetOptional[int]➖Number of records to skip for pagination0
limitOptional[int]➖Maximum number of records to return (max 100)50
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

operations.ListGuardrailMemberAssignmentsResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

bulk_assign_members

Assign multiple organization members to a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.bulk_assign_members(id="550e8400-e29b-41d4-a716-446655440000", member_user_ids=[
12 "user_abc123",
13 "user_def456",
14 ])
15
16 # Handle response
17 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
member_user_idsList[str]✔️Array of member user IDs to assign to the guardrail[
“user_abc123”,
“user_def456”
]
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.BulkAssignMembersResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

bulk_unassign_members

Unassign multiple organization members from a specific guardrail. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.bulk_unassign_members(id="550e8400-e29b-41d4-a716-446655440000", member_user_ids=[
12 "user_abc123",
13 "user_def456",
14 ])
15
16 # Handle response
17 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
idstr✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
member_user_idsList[str]✔️Array of member user IDs to unassign from the guardrail[
“user_abc123”,
“user_def456”
]
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

components.BulkUnassignMembersResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

list_key_assignments

List all API key guardrail assignments for the authenticated user. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.list_key_assignments()
12
13 while res is not None:
14 # Handle items
15
16 res = res.next()

Parameters

ParameterTypeRequiredDescriptionExample
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
offsetOptional[int]➖Number of records to skip for pagination0
limitOptional[int]➖Maximum number of records to return (max 100)50
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

operations.ListKeyAssignmentsResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

list_member_assignments

List all organization member guardrail assignments for the authenticated user. Management key required.

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 http_referer="<value>",
6 x_open_router_title="<value>",
7 x_open_router_categories="<value>",
8 api_key=os.getenv("OPENROUTER_API_KEY", ""),
9) as open_router:
10
11 res = open_router.guardrails.list_member_assignments()
12
13 while res is not None:
14 # Handle items
15
16 res = res.next()

Parameters

ParameterTypeRequiredDescriptionExample
http_refererOptional[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_titleOptional[str]➖The app display name allows you to customize how your app appears in OpenRouter’s dashboard.
x_open_router_categoriesOptional[str]➖Comma-separated list of app categories (e.g. “cli-agent,cloud-agent”). Used for marketplace rankings.
offsetOptional[int]➖Number of records to skip for pagination0
limitOptional[int]➖Maximum number of records to return (max 100)50
retriesOptional[utils.RetryConfig]➖Configuration to override the default retry behavior of the client.

Response

operations.ListMemberAssignmentsResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*