# HTML to Markdown for AI Agents (`gracious_kofta/html-to-markdown`) Actor

Convert HTML or public web pages into clean Markdown for AI agents, RAG pipelines, and automation workflows.

- **URL**: https://apify.com/gracious\_kofta/html-to-markdown.md
- **Developed by:** [Leonardo Freitas](https://apify.com/gracious_kofta) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## HTML to Markdown for AI Agents

Convert HTML or a publicly reachable web page into compact, predictable Markdown. This is an API-first building block for AI agents, RAG pipelines, content normalization, and automation workflows—not a human-facing application.

### What it does

- Converts supplied HTML without making a network request.
- Fetches one public HTTP(S) URL and converts its returned HTML to Markdown.
- Preserves common headings, links, emphasis, lists, line breaks, and fenced code blocks.
- Removes scripts, styles, comments, and remaining HTML tags.

### Input

Provide **exactly one** of `html` or `url`.

| Field | Type | Description |
| --- | --- | --- |
| `html` | string | HTML to convert. Maximum 1,000,000 characters. |
| `url` | string | Public HTTP(S) URL to fetch and convert. Maximum 2,048 characters. |

#### Convert supplied HTML

```json
{
  "html": "<h1>Release notes</h1><p>Use <strong>Markdown</strong> downstream.</p><ul><li>Fast</li><li>Portable</li></ul>"
}
```

#### Convert a public URL

```json
{
  "url": "https://example.com/"
}
```

### Output contract

Each processed run writes one standardized execution envelope to the default Dataset. If a caller's Apify maximum-charge limit cannot cover a paid result, the Actor stops before processing and writes no Dataset item.

```json
{
  "tool": "html-to-markdown",
  "version": "0.1.0",
  "startedAt": "2026-01-01T00:00:00.000Z",
  "finishedAt": "2026-01-01T00:00:00.000Z",
  "durationMs": 12,
  "success": true,
  "data": {
    "markdown": "# Release notes\n\nUse **Markdown** downstream.\n\n- Fast\n- Portable",
    "sourceUrl": "https://example.com/"
  }
}
```

`sourceUrl` is returned only when `url` was used. Consumers should check `success` before reading `data`.

The Actor also declares an Apify Output schema and Dataset schema, so API clients and AI agents can discover the Dataset URL and the meaning of each result field.

### Call it from an agent or API

Use the canonical synchronous Apify endpoint when a caller needs the Dataset item as the response. Replace `<actor-id-or-name>` with the Actor identifier shown in Apify and keep the token in an authorization header.

```bash
curl --request POST \
  "https://api.apify.com/v2/actors/<actor-id-or-name>/run-sync-get-dataset-items" \
  --header "Authorization: Bearer $APIFY_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"html":"<h1>Hello agent</h1><p>Normalized content.</p>"}'
```

The response is an array containing the Dataset item. Never place an API token in a URL, log, prompt, or source repository.

### Safety and limits

For URL input, the Actor permits only public HTTP(S) destinations. It rejects localhost, private and reserved IP ranges, cloud metadata hosts, credentials in URLs, unsupported ports, and unsafe redirects. DNS resolution is checked before connecting.

The fetch path is bounded to a 1 MB response, three redirects, and a short execution timeout. It does not execute remote JavaScript, use browser rendering, authenticate to websites, or fetch protected pages. Use supplied `html` when the source is already available to your workflow.

Do not submit credentials, private documents, or personal data unless you have the right to process them in your Apify account.

### Errors

Failures are returned as `success: false` with `errorType` and a sanitized `errorMessage`. Common error types include `INVALID_INPUT`, `INVALID_URL`, `SSRF_BLOCKED`, `HTTP_ERROR`, `TIMEOUT`, `RESPONSE_TOO_LARGE`, and `TOO_MANY_REDIRECTS`.

### Product status

Version `0.1.0` is a beta utility. Pricing, public availability, and future MCP or agentic-payment access are configured in Apify; this Actor remains intentionally small and deterministic.

# Actor input Schema

## `html` (type: `string`):

HTML to convert to Markdown. Provide exactly one of html or url.

## `url` (type: `string`):

HTTP(S) public URL to fetch and convert. Provide exactly one of html or url.

## Actor input object example

```json
{
  "html": "<h1>Example document</h1><p>This safe sample is converted to Markdown.</p>"
}
```

# Actor output Schema

## `results` (type: `string`):

Default Dataset items use the documented execution envelope. Check success before reading data; a run rejected before processing for the caller's PPE cap has no item.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "html": "<h1>Example document</h1><p>This safe sample is converted to Markdown.</p>"
};

// Run the Actor and wait for it to finish
const run = await client.actor("gracious_kofta/html-to-markdown").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "html": "<h1>Example document</h1><p>This safe sample is converted to Markdown.</p>" }

# Run the Actor and wait for it to finish
run = client.actor("gracious_kofta/html-to-markdown").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "html": "<h1>Example document</h1><p>This safe sample is converted to Markdown.</p>"
}' |
apify call gracious_kofta/html-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gracious_kofta/html-to-markdown"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/J8D745QdpBP3bftXN/builds/vT7MkMTVfjIJzPQtF/openapi.json
