For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.
Create a guardrail
POST https://modelgates.ai/api/v1/guardrails Content-Type: application/json
Create a new guardrail for the authenticated user. Management key required.
Reference: https://modelgates.ai/docs/api/api-reference/guardrails/create-guardrail
OpenAPI Specification
yaml
openapi: 3.1.0info: title: ModelGates API version: 1.0.0paths: /guardrails: post: operationId: create-guardrail summary: Create a guardrail description: >- Create a new guardrail for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. tags: - subpackage_guardrails parameters: - name: Authorization in: header description: API key as bearer token in Authorization header required: true schema: type: string responses: '201': description: Guardrail created successfully content: application/json: schema: $ref: '#/components/schemas/CreateGuardrailResponse' '400': description: Bad Request - Invalid request parameters or malformed input content: application/json: schema: $ref: '#/components/schemas/BadRequestResponse' '401': description: Unauthorized - Authentication required or invalid credentials content: application/json: schema: $ref: '#/components/schemas/UnauthorizedResponse' '403': description: Forbidden - Authentication successful but insufficient permissions content: application/json: schema: $ref: '#/components/schemas/ForbiddenResponse' '500': description: Internal Server Error - Unexpected server error content: application/json: schema: $ref: '#/components/schemas/InternalServerResponse' requestBody: content: application/json: schema: $ref: '#/components/schemas/CreateGuardrailRequest'servers: - url: https://modelgates.ai/api/v1components: schemas: ContentFilterBuiltinAction: type: string enum: - redact - block - flag description: Action taken when the builtin filter triggers title: ContentFilterBuiltinAction ContentFilterBuiltinSlug: type: string enum: - email - phone - ssn - credit-card - ip-address - person-name - address - regex-prompt-injection description: The builtin filter identifier title: ContentFilterBuiltinSlug ContentFilterBuiltinEntry: type: object properties: action: $ref: '#/components/schemas/ContentFilterBuiltinAction' label: type: string description: >- Optional label used in redaction placeholders (e.g. "[PROMPT_INJECTION]") slug: $ref: '#/components/schemas/ContentFilterBuiltinSlug' required: - action - slug description: >- A builtin content filter entry. Builtin filters include PII detectors and the regex-based prompt injection detector. title: ContentFilterBuiltinEntry ContentFilterAction: type: string enum: - redact - block description: Action taken when the pattern matches title: ContentFilterAction ContentFilterEntry: type: object properties: action: $ref: '#/components/schemas/ContentFilterAction' label: type: - string - 'null' description: Optional label used in redaction placeholders or error messages pattern: type: string description: A regex pattern to match against request content required: - action - pattern description: >- A custom regex content filter that scans request messages for matching patterns. title: ContentFilterEntry GuardrailInterval: type: string enum: - daily - weekly - monthly description: Interval at which the limit resets (daily, weekly, monthly) title: GuardrailInterval CreateGuardrailRequest: type: object properties: allowed_models: type: - array - 'null' items: type: string description: Array of model identifiers (slug or canonical_slug accepted) allowed_providers: type: - array - 'null' items: type: string description: List of allowed provider IDs content_filter_builtins: type: - array - 'null' items: $ref: '#/components/schemas/ContentFilterBuiltinEntry' description: >- 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. content_filters: type: - array - 'null' items: $ref: '#/components/schemas/ContentFilterEntry' description: Custom regex content filters to apply to request messages description: type: - string - 'null' description: Description of the guardrail enforce_zdr: type: - boolean - 'null' description: >- 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. enforce_zdr_anthropic: type: - boolean - 'null' description: >- Whether to enforce zero data retention for Anthropic models. Falls back to enforce_zdr when not provided. enforce_zdr_google: type: - boolean - 'null' description: >- Whether to enforce zero data retention for Google models. Falls back to enforce_zdr when not provided. enforce_zdr_openai: type: - boolean - 'null' description: >- Whether to enforce zero data retention for OpenAI models. Falls back to enforce_zdr when not provided. enforce_zdr_other: type: - boolean - 'null' description: >- Whether to enforce zero data retention for models that are not from Anthropic, OpenAI, or Google. Falls back to enforce_zdr when not provided. ignored_models: type: - array - 'null' items: type: string description: >- Array of model identifiers to exclude from routing (slug or canonical_slug accepted) ignored_providers: type: - array - 'null' items: type: string description: List of provider IDs to exclude from routing limit_usd: type: - number - 'null' format: double description: Spending limit in USD name: type: string description: Name for the new guardrail reset_interval: $ref: '#/components/schemas/GuardrailInterval' workspace_id: type: string format: uuid description: >- The workspace to create the guardrail in. Defaults to the default workspace if not provided. required: - name title: CreateGuardrailRequest CreateGuardrailResponseData: type: object properties: allowed_models: type: - array - 'null' items: type: string description: Array of model canonical_slugs (immutable identifiers) allowed_providers: type: - array - 'null' items: type: string description: List of allowed provider IDs content_filter_builtins: type: - array - 'null' items: $ref: '#/components/schemas/ContentFilterBuiltinEntry' description: >- Builtin content filters applied to requests. Includes PII detectors and the regex-based prompt injection detector. content_filters: type: - array - 'null' items: $ref: '#/components/schemas/ContentFilterEntry' description: Custom regex content filters applied to request messages created_at: type: string description: ISO 8601 timestamp of when the guardrail was created description: type: - string - 'null' description: Description of the guardrail enforce_zdr: type: - boolean - 'null' description: >- 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. enforce_zdr_anthropic: type: - boolean - 'null' description: >- Whether to enforce zero data retention for Anthropic models. Falls back to enforce_zdr when not provided. enforce_zdr_google: type: - boolean - 'null' description: >- Whether to enforce zero data retention for Google models. Falls back to enforce_zdr when not provided. enforce_zdr_openai: type: - boolean - 'null' description: >- Whether to enforce zero data retention for OpenAI models. Falls back to enforce_zdr when not provided. enforce_zdr_other: type: - boolean - 'null' description: >- Whether to enforce zero data retention for models that are not from Anthropic, OpenAI, or Google. Falls back to enforce_zdr when not provided. id: type: string format: uuid description: Unique identifier for the guardrail ignored_models: type: - array - 'null' items: type: string description: Array of model canonical_slugs to exclude from routing ignored_providers: type: - array - 'null' items: type: string description: List of provider IDs to exclude from routing limit_usd: type: - number - 'null' format: double description: Spending limit in USD name: type: string description: Name of the guardrail reset_interval: $ref: '#/components/schemas/GuardrailInterval' updated_at: type: - string - 'null' description: ISO 8601 timestamp of when the guardrail was last updated workspace_id: type: string description: The workspace ID this guardrail belongs to. required: - created_at - id - name - workspace_id description: The created guardrail title: CreateGuardrailResponseData CreateGuardrailResponse: type: object properties: data: $ref: '#/components/schemas/CreateGuardrailResponseData' required: - data title: CreateGuardrailResponse BadRequestResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for BadRequestResponse title: BadRequestResponseErrorData BadRequestResponse: type: object properties: error: $ref: '#/components/schemas/BadRequestResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Bad Request - Invalid request parameters or malformed input title: BadRequestResponse UnauthorizedResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for UnauthorizedResponse title: UnauthorizedResponseErrorData UnauthorizedResponse: type: object properties: error: $ref: '#/components/schemas/UnauthorizedResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Unauthorized - Authentication required or invalid credentials title: UnauthorizedResponse ForbiddenResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for ForbiddenResponse title: ForbiddenResponseErrorData ForbiddenResponse: type: object properties: error: $ref: '#/components/schemas/ForbiddenResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Forbidden - Authentication successful but insufficient permissions title: ForbiddenResponse InternalServerResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for InternalServerResponse title: InternalServerResponseErrorData InternalServerResponse: type: object properties: error: $ref: '#/components/schemas/InternalServerResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Internal Server Error - Unexpected server error title: InternalServerResponse securitySchemes: apiKey: type: http scheme: bearer description: API key as bearer token in Authorization headerSDK Code Examples
python
import requests url = "https://modelgates.ai/api/v1/guardrails" payload = { "name": "My New Guardrail", "allowed_models": None, "allowed_providers": ["openai", "anthropic", "deepseek"], "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"}headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json())