Guardrails

Create a guardrail

Create a new guardrail for the authenticated user. A newly created guardrail enforces nothing until it is assigned to API keys or organization members; workspace_id places the guardrail in a workspace but does not apply it to that workspace's traffic. To restrict all traffic in a workspace, update the workspace's default guardrail instead. Management key required.

post/guardrails

Request body

allowed_data_regionsGuardrailDataRegion[] nullable

Data regions through which requests governed by this guardrail must arrive. global is https://openrouter.ai, europe is https://eu.openrouter.ai, and us is https://us.openrouter.ai. Requests arriving through any other region are rejected. null leaves the ingress region unrestricted. When several guardrails apply (workspace default, member, API key), the effective regions are the intersection of every non-null value. An empty array is rejected.

allowed_modelsstring[] nullable

Array of model identifiers (slug or canonical_slug accepted)

allowed_providersstring[] nullable

List of allowed provider IDs

descriptionstring nullable

Description of the guardrail

enable_free_model_publicationboolean nullable

Whether this guardrail allows free endpoints that publish prompts.

enable_free_model_trainingboolean nullable

Whether this guardrail allows free endpoints that train on request data.

enable_paid_model_trainingboolean nullable

Whether this guardrail allows paid endpoints that train on request data.

enforce_zdrboolean nullable

Deprecated. Use enforce_zdr_anthropic, enforce_zdr_openai, enforce_zdr_google, enforce_zdr_xai, 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.

enforce_zdr_anthropicboolean nullable

Whether to enforce zero data retention for Anthropic models. Falls back to enforce_zdr when not provided.

enforce_zdr_googleboolean nullable

Whether to enforce zero data retention for Google models. Falls back to enforce_zdr when not provided.

enforce_zdr_openaiboolean nullable

Whether to enforce zero data retention for OpenAI models. Falls back to enforce_zdr when not provided.

enforce_zdr_otherboolean nullable

Whether to enforce zero data retention for models that are not from Anthropic, OpenAI, Google, or xAI. Falls back to enforce_zdr when not provided.

enforce_zdr_xaiboolean nullable

Whether to enforce zero data retention for xAI models. Falls back to enforce_zdr when not provided.

ignored_modelsstring[] nullable

Array of model identifiers to exclude from routing (slug or canonical_slug accepted)

ignored_providersstring[] nullable

List of provider IDs to exclude from routing

include_byok_in_budgetsboolean

Whether BYOK (bring-your-own-key) inference spend counts toward this guardrail's limit_usd, in addition to OpenRouter credit spend. Defaults to false.

limit_usdnumber double nullable

Spending limit in USD. Must be provided together with reset_interval: a request that sets only one of the two is rejected with a 400.

namestring required

Name for the new guardrail

reset_interval'daily' | 'weekly' | 'monthly' | 'null' nullable

Interval at which the limit resets (daily, weekly, monthly)

workspace_idstring uuid

The workspace to create the guardrail in. When omitted, the guardrail is created in the default workspace; if that default has been deleted, the request returns a 400 and you must pass workspace_id explicitly. This only places the guardrail in the workspace; the created guardrail enforces nothing for that workspace's traffic until it is assigned to API keys or members. To restrict all traffic in a workspace, update the workspace's default guardrail instead.

Example request

{
  "allowed_models": null,
  "allowed_providers": [
    "openai",
    "anthropic",
    "deepseek"
  ],
  "content_filter_builtins": [
    {
      "action": "block",
      "slug": "regex-prompt-injection"
    }
  ],
  "content_filters": null,
  "description": "A guardrail for limiting API usage",
  "enforce_zdr_anthropic": true,
  "enforce_zdr_google": false,
  "enforce_zdr_openai": true,
  "enforce_zdr_other": false,
  "enforce_zdr_xai": false,
  "ignored_models": null,
  "ignored_providers": null,
  "limit_usd": 50,
  "name": "My New Guardrail",
  "reset_interval": "monthly"
}

Response

Guardrail created successfully

Example response

{
  "data": {
    "allowed_models": null,
    "allowed_providers": [
      "openai",
      "anthropic",
      "google"
    ],
    "content_filter_builtins": [
      {
        "action": "redact",
        "label": "[EMAIL]",
        "slug": "email"
      }
    ],
    "content_filters": null,
    "created_at": "2025-08-24T10:30:00Z",
    "description": "A guardrail for limiting API usage",
    "enable_free_model_publication": false,
    "enable_free_model_training": true,
    "enable_paid_model_training": true,
    "enforce_zdr": null,
    "enforce_zdr_anthropic": true,
    "enforce_zdr_google": false,
    "enforce_zdr_openai": true,
    "enforce_zdr_other": false,
    "enforce_zdr_xai": false,
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "ignored_models": null,
    "ignored_providers": null,
    "include_byok_in_budgets": false,
    "limit_usd": 50,
    "name": "My New Guardrail",
    "reset_interval": "monthly",
    "updated_at": null,
    "workspace_id": "0df9e665-d932-5740-b2c7-b52af166bc11"
  }
}

Changes