> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bunny.build/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /markdown-to-html

> Convert Markdown to clean, sanitized HTML. Supports GFM, tables, code highlighting, and more.

## Endpoint

```
POST https://api.bunny.build/api/v1/markdown-to-html
```

## Authentication

| Header         | Required | Value                    |
| -------------- | -------- | ------------------------ |
| `X-API-Key`    | Yes      | Your API key (`bun_...`) |
| `Content-Type` | Yes      | `application/json`       |

## Overview

Convert Markdown source into sanitized HTML ready for rendering in browsers or email clients. Supports GitHub Flavored Markdown (GFM), tables, task lists, fenced code blocks with syntax highlighting, and strikethrough. Output is sanitized to prevent XSS.

## Use cases

* Render user-generated Markdown content safely in web apps
* Convert README or documentation files to HTML for display
* Process blog post drafts written in Markdown
* Generate HTML emails from Markdown templates

## Details

Parsing follows the CommonMark specification with GFM extensions. HTML in the input is sanitized. Code blocks are wrapped in `<pre><code>` tags with a language class for CSS-based highlighting.

## Request body

| Field      | Type   | Required | Description                     |
| ---------- | ------ | -------- | ------------------------------- |
| `markdown` | string | Yes      | Markdown source text to convert |

### Example

````json theme={null}
{
  "markdown": "# Hello\n\nThis is **bold** and _italic_ text.\n\n```js\nconsole.log('hi');\n```"
}
````

## Response

### 200 OK

| Field                  | Type    | Description                                                     |
| ---------------------- | ------- | --------------------------------------------------------------- |
| `html`                 | string  | Rendered, sanitized HTML                                        |
| `word_count`           | integer | Number of words in the input Markdown source                    |
| `reading_time_minutes` | integer | Estimated reading time in minutes (minimum 1, based on 200 wpm) |
| `chars`                | integer | Character count of the input Markdown source                    |

**Example**

```json theme={null}
{
  "html": "<h1>Hello</h1>\n<p>This is <strong>bold</strong> and <em>italic</em> text.</p>\n<pre><code class=\"language-js\">console.log('hi');\n</code></pre>",
  "word_count": 12,
  "reading_time_minutes": 1,
  "chars": 74
}
```

### 401 Unauthorized

```json theme={null}
{
  "detail": "Missing API key. Include X-API-Key header."
}
```

### 402 Payment Required

```json theme={null}
{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}
```

### 422 Unprocessable Entity

```json theme={null}
{
  "detail": "Missing required field: markdown"
}
```

### 429 Too Many Requests

```json theme={null}
{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}
```

## cURL example

```bash theme={null}
curl -X POST https://api.bunny.build/api/v1/markdown-to-html \
  -H "X-API-Key: bun_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"markdown": "# Hello\n\nThis is **bold** text."}'
```
