> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lyzr.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create RAI Policy

**POST** `/v1/rai/policies`\
Create a new Responsible AI (RAI) policy.

## Description

This endpoint allows creating a new RAI policy including configuration for topics, keywords, toxicity checks, prompt injection protection, and PII/secrets detection.

## Request

**Headers**

* `x-api-key`: API key for authentication (required)
* `Content-Type`: `application/json`

**Request Body**

```json theme={null}
{
  "name": "string",
  "description": "string",
  "allowed_topics": {
    "enabled": false,
    "topics": []
  },
  "banned_topics": {
    "enabled": false,
    "topics": []
  },
  "keywords": {
    "enabled": false,
    "keywords": []
  },
  "toxicity_check": {
    "enabled": true,
    "threshold": 1
  },
  "prompt_injection": {
    "enabled": true,
    "threshold": 1
  },
  "secrets_detection": {
    "enabled": true,
    "action": "mask"
  },
  "pii_detection": {
    "enabled": true,
    "types": {},
    "custom_pii": [
      {
        "label": "string",
        "replacement": "string",
        "action": "redact"
      }
    ]
  },
  "user_id": "string",
  "created_at": "2025-05-16T10:55:33.101Z",
  "updated_at": "2025-05-16T10:55:33.101Z"
}
```

## Response

### 200 OK

```json theme={null}
{
  "_id": "string",
  "name": "string",
  "description": "string",
  "allowed_topics": {
    "enabled": false,
    "topics": []
  },
  "banned_topics": {
    "enabled": false,
    "topics": []
  },
  "keywords": {
    "enabled": false,
    "keywords": []
  },
  "toxicity_check": {
    "enabled": true,
    "threshold": 1
  },
  "prompt_injection": {
    "enabled": true,
    "threshold": 1
  },
  "secrets_detection": {
    "enabled": true,
    "action": "mask"
  },
  "pii_detection": {
    "enabled": true,
    "types": {},
    "custom_pii": [
      {
        "label": "string",
        "replacement": "string",
        "action": "redact"
      }
    ]
  },
  "user_id": "string",
  "created_at": "2025-05-16T10:55:33.116Z",
  "updated_at": "2025-05-16T10:55:33.116Z"
}
```

### 422 Unprocessable Entity

```json theme={null}
{
  "detail": [
    {
      "loc": ["string", 0],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Curl Example

```bash theme={null}
curl -X 'POST'   'https://rai-prod.studio.lyzr.ai/v1/rai/policies'   -H 'accept: application/json'   -H 'x-api-key: sk-default-Bk19s6ZUGIBoBkJNdkJ8YfcPLwULRXcH'   -H 'Content-Type: application/json'   -d '{...}'
```


## OpenAPI

````yaml post /v1/rai/policies
openapi: 3.0.3
info:
  title: RAI Policy API
  version: 1.0.0
  description: API for managing RAI policies.
servers:
  - url: https://rai-prod.studio.lyzr.ai
security: []
paths:
  /v1/rai/policies:
    post:
      tags:
        - RAI
      summary: Create Policy
      description: Create a new RAI policy.
      operationId: createPolicy
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                allowed_topics:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    topics:
                      type: array
                      items:
                        type: string
                banned_topics:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    topics:
                      type: array
                      items:
                        type: string
                keywords:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    keywords:
                      type: array
                      items:
                        type: string
                toxicity_check:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    threshold:
                      type: number
                prompt_injection:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    threshold:
                      type: number
                secrets_detection:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    action:
                      type: string
                pii_detection:
                  type: object
                  properties:
                    enabled:
                      type: boolean
                    types:
                      type: object
                      additionalProperties:
                        type: string
                    custom_pii:
                      type: array
                      items:
                        type: object
                        properties:
                          label:
                            type: string
                          replacement:
                            type: string
                          action:
                            type: string
                user_id:
                  type: string
                created_at:
                  type: string
                  format: date-time
                updated_at:
                  type: string
                  format: date-time
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  _id:
                    type: string
                  name:
                    type: string
                  description:
                    type: string
                  allowed_topics:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      topics:
                        type: array
                        items:
                          type: string
                  banned_topics:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      topics:
                        type: array
                        items:
                          type: string
                  keywords:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      keywords:
                        type: array
                        items:
                          type: string
                  toxicity_check:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      threshold:
                        type: number
                  prompt_injection:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      threshold:
                        type: number
                  secrets_detection:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      action:
                        type: string
                  pii_detection:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                      types:
                        type: object
                        additionalProperties:
                          type: string
                      custom_pii:
                        type: array
                        items:
                          type: object
                          properties:
                            label:
                              type: string
                            replacement:
                              type: string
                            action:
                              type: string
                  user_id:
                    type: string
                  created_at:
                    type: string
                    format: date-time
                  updated_at:
                    type: string
                    format: date-time
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: array
                    items:
                      type: object
                      properties:
                        loc:
                          type: array
                          items:
                            type: string
                        msg:
                          type: string
                        type:
                          type: string
      security:
        - ApiKeyAuth: []
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````