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

# Create a new constraint

> **Required scope:** write

**Required scope:** `write`

### Request body

`CreateConstraintRequest`

<ParamField body="description" type="string" required>
  Human-readable description
</ParamField>

<ParamField body="expression" type="string" required>
  Logical expression in NSR-L syntax
</ParamField>

<ParamField body="id" type="string" required>
  Unique constraint identifier
</ParamField>

<ParamField body="source" type="string">
  Source of the constraint
</ParamField>

<ParamField body="strength" type="ConstraintStrengthRequest" required />

### Response

`ConstraintResponse`

<ResponseField name="description" type="string" required />

<ResponseField name="expression" type="string" required />

<ResponseField name="id" type="string" required />

<ResponseField name="source" type="string" required />

<ResponseField name="strength" type="ConstraintStrengthRequest" required>
  <Expandable title="ConstraintStrengthRequest">
    <ResponseField name="type" type="string" required />
  </Expandable>
</ResponseField>

### Status codes

| Code  | Meaning                                            |
| ----- | -------------------------------------------------- |
| `201` | Constraint created                                 |
| `400` | Invalid constraint                                 |
| `401` | Unauthorized — missing or invalid credentials      |
| `403` | Forbidden — the key/token lacks the required scope |
| `409` | Constraint already exists                          |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/api/v1/constraints' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "description": "Cannot ship before payment received",
    "expression": "shipped(X) -> paid(X)",
    "id": "ship_after_payment",
    "source": "domain_rule",
    "strength": {
      "type": "hard"
    }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "description": "Two-person tent, green — replacement for damaged pole set.",
    "expression": "string",
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "source": "string",
    "strength": {
      "type": "hard"
    }
  }
  ```
</ResponseExample>
