# Web Page to Markdown | Character Limit for AI Agents (`wayturn/single-page-markdown-for-agents`) Actor

Convert one public HTML page into Markdown for an AI prompt or RAG pipeline. Set maxChars to cap the output in Unicode characters. Each result includes the page title, final URL, original length and a flag showing whether the Markdown was truncated. Works with static HTML.

- **URL**: https://apify.com/wayturn/single-page-markdown-for-agents.md
- **Developed by:** [Wayturn Hung](https://apify.com/wayturn) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 converted pages

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

## Web Page to Markdown | Character Limit for AI Agents

Give a research agent the main text of one public, static HTML page. Set a character budget before fetching it. The result includes Markdown, the title and the final URL for citation.

### Try a 200-character excerpt

In a test with the page below, the extracted Markdown was 9,349 Unicode characters long. This input returned exactly 200 characters with truncated set to true. The source page can change over time.

```json
{
  "url": "https://docs.apify.com/platform/proxy/google-serp-proxy",
  "maxChars": 200
}
```

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `url` | string | `https://example.com/` | Public http(s) URL. Private, loopback and link-local addresses are blocked, including via DNS and redirects. |
| `maxChars` | integer | `8000` | Maximum Unicode characters in `markdown` (100 to 200000). |

### Output

One dataset item:

| Field | Description |
|---|---|
| `url` | The URL you requested |
| `finalUrl` | The URL after redirects |
| `title` | Page title |
| `markdown` | Main content as Markdown (headings, links and lists preserved) |
| `truncated` | `true` if the content was cut to `maxChars` |
| `originalLength` | Length of the full Markdown in Unicode characters |

### How it works

1. Validates the URL and the `maxChars` range.
2. Resolves the hostname and blocks any private or reserved address. Each redirect hop is re-checked.
3. Fetches static HTML with a 20 second timeout, a 5 MB body cap and up to 5 redirects.
4. Removes scripts, styles, navigation, headers, footers, sidebars and forms.
5. Uses `<main>`, `<article>` or `[role=main]` when present, otherwise `<body>`.
6. Converts to Markdown and truncates by Unicode code point.

Failures stop the run with an explicit message, for example an HTTP error, a timeout, a non-HTML content type, or a blocked private address.

### Limits

- Static HTML only. Pages that need JavaScript to render their content return little or no text.
- No login, cookies or custom headers.

### Cost

A converted page costs $0.001. The start fee is $0.00005 per allocated GB (minimum one event). At 1 GB, converting one page costs $0.00105.

### Local development

```bash
npm install
apify run
```

Put a test input in `storage/key_value_stores/default/INPUT.json`, for example `{"url": "https://example.com/", "maxChars": 500}`.

# Actor input Schema

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

Public http(s) URL of the page to convert. Private, loopback and link-local addresses are blocked.

## `maxChars` (type: `integer`):

Maximum number of Unicode characters in the returned Markdown. Longer content is truncated and flagged.

## Actor input object example

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

# Actor output Schema

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

No description

# 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 = {
    "url": "https://example.com/"
};

// Run the Actor and wait for it to finish
const run = await client.actor("wayturn/single-page-markdown-for-agents").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 = { "url": "https://example.com/" }

# Run the Actor and wait for it to finish
run = client.actor("wayturn/single-page-markdown-for-agents").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 '{
  "url": "https://example.com/"
}' |
apify call wayturn/single-page-markdown-for-agents --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,wayturn/single-page-markdown-for-agents"
        }
    }
}
```

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/h2XNA2ooh4vJocGph/builds/jBGOtqS1B2eGzAzwm/openapi.json
