# AI-Ready Website to Clean Markdown, Token Counter & RAG Chunker (`duartelabs/ai-website-to-markdown-rag-chunker`) Actor

Convert any website or documentation page into noise-free Markdown, smart RAG chunks with context headers, extracted Q\&A pairs, LLM token savings audit, and multilingual AI summaries (EN, ES, PT, FR, DE, IT) in 1.5 seconds.

- **URL**: https://apify.com/duartelabs/ai-website-to-markdown-rag-chunker.md
- **Developed by:** [Cristian Duarte](https://apify.com/duartelabs) (community)
- **Categories:** AI, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

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

## 🤖 AI-Ready Website to Clean Markdown, Token Counter & RAG Chunker

**Stop feeding noisy HTML to ChatGPT, Claude, and your Vector Databases.**
Most web pages contain **85% to 96% HTML noise** (navigation menus, cookie banners, scripts, SVG icons, and tracking bloat) that burns your OpenAI/Anthropic API budget and degrades RAG retrieval accuracy.

**AI-Ready Website to Clean Markdown, Token Counter & RAG Chunker** strips out 100% of DOM noise in **1.5 seconds per page** using ultra-lightweight HTTP/2 requests—delivering clean hierarchical Markdown, **context-injected RAG chunks**, **auto-extracted Q\&A pairs**, and a **Multilingual Token Savings Audit** (`EN`, `ES`, `PT`, `FR`, `DE`, `IT`).

***

### 🔥 Why AI Engineers & n8n/Make Builders Choose This Actor

| Feature | Standard Markdown Scrapers | **AI-Ready Markdown & RAG Chunker (`duartelabs`)** |
| :--- | :--- | :--- |
| **Execution Speed & RAM** | Heavy headless browsers (30–60s, high compute cost) | **1.5 seconds via pure HTTP/2 (~$0.00 compute)** |
| **Smart RAG Chunking** | Dumps one massive text string that breaks embeddings | **Built-in Semantic Chunker (`smartChunks`) with Parent Context Headers** |
| **LLM Token & Cost Audit** | None | **Calculates Raw vs. Clean Tokens, % Saved & Est. GPT-4o Cost** |
| **Auto Q\&A Extraction** | None | **Automatically extracts Question/Answer pairs (`extractedFAQs`) for Chatbot training** |
| **Markdown Tables & Links** | Often broken or stripped | **Converts HTML tables to clean Markdown tables & resolves absolute URLs** |
| **Multilingual Audit Summary** | English only | **6 Languages (`EN`, `ES`, `PT`, `FR`, `DE`, `IT`)** |

***

### 📦 Sample Output JSON

```json
{
  "url": "https://apify.com/about",
  "domain": "apify.com",
  "title": "About Apify - Full-stack web scraping and data extraction platform",
  "detectedLanguage": "en",
  "rawHtmlTokens": 38420,
  "cleanMarkdownTokens": 1240,
  "tokenSavingsPct": 96.8,
  "estimatedGpt4oCostUsd": 0.0031,
  "wordCount": 935,
  "readingTimeMinutes": 4.7,
  "totalChunks": 3,
  "aiReadinessSummary": "✅ [AI & RAG READY] apify.com: Stripped 96.8% of noisy HTML bloat (38,420 → 1,240 LLM tokens). Structured into 3 context-aware vector chunks and 2 extracted Q&A pairs.",
  "smartChunks": [
    {
      "chunkIndex": 1,
      "sectionHeading": "What we do",
      "tokenEstimate": 420,
      "charLength": 1680,
      "ragText": "# About Apify > What we do\nSource: https://apify.com/about\n\nApify is a full-stack web scraping and browser automation platform..."
    }
  ],
  "extractedFAQs": [
    {
      "question": "Why did we launch Apify?",
      "answer": "We built Apify to make the web more programmable and help developers extract structured data effortlessly."
    }
  ]
}
```

***

### 🔗 Seamless Integration with n8n, Make, LangChain & Vector DBs

1. **Pinecone / Qdrant / Supabase pgvector:** Map `smartChunks[].ragText` directly into your OpenAI `text-embedding-3-small` node—no custom text-splitting code needed!
2. **Custom GPTs & Claude Projects:** Feed `cleanMarkdown` directly into your LLM prompt while saving **90%+ on input token costs**.
3. **AI Support Chatbots:** Use `extractedFAQs` to populate instant FAQ knowledge bases.

***

### 🤖 1-Click Integration with Claude Desktop & Cursor (MCP)

```json
{
  "mcpServers": {
    "apify": {
      "command": "npx",
      "args": ["-y", "@apify/actors-mcp-server", "--actors", "duartelabs/ai-website-to-markdown-rag-chunker"],
      "env": { "APIFY_TOKEN": "YOUR_APIFY_API_TOKEN" }
    }
  }
}
```

***

### 🛠️ Complete Your Automation Stack by `duartelabs`

- 🟢 **[B2B Lead, WhatsApp, Email & Ad-Pixel Intelligence Scraper](https://apify.com/duartelabs/b2b-lead-whatsapp-pixel-scraper):** Extract verified WhatsApp numbers, decision-maker emails, 9+ Ad Pixels, Schema.org data, and multilingual outreach hooks.
- 🟠 **[Shopify Competitor Price, Stock, Discount & Best-Sellers Spy](https://apify.com/duartelabs/shopify-competitor-price-stock-spy):** Extract complete competitor product catalogs, live discounts, stock availability, and AI pricing insights in seconds.
- 🔵 **[Technical SEO, Meta, Schema.org & Broken Links Auditor](https://apify.com/duartelabs/seo-meta-schema-broken-links-auditor):** Audit websites for 0–100 Technical SEO Score, missing Meta/H1 tags, Schema.org JSON-LD, image ALT gaps, response speed, and broken 404 links in 6 languages.

***

### ⚡ Ready-to-Import n8n Workflow Templates & Claude/Cursor MCP Config (1-Click Download)

Import these pre-built JSON workflows directly into **n8n** (`Workflows -> Import from URL / File`) or **Claude Desktop / Cursor IDE**:

- 🤖 **[Complete 4-Actor Claude Desktop & Cursor MCP Config (`claude_cursor_mcp_config.json`)](https://api.apify.com/v2/key-value-stores/1IuKKYulFhXhqM36b/records/claude_cursor_mcp_config.json)**
- 🟢 **[n8n B2B Lead, WhatsApp & Ad-Pixel Enricher Template (`n8n_b2b_lead_whatsapp_workflow.json`)](https://api.apify.com/v2/key-value-stores/1IuKKYulFhXhqM36b/records/n8n_b2b_lead_whatsapp_workflow.json)**
- 🟠 **[n8n Shopify Competitor Price & Stock Spy Template (`n8n_shopify_competitor_spy_workflow.json`)](https://api.apify.com/v2/key-value-stores/1IuKKYulFhXhqM36b/records/n8n_shopify_competitor_spy_workflow.json)**
- 🟣 **[n8n AI Website to Clean Markdown & RAG Chunker Template (`n8n_ai_markdown_rag_chunker_workflow.json`)](https://api.apify.com/v2/key-value-stores/1IuKKYulFhXhqM36b/records/n8n_ai_markdown_rag_chunker_workflow.json)**
- 🔵 **[n8n Technical SEO, Schema & Broken Links Auditor Template (`n8n_technical_seo_auditor_workflow.json`)](https://api.apify.com/v2/key-value-stores/1IuKKYulFhXhqM36b/records/n8n_technical_seo_auditor_workflow.json)**

# Actor input Schema

## `targetUrls` (type: `array`):

Enter the web pages, blog posts, help center articles, or documentation URLs you want to convert into clean LLM-ready Markdown and RAG chunks.

## `chunkSizeTokens` (type: `integer`):

Maximum number of LLM tokens per RAG chunk. Chunks are split intelligently at heading and paragraph boundaries without cutting sentences in half.

## `chunkOverlapTokens` (type: `integer`):

Number of overlapping tokens between consecutive chunks to preserve semantic continuity in vector databases (Pinecone, Qdrant, Supabase, Weaviate).

## `includeLinksAndTables` (type: `boolean`):

If enabled, HTML tables are converted into clean Markdown tables and relative links are converted to absolute URLs.

## `reportLanguage` (type: `string`):

Choose the language for the automated AI Readiness & Token Savings diagnostic summary.

## Actor input object example

```json
{
  "targetUrls": [
    {
      "url": "https://apify.com/about"
    },
    {
      "url": "https://stripe.com/docs/api"
    }
  ],
  "chunkSizeTokens": 500,
  "chunkOverlapTokens": 50,
  "includeLinksAndTables": true,
  "reportLanguage": "en"
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing all processed pages, clean Markdown, token savings, and RAG vector chunks.

# 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 = {
    "targetUrls": [
        {
            "url": "https://apify.com/about"
        },
        {
            "url": "https://stripe.com/docs/api"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("duartelabs/ai-website-to-markdown-rag-chunker").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 = { "targetUrls": [
        { "url": "https://apify.com/about" },
        { "url": "https://stripe.com/docs/api" },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("duartelabs/ai-website-to-markdown-rag-chunker").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 '{
  "targetUrls": [
    {
      "url": "https://apify.com/about"
    },
    {
      "url": "https://stripe.com/docs/api"
    }
  ]
}' |
apify call duartelabs/ai-website-to-markdown-rag-chunker --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,duartelabs/ai-website-to-markdown-rag-chunker"
        }
    }
}
```

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/bDtbnaBTT1YRmLwyX/builds/LLCveHhUFGRvg6FdW/openapi.json
