apyhub
Back
▣ OUTPUT KIT

Convert Markdown & HTML API

What it does

The Markdown to HTML API converts Markdown into HTML, and HTML back into Markdown, from one endpoint. Send your text and get back the converted content, the document title, a table of contents and size statistics.

To render Markdown, send it in markdown. The output supports GitHub-style tables, task lists, strikethrough and fenced code blocks. Set toc to true to get every heading with its level and anchor id. Set fullPage to true to get a complete HTML page with a doctype and readable CSS, and use title to set its page title. Raw HTML inside the Markdown is shown as text, and javascript: and data: links are replaced with #.

To go the other way, send a page or fragment in html. Set mainContent to true to keep only the main article and drop menus, sidebars and footers. If you are not sure which format you have, send it in text and set to to html, markdown or auto. Each input can be up to 1,000,000 characters.

Teams use the Markdown to HTML API to render user-written docs in a CMS, build newsletters from Markdown drafts, and convert HTML to Markdown for LLM and RAG pipelines. Each response also includes word, link and estimated token counts.

AI agents can call it through ApyHub MCP.

POST
Convert Markdown & HTML API
https://api.eu.apyhub.com/martin10291/convert-markdown-html/markdown-html-converter

QUICKSTART

GUIDE

Quickstart

Convert a short Markdown snippet to HTML.

curl -X POST "https://api.eu.apyhub.com/martin10291/convert-markdown-html/markdown-html-converter" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"markdown":"# Hello world\n\nThis is **bold**."}'

What you'll get back

Returns a JSON object with count and items. The single item holds the converted html, the title (the first heading), a toc with every heading and its anchor id, and stats about the text. If you send html instead, the item holds markdown and content in place of html.

{
  "count": 1,
  "items": [
    {
      "from": "markdown",
      "to": "html",
      "title": "Hello world",
      "html": "<h1 id=\"hello-world\">Hello world</h1>\n<p>This is <strong>bold</strong>.</p>",
      "toc": [
        { "id": "hello-world", "level": 1, "text": "Hello world" }
      ],
      "stats": {
        "codeBlocks": 0,
        "estTokensIn": 8,
        "estTokensOut": 19,
        "headings": 1,
        "images": 0,
        "inputChars": 32,
        "links": 0,
        "outputChars": 75,
        "tables": 0,
        "words": 6
      },
      "ms": 0.2
    }
  ]
}
TRY ITLIVE · 100 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
Send one of markdown, html or text.
Target format when you send 'text'.
Markdown to HTML: return the table of contents (level, text and anchor id of every heading).
HTML to convert to Markdown, a whole page or a fragment. Max 1,000,000 characters.

About this endpoint

What it does

Converts Markdown to HTML or HTML to Markdown, or detects the direction when you send plain text. Returns the converted content with the document title, a table of contents and size statistics.

Request Body

ParameterTypeDescription
markdownStringMarkdown text to convert to HTML. Supports GitHub-style tables, task lists, strikethrough and fenced code. Max 1,000,000 characters. Send one of markdown, html or text.
htmlStringHTML to convert to Markdown, either a whole page or a fragment. Max 1,000,000 characters. Send one of markdown, html or text.
textStringAny text, used instead of markdown or html. The direction is detected automatically unless you set to.
toENUMTarget format when you send text. Allowed values: html, markdown, auto. Default: auto.
tocBooleanMarkdown to HTML: return the table of contents with the level, text and anchor id of every heading.
fullPageBooleanMarkdown to HTML: return a complete HTML page with doctype, <title> and readable CSS instead of a fragment. Default: false.
titleStringMarkdown to HTML with fullPage: the page <title>. Default: the first H1.
mainContentBooleanHTML to Markdown: keep only the main article text and drop navigation, footers, sidebars and cookie banners. Default: false.

Response

Returns a JSON object with count and items. items always holds one conversion result.

ParameterTypeDescription
countIntegerNumber of results in items. Always 1.
itemsObject ArrayThe conversion result.
items[].fromENUMInput format. Allowed values: markdown, html.
items[].toENUMOutput format. Allowed values: html, markdown.
items[].htmlStringThe converted HTML. Only present for Markdown to HTML. With fullPage, a complete HTML page.
items[].markdownStringThe converted Markdown. Only present for HTML to Markdown.
items[].contentENUMOnly present for HTML to Markdown. Allowed values: main (only the main article was kept, mainContent), full (the whole page was converted).
items[].titleStringDocument title: the title you sent, otherwise the first H1 (Markdown) or the page <title> (HTML). Document if none is found.
items[].tocObject ArrayEvery heading in document order.
items[].toc[].idStringAnchor id of the heading, e.g. hello-world. Repeated headings get a suffix, e.g. a-1.
items[].toc[].levelIntegerHeading level. Range: 1 to 6.
items[].toc[].textStringHeading text.
items[].statsObjectSize and content statistics.
items[].stats.inputCharsIntegerCharacters in the input.
items[].stats.outputCharsIntegerCharacters in the output.
items[].stats.wordsIntegerNumber of words.
items[].stats.headingsIntegerNumber of headings.
items[].stats.linksIntegerNumber of links.
items[].stats.imagesIntegerNumber of images.
items[].stats.tablesIntegerNumber of tables.
items[].stats.codeBlocksIntegerNumber of code blocks. Only present for Markdown to HTML.
items[].stats.estTokensInIntegerEstimated LLM tokens in the input.
items[].stats.estTokensOutIntegerEstimated LLM tokens in the output.
items[].warningsString ArrayNotes about the conversion, e.g. raw HTML tags in the Markdown that were kept as visible text. Only present when there is something to report.
items[].msNumberConversion time in milliseconds.

Notes

  • Raw HTML inside Markdown is shown as text, and javascript: and data: links become #, so the HTML output is safe to embed.
  • Wrong types, values outside an enum, input over 1,000,000 characters, or a request with no markdown, html or text return 400 with code invalid_input, error and message. These requests are not billed.
  • Input and output are not stored.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.