Table of contents
What it is
Section titled “What it is”One call that takes a Markdown document and returns a table of contents as a nested Markdown list, plus every heading with its depth, text, anchor slug and line.
When to use it
Section titled “When to use it”- Your agent’s cue: a README or a long document needs a table of contents at the top, or the agent needs to link to a section by its anchor.
- You’ll reach for it when the headings keep changing and the hand-maintained list at the top is always one edit behind.
Real use cases
Section titled “Real use cases”Building without a terminal
Section titled “Building without a terminal”You are building a documentation portal in Lovable that imports READMEs from your repositories. The H1 of a README often carries badges, and the headings often carry inline code. A backend function sends each README to MarkdownScribe and shows the table of contents it gets back; its anchors are the same ones GitHub generates for that file, so a link copied from the portal works on GitHub too.
Working with a coding agent
Section titled “Working with a coding agent”Your coding agent has to add “see the section on calling nvm use automatically” to a document, as a link. It calls the operation, finds the heading in headings, and uses its slug, calling-nvm-use-automatically, the same slug GitHub gives that heading, backticks and all. No guessing at how punctuation turns into an anchor.
In a pipeline
Section titled “In a pipeline”A build step regenerates the table of contents of every long document before publishing. Documents written by many hands skip heading levels: an #### right under a ##. The list comes back nested under the real parent, so it renders as a list and not as text glued to the item above, and headings that contain code keep their backticks in the link text.
Why through the API
Section titled “Why through the API”- Anchors that match GitHub’s. Badges, inline code, punctuation and repeated headings produce the same slugs GitHub renders, so links built from the response work there.
- The structure, not just the list.
headingsgives depth, text, slug and line for each heading; the list intocis one way to use it, linking by slug is another. - Only real headings. Lines that look like headings inside code blocks are ignored; a text search would count them.
Copy-ready example
Section titled “Copy-ready example”curl https://api.markdownscribe.com/v1/md/toc \ -H "X-API-Key: $MDSCRIBE_API_KEY" \ -H "Content-Type: application/json" \ -d '{"markdown":"# Node Version Manager [](https://example.org/ci)\n\n## Installing\n\n### Install with `curl`\n\n## Usage\n\n#### Calling `nvm use` automatically\n\n## Troubleshooting\n"}'TypeScript SDK
Section titled “TypeScript SDK”import { MarkdownScribeClient } from "@markdownscribe/sdk";
const client = new MarkdownScribeClient({ apiKey: process.env.MDSCRIBE_API_KEY! });const result = await client.toc({ markdown: "# Node Version Manager [](https://example.org/ci)\n\n## Installing\n\n### Install with `curl`\n\n## Usage\n\n#### Calling `nvm use` automatically\n\n## Troubleshooting\n",});Save the markdown value above as README.md, then:
mdscribe toc README.mdResponse
Section titled “Response”Captured from the API on 2026-10-23.
{ "toc": "- [Node Version Manager](#node-version-manager-)\n - [Installing](#installing)\n - [Install with `curl`](#install-with-curl)\n - [Usage](#usage)\n - [Calling `nvm use` automatically](#calling-nvm-use-automatically)\n - [Troubleshooting](#troubleshooting)", "headings": [ { "depth": 1, "text": "Node Version Manager", "slug": "node-version-manager-", "line": 1 }, { "depth": 2, "text": "Installing", "slug": "installing", "line": 3 }, { "depth": 3, "text": "Install with curl", "slug": "install-with-curl", "line": 5 }, { "depth": 2, "text": "Usage", "slug": "usage", "line": 7 }, { "depth": 4, "text": "Calling nvm use automatically", "slug": "calling-nvm-use-automatically", "line": 9 }, { "depth": 2, "text": "Troubleshooting", "slug": "troubleshooting", "line": 11 } ], "meta": { "request_id": "01M5MY6MM48EFQX12MXMN7YD3G", "duration_ms": 24, "credits": 1 }}Credits, limits and errors
Section titled “Credits, limits and errors”1 credit per call. Each response says what it cost in the X-Credits-Charged header. Error responses are never charged.
- Options:
options.min_depthandoptions.max_depth(1 to 6) limit which heading levels appear. The defaults include every level. - Input:
markdown, up to 1,048,576 characters. ATX headings (#to######) and setext headings (underlined with===or---) are both read.
| Error | When |
|---|---|
validation |
markdown is missing, or a depth option is outside 1 to 6. |
payload_too_large |
The document is longer than 1,048,576 characters. |
unauthorized, insufficient_credits, rate_limited |
The key, the balance or the per-minute limit, as on every operation. |
Alternatives, and when MarkdownScribe is worth it
Section titled “Alternatives, and when MarkdownScribe is worth it”Checked on 2026-10-23 against the tool’s own documentation.
- markdown-toc. Add a
<!-- toc -->comment to the file and runnpx markdown-toc -i README.mdin a terminal to insert or refresh the list in place (github.com/jonschlinkert/markdown-toc). Use MarkdownScribe when your agent runs where there is no terminal (the Lovable or Base44 editor), when you want the headings with their slugs and lines as JSON, or when you want format, lint, table of contents and frontmatter from one key with one error format and one bill.