> ## Documentation Index
> Fetch the complete documentation index at: https://superdoc-caio-pizzol-docs-ai-core-preset.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# create.heading

> Create a new heading at the target position.

## Summary

Create a new heading at the target position.

* Operation ID: `create.heading`
* API member path: `editor.doc.create.heading(...)`
* Mutates document: `yes`
* Idempotency: `non-idempotent`
* Supports tracked mode: `yes`
* Supports dry run: `yes`
* Deterministic target resolution: `yes`

## Expected result

Returns a CreateHeadingResult with the new heading block ID and address.

## Input fields

| Field   | Type                                                                                                        | Required | Description                                                                                                   |
| ------- | ----------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------- |
| `at`    | object(kind="documentStart") \| object(kind="documentEnd") \| object(kind="before") \| object(kind="after") | no       | One of: object(kind="documentStart"), object(kind="documentEnd"), object(kind="before"), object(kind="after") |
| `in`    | StoryLocator                                                                                                | no       | StoryLocator                                                                                                  |
| `level` | integer                                                                                                     | yes      |                                                                                                               |
| `text`  | string                                                                                                      | no       |                                                                                                               |

### Example request

```json theme={null}
{
  "at": {
    "kind": "documentStart"
  },
  "in": {
    "kind": "story",
    "storyType": "body"
  },
  "level": 1
}
```

## Output fields

### Variant 1 (success=true)

| Field                        | Type                    | Required | Description           |
| ---------------------------- | ----------------------- | -------- | --------------------- |
| `heading`                    | HeadingAddress          | yes      | HeadingAddress        |
| `heading.kind`               | `"block"`               | yes      | Constant: `"block"`   |
| `heading.nodeId`             | string                  | yes      |                       |
| `heading.nodeType`           | `"heading"`             | yes      | Constant: `"heading"` |
| `insertionPoint`             | TextAddress             | yes      | TextAddress           |
| `insertionPoint.blockId`     | string                  | yes      |                       |
| `insertionPoint.kind`        | `"text"`                | yes      | Constant: `"text"`    |
| `insertionPoint.range`       | Range                   | yes      | Range                 |
| `insertionPoint.range.end`   | integer                 | yes      |                       |
| `insertionPoint.range.start` | integer                 | yes      |                       |
| `ref`                        | string                  | no       |                       |
| `success`                    | `true`                  | yes      | Constant: `true`      |
| `trackedChangeRefs`          | TrackedChangeAddress\[] | no       |                       |

### Variant 2 (success=false)

| Field             | Type    | Required | Description        |
| ----------------- | ------- | -------- | ------------------ |
| `failure`         | object  | yes      |                    |
| `failure.code`    | enum    | yes      | `"INVALID_TARGET"` |
| `failure.details` | any     | no       |                    |
| `failure.message` | string  | yes      |                    |
| `success`         | `false` | yes      | Constant: `false`  |

### Example response

```json theme={null}
{
  "heading": {
    "kind": "block",
    "nodeId": "node-def456",
    "nodeType": "heading"
  },
  "insertionPoint": {
    "blockId": "block-abc123",
    "kind": "text",
    "range": {
      "end": 10,
      "start": 0
    }
  },
  "ref": "handle:abc123",
  "success": true,
  "trackedChangeRefs": [
    {
      "entityId": "entity-789",
      "entityType": "trackedChange",
      "kind": "entity",
      "story": {
        "kind": "story",
        "storyType": "body"
      }
    }
  ]
}
```

## Pre-apply throws

* `TARGET_NOT_FOUND`
* `CAPABILITY_UNAVAILABLE`
* `INVALID_TARGET`
* `AMBIGUOUS_TARGET`
* `STORY_NOT_FOUND`
* `STORY_MISMATCH`
* `STORY_NOT_SUPPORTED`
* `CROSS_STORY_PLAN`
* `MATERIALIZATION_FAILED`

## Non-applied failure codes

* `INVALID_TARGET`

## Raw schemas

<Accordion title="Raw input schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "at": {
        "description": "Position: {kind:'documentEnd'} to append, {kind:'documentStart'} to prepend, or {kind:'before'|'after', target:{kind:'block', nodeType:'...', nodeId:'...'}} for relative placement.",
        "oneOf": [
          {
            "additionalProperties": false,
            "properties": {
              "kind": {
                "const": "documentStart"
              }
            },
            "required": [
              "kind"
            ],
            "type": "object"
          },
          {
            "additionalProperties": false,
            "properties": {
              "kind": {
                "const": "documentEnd"
              }
            },
            "required": [
              "kind"
            ],
            "type": "object"
          },
          {
            "additionalProperties": false,
            "properties": {
              "kind": {
                "const": "before"
              },
              "target": {
                "$ref": "#/$defs/BlockNodeAddress"
              }
            },
            "required": [
              "kind",
              "target"
            ],
            "type": "object"
          },
          {
            "additionalProperties": false,
            "properties": {
              "kind": {
                "const": "after"
              },
              "target": {
                "$ref": "#/$defs/BlockNodeAddress"
              }
            },
            "required": [
              "kind",
              "target"
            ],
            "type": "object"
          }
        ]
      },
      "in": {
        "$ref": "#/$defs/StoryLocator"
      },
      "level": {
        "description": "Heading level (1-6).",
        "maximum": 6,
        "minimum": 1,
        "type": "integer"
      },
      "text": {
        "description": "Heading text content.",
        "type": "string"
      }
    },
    "required": [
      "level"
    ],
    "type": "object"
  }
  ```
</Accordion>

<Accordion title="Raw output schema">
  ```json theme={null}
  {
    "oneOf": [
      {
        "additionalProperties": false,
        "properties": {
          "heading": {
            "$ref": "#/$defs/HeadingAddress"
          },
          "insertionPoint": {
            "$ref": "#/$defs/TextAddress"
          },
          "ref": {
            "description": "Ref handle for the created block. Pass directly to superdoc_format or superdoc_edit ref param without searching.",
            "type": "string"
          },
          "success": {
            "const": true
          },
          "trackedChangeRefs": {
            "items": {
              "$ref": "#/$defs/TrackedChangeAddress"
            },
            "type": "array"
          }
        },
        "required": [
          "success",
          "heading",
          "insertionPoint"
        ],
        "type": "object"
      },
      {
        "additionalProperties": false,
        "properties": {
          "failure": {
            "additionalProperties": false,
            "properties": {
              "code": {
                "enum": [
                  "INVALID_TARGET"
                ]
              },
              "details": {},
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "type": "object"
          },
          "success": {
            "const": false
          }
        },
        "required": [
          "success",
          "failure"
        ],
        "type": "object"
      }
    ]
  }
  ```
</Accordion>

<Accordion title="Raw success schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "heading": {
        "$ref": "#/$defs/HeadingAddress"
      },
      "insertionPoint": {
        "$ref": "#/$defs/TextAddress"
      },
      "ref": {
        "description": "Ref handle for the created block. Pass directly to superdoc_format or superdoc_edit ref param without searching.",
        "type": "string"
      },
      "success": {
        "const": true
      },
      "trackedChangeRefs": {
        "items": {
          "$ref": "#/$defs/TrackedChangeAddress"
        },
        "type": "array"
      }
    },
    "required": [
      "success",
      "heading",
      "insertionPoint"
    ],
    "type": "object"
  }
  ```
</Accordion>

<Accordion title="Raw failure schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "failure": {
        "additionalProperties": false,
        "properties": {
          "code": {
            "enum": [
              "INVALID_TARGET"
            ]
          },
          "details": {},
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      },
      "success": {
        "const": false
      }
    },
    "required": [
      "success",
      "failure"
    ],
    "type": "object"
  }
  ```
</Accordion>
