/api/v1/split/sectionsSplit into sections API
Chunk by every heading or by level.
POST /api/v1/split/sections splits a markdown document into structured sections at every heading — or only at headings of a specific level — for LLM chunking, multi-page generation, and doc indexes.
Overview
Split a document into sections — either every heading (default) or only at a specific heading level. Each section comes back with its level, title, raw source, and starting line. Useful for LLM context chunking, multi-page site generation, or doc indexes.
Request
Authenticate with Authorization: Bearer YOUR_API_KEY and send a JSON body containing the parameters below. Pick your language:
curl -X POST 'https://trymarkdownviewer.com/api/v1/split/sections' \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown":"# A\nfirst\n\n## B\nsecond"}'Body parameters
| Field | Type | Required | Description |
|---|---|---|---|
| markdown | string | required | Markdown source. |
| byLevel | 1..6 | optional | When set, only split on headings of this level. |
Response
Success responses are wrapped in a data field. Errors use { error: { code, message } } with an appropriate HTTP status — see the error reference.
{
"data": {
"sections": [
{
"id": "s-0-a",
"level": 1,
"title": "A",
"raw": "# A\nfirst",
"line": 1
},
{
"id": "s-1-b",
"level": 2,
"title": "B",
"raw": "## B\nsecond",
"line": 4
}
],
"count": 2
}
}Use cases
LLM context windows
Chunk a long doc to fit within a model's context limit.
Multi-page site builds
Generate one page per top-level heading from a single source.
Related endpoints
Try in browser
Free tools that run the same logic locally — no API key, no upload.
Try it
Send a real request against your account in the API playground. Errors there link straight back to the error reference.