# Subreddit Posts Search Scraper (`khadinakbar/subreddit-posts-search-scraper`) Actor

Search public Reddit posts by keyword inside specified subreddits. Returns one validated post record per result; it does not extract comments, profiles, or subreddit metadata.

- **URL**: https://apify.com/khadinakbar/subreddit-posts-search-scraper.md
- **Developed by:** [Khadin Akbar](https://apify.com/khadinakbar) (community)
- **Categories:** Social media, Automation, AI
- **Stats:** 1 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 subreddit post founds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Subreddit Posts Search Scraper

Search public Reddit posts by keyword inside specified subreddits. This actor returns one structured post record per result for community research, product discovery, brand monitoring, and AI-agent workflows.

Use this when you already know the communities to inspect. It does not discover subreddits, extract full comment threads, scrape user profiles, or access private content.

### What you get

Each dataset record contains the public post title, body when available, author, subreddit, score, comment count, flair, permalink, external URL, flags, timestamp, query, requested subreddit, and provenance route.

### Input

```json
{
  "searchQuery": "artificial intelligence",
  "subreddits": ["technology", "MachineLearning"],
  "maxResults": 25,
  "sortBy": "relevance",
  "timeFilter": "month",
  "includeNsfw": false
}
```

| Field | Required | Meaning |
|---|---:|---|
| `searchQuery` | Yes | Keyword or phrase to find in public posts. |
| `subreddits` | Yes | One to 20 subreddit names, r/ names, or subreddit URLs. |
| `maxResults` | No | Total cap across all selected communities; default 25. |
| `sortBy` | No | `relevance`, `new`, `top`, `comments`, or `hot`. |
| `timeFilter` | No | `hour`, `day`, `week`, `month`, `year`, or `all`. |
| `includeNsfw` | No | Include NSFW-marked public posts; defaults to false. |

### Pricing

Pay per event plus Apify platform usage:

| Event | Price |
|---|---:|
| Post saved to dataset | $0.005 |

The actor logs its maximum event-cost cap before it fetches data. A `post-found` event is charged only after a complete validated record is persisted.

### Outputs and outcomes

The dataset contains post records. `OUTPUT` stores a compact outcome and `RUN_SUMMARY` contains provider attempts, validation counts, warnings, and billing telemetry.

- `COMPLETE`: all requested work completed.
- `PARTIAL`: useful posts were saved but a provider or storage step failed.
- `VALID_EMPTY`: the selected communities were searched successfully but no posts matched.
- `INVALID_INPUT`: fix the query or subreddit list.
- `UPSTREAM_FAILED` or `CONFIG_ERROR`: no useful result could be produced; check `RUN_SUMMARY`.

### Limitations and responsible use

This actor retrieves only public data made available by its configured providers. It cannot access private, deleted, quarantined, banned, or login-only Reddit content. Use the results only where your rights, approvals, and applicable law permit; do not use them to identify, harass, or de-anonymize people.

# Actor input Schema

## `searchQuery` (type: `string`):

Use this for the keyword or phrase to find in public Reddit posts, for example "artificial intelligence". It is searched independently inside every selected subreddit. This field is required and must contain 1 through 200 characters. This is not a Reddit URL, username, or subreddit name.

## `subreddits` (type: `array`):

Use this for the public communities to search, for example "technology" or "r/MachineLearning". Accepts a bare name, an r/ prefix, or a Reddit subreddit URL. Provide 1 through 20 distinct communities. This is not a global Reddit search, a post URL list, or a list of usernames.

## `maxResults` (type: `integer`):

Use this to cap the total unique posts saved across all subreddit searches, for example 25. Defaults to 25 and accepts 1 through 1000. The cap also prevents more than this number of post-found event charges. This is not a per-subreddit limit or a page count.

## `sortBy` (type: `string`):

Use this to choose provider ordering for matching posts, for example "relevance". Defaults to relevance; choose new for monitoring, top for high-scoring posts, or comments for active discussions. This does not search comments or change the search query.

## `timeFilter` (type: `string`):

Use this to constrain the provider search time window, for example "month". Defaults to month and accepts hour, day, week, month, year, or all. Use all for historical research and new for recent monitoring. This is not an exact post-date cutoff.

## `includeNsfw` (type: `boolean`):

Use this only when adult-marked public Reddit posts are appropriate for the stated research purpose. Pass true to keep posts whose provider metadata marks them NSFW. Defaults to false. This does not bypass private, quarantined, deleted, or login-only content restrictions.

## Actor input object example

```json
{
  "searchQuery": "artificial intelligence",
  "subreddits": [
    "technology",
    "MachineLearning"
  ],
  "maxResults": 25,
  "sortBy": "relevance",
  "timeFilter": "month",
  "includeNsfw": false
}
```

# Actor output Schema

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

One validated public Reddit post record per dataset item.

## `output` (type: `string`):

Compact terminal outcome and charged post count.

## `runSummary` (type: `string`):

Detailed provider routing, validation, and terminal diagnostics.

# 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 = {
    "searchQuery": "artificial intelligence",
    "subreddits": [
        "technology",
        "MachineLearning"
    ],
    "maxResults": 25,
    "sortBy": "relevance",
    "timeFilter": "month",
    "includeNsfw": false
};

// Run the Actor and wait for it to finish
const run = await client.actor("khadinakbar/subreddit-posts-search-scraper").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 = {
    "searchQuery": "artificial intelligence",
    "subreddits": [
        "technology",
        "MachineLearning",
    ],
    "maxResults": 25,
    "sortBy": "relevance",
    "timeFilter": "month",
    "includeNsfw": False,
}

# Run the Actor and wait for it to finish
run = client.actor("khadinakbar/subreddit-posts-search-scraper").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 '{
  "searchQuery": "artificial intelligence",
  "subreddits": [
    "technology",
    "MachineLearning"
  ],
  "maxResults": 25,
  "sortBy": "relevance",
  "timeFilter": "month",
  "includeNsfw": false
}' |
apify call khadinakbar/subreddit-posts-search-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,khadinakbar/subreddit-posts-search-scraper"
        }
    }
}

```

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/oNUcoVwPp1CWmznbW/builds/YoQZjFSidLZHCDWHG/openapi.json
