> ## 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.

# Generate an explanation for a query

> Generate a post-hoc explanation for a query. **Required scope:** write

Generate a post-hoc explanation for a query.

**Required scope:** `write`

### Request body

`ExplainRequest`

<ParamField body="query" type="string" required>
  The query to explain
</ParamField>

<ParamField body="session_id" type="string">
  Session ID for context
</ParamField>

<ParamField body="style" type="string">
  Explanation style: 'symbolic', 'neural', 'contrastive'
</ParamField>

### Response

`ExplainResponse`

<ResponseField name="components" type="object">
  <Expandable title="components">
    <ResponseField name="decision_points" type="string[]" required>
      Key decision points
    </ResponseField>

    <ResponseField name="perception" type="string" required>
      Perception explanation
    </ResponseField>

    <ResponseField name="semantics" type="string" required>
      Semantic computation explanation
    </ResponseField>

    <ResponseField name="syntax" type="string" required>
      Syntax (parsing) explanation
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="enabled" type="boolean" required>
  Whether explainability is enabled
</ResponseField>

<ResponseField name="explanation" type="string">
  Human-readable explanation
</ResponseField>

### Status codes

| Code  | Meaning                                            |
| ----- | -------------------------------------------------- |
| `200` | Explanation generated                              |
| `400` | Invalid request                                    |
| `401` | Unauthorized — missing or invalid credentials      |
| `403` | Forbidden — the key/token lacks the required scope |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset |
| `500` | Failed to generate explanation                     |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/api/v1/explain' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "query": "string",
    "session_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "style": "string"
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "components": {
      "decision_points": [
        "string"
      ],
      "perception": "string",
      "semantics": "string",
      "syntax": "49.00"
    },
    "enabled": true,
    "explanation": "string"
  }
  ```
</ResponseExample>
