# Substack Scraper to Markdown for AI, RAG & LLMs (`mersetti/substack-to-markdown`) Actor

Export Substack newsletter posts as clean Markdown, text or HTML with metadata and ready-made RAG chunks. Works with substack.com and custom domains, skips paywalled content, monitors new posts.

- **URL**: https://apify.com/mersetti/substack-to-markdown.md
- **Developed by:** [Max Prozapas](https://apify.com/mersetti) (community)
- **Categories:** AI, News, Integrations
- **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

## Substack Scraper to Markdown — for AI, RAG & LLMs

Turn any Substack newsletter into **clean Markdown** (or text / HTML) with full metadata and optional
**ready-made RAG chunks**. Works with `*.substack.com` and custom domains (e.g. `lennysnewsletter.com`).

- ✅ Clean Markdown: subscribe buttons, share widgets and image wrappers removed — ready for LLMs
- ✅ RAG chunking on paragraph boundaries with section headings and overlap
- ✅ Metadata: title, subtitle, date, authors, tags, word count, reactions, comments, cover image, podcast URL
- ✅ Filters: date, keywords, max posts
- ✅ Monitoring: return only posts published since the last run — schedule it and get a newsletter feed
- ✅ Respects paywalls: paid posts return metadata and a short public teaser only

### Use cases

- Build a **RAG knowledge base / chatbot** from your favourite newsletters
- **AI agents** that need fresh expert content (product, tech, finance, politics…)
- Newsletter **research and analytics**: posting frequency, engagement, topics
- **Content monitoring**: get every new post from a list of newsletters into Slack, Notion, Google Sheets
- Backing up **your own** Substack as Markdown

### Input

| Field | Description |
|---|---|
| `publications` | Publication URLs, names (`astralcodexten`) or single post URLs (`…/p/slug`). |
| `maxPostsPerPublication` | Newest first (default 50). |
| `postedAfter` | `YYYY-MM-DD`. |
| `keywords` | Match in title, subtitle or tags. |
| `includeContent` | Full body of free posts (default on). |
| `contentFormat` | `markdown` (default), `text`, `html`. |
| `chunkSize` / `chunkOverlap` | RAG chunks in characters (0 = off). |
| `includePaidPosts` | Add paywalled posts as metadata + teaser. |
| `onlyNewPosts` / `monitorId` | Only posts not returned in previous runs. |

```json
{
  "publications": ["https://www.lennysnewsletter.com", "astralcodexten"],
  "maxPostsPerPublication": 20,
  "postedAfter": "2026-01-01",
  "chunkSize": 2000
}
```

### Output

```json
{
  "publication": "www.lennysnewsletter.com",
  "postId": 215694124,
  "title": "All of the Lenny & Friends Summit talks are now online!",
  "subtitle": "Plus, some reflections and takeaways from the day",
  "url": "https://www.lennysnewsletter.com/p/all-of-the-lenny-and-friends-summit",
  "postDate": "2026-09-29T13:15:57.512Z",
  "audience": "everyone",
  "isPaywalled": false,
  "authors": [{ "name": "Lenny Rachitsky", "handle": "lenny" }],
  "tags": [],
  "wordcount": 1276,
  "reactionCount": 289,
  "commentCount": 7,
  "contentFormat": "markdown",
  "content": "Two years ago, we held the first-ever Lenny and Friends Summit…",
  "chunks": [{ "index": 0, "heading": null, "text": "…" }]
}
```

A per-publication report is saved to the `SUMMARY` record of the run's key-value store.

### Pricing

Pay per post: a small fee per run plus a fee per post in the dataset. With monitoring on you pay only for new posts.

### Legal

The Actor reads only publicly available posts through Substack's public web endpoints and never extracts paywalled content.
Posts remain the copyright of their authors — make sure your use (e.g. internal research, personal knowledge base)
complies with applicable law and the authors' terms.

### FAQ

**Does it work with custom domains?** Yes — any Substack publication, e.g. `https://www.lennysnewsletter.com`.

**Can I scrape paid posts?** No. Paywalled posts return metadata and the short public teaser only (enable
`includePaidPosts`). The Actor never extracts paywalled content.

**How do I build a RAG knowledge base?** Set `chunkSize` to 1500–3000. Each post gets `chunks[]` with text and
section heading — load them straight into your vector database with `url` and `title` as metadata.

**Can I get only new posts?** Enable `onlyNewPosts` and schedule the Actor; each run returns posts published since
the previous run.

### Related tools

- [Career Sites Jobs Feed (11 ATS)](https://apify.com/mersetti/ats-jobs-feed)
- [Shopify Products & Price Monitor](https://apify.com/mersetti/shopify-products-monitor)
- Guide: [Substack API on GitHub](https://github.com/Mersetti/substack-api-guide)

# Actor input Schema

## `publications` (type: `array`):

Publication URLs (https://name.substack.com or a custom domain like https://www.lennysnewsletter.com), bare names (astralcodexten) or single post URLs (https://.../p/post-slug).

## `maxPostsPerPublication` (type: `integer`):

Newest posts first.

## `postedAfter` (type: `string`):

Only posts published after this date, format YYYY-MM-DD. Empty = any date.

## `keywords` (type: `array`):

Keep only posts whose title, subtitle or tags contain any of these words.

## `includeContent` (type: `boolean`):

Full post body for free posts. Turn off to get metadata only (faster).

## `contentFormat` (type: `string`):

Markdown is best for LLMs and RAG.

## `chunkSize` (type: `integer`):

Split content into chunks of up to N characters on paragraph boundaries, each with its section heading. 0 = no chunking. 1500–3000 works well for embeddings.

## `chunkOverlap` (type: `integer`):

Characters repeated from the previous chunk for context.

## `includePaidPosts` (type: `boolean`):

Paid posts are returned with metadata and a short public teaser only — never the paywalled body.

## `onlyNewPosts` (type: `boolean`):

Remember posts between runs and return only posts not returned before. Schedule the Actor to build a newsletter feed.

## `monitorId` (type: `string`):

Name of the saved state. Use different IDs for different feeds.

## Actor input object example

```json
{
  "publications": [
    "https://www.lennysnewsletter.com",
    "astralcodexten"
  ],
  "maxPostsPerPublication": 50,
  "includeContent": true,
  "contentFormat": "markdown",
  "chunkSize": 0,
  "chunkOverlap": 200,
  "includePaidPosts": false,
  "onlyNewPosts": false,
  "monitorId": "default"
}
```

# Actor output Schema

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

No description

## `summary` (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 = {
    "publications": [
        "https://www.lennysnewsletter.com",
        "astralcodexten"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("mersetti/substack-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 = { "publications": [
        "https://www.lennysnewsletter.com",
        "astralcodexten",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("mersetti/substack-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 '{
  "publications": [
    "https://www.lennysnewsletter.com",
    "astralcodexten"
  ]
}' |
apify call mersetti/substack-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,mersetti/substack-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/o6yei7pbe2oGvCp0c/builds/faLZaeBloFyRmZyfe/openapi.json
