# How to search Reddit posts by keyword and collect their comments

> Search Reddit posts by keyword, sort and time period, then read the comment threads under the busiest posts into one CSV: parameters, reply structure, Python code and cost.

Canonical page: https://okdata.online/guides/reddit-search-posts-and-comments/

Search with Reddit post search, then read the threads you keep with Reddit post comments. The worked example is 8 calls and costs $0.02; a failed call is not charged.

Updated 2026-11-12

The job: Reddit is where people ask "which one should I buy" and get long, honest answers. You want those answers for a product or topic as data. Search for the posts, keep the threads with the most discussion, and read their comments with the reply structure intact. You end with one CSV: each row a comment with its post, community, text, score, author and, for replies, the comment it answers.

No Reddit account, app registration or OAuth token is involved. Each call is an HTTPS request with your key.

## Step by step

### Step 1: search posts

Call [Reddit post search](https://okdata.online/apis/reddit/posts/search/) with `query`. Two parameters decide what comes back:

- `sort`: `relevance` (the default), `latest` (newest first) or `popular` (highest score first).
- `published_within`: `day`, `week`, `month` or `year`. Leave it out to search all time.

One call returns about 25 posts for $0.004. Each post has `id` (in Reddit's `t3_` form, such as `t3_1p4kx9q`), `url`, `type` (`text`, `image` or `video`), `title`, the body in `text` (empty for link and image posts), `published_at`, `author.username`, the score in `metrics.likes` and the comment count in `metrics.comments`. Add `view=full` for `ext.subreddit` (the community, as `r/name`), `ext.upvote_ratio`, `ext.link` (the outside link of a link post), `ext.flair` and `ext.nsfw`.

```bash
curl -G "https://api.okdata.online/v1/reddit/posts/search" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=air fryer' \
  -d sort=popular -d published_within=month -d view=full
```

For the next page, send `page.next_cursor` back as `cursor`, unchanged; stop when `page.has_more` is `false`.

### Step 2: read the comments

Pass a post's `id` (with or without `t3_`) or its link as `url` to [Reddit post comments](https://okdata.online/apis/reddit/posts/comments/list/). `sort` takes `best` (the default, Reddit's own order), `latest` or `popular` (highest score first).

One call returns about 10 comments for $0.002, together with the first levels of replies under them. Each comment has `id` (`t1_` form), `post_id`, `parent_id`, `text`, `author.username`, the score in `likes`, the reply count in `replies` and `published_at`. `parent_id` is null for a top-level comment and holds the `t1_` ID of the comment being answered for a reply, so you can rebuild the thread as a tree.

```bash
curl -G "https://api.okdata.online/v1/reddit/posts/comments/list" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  -d id=t3_1p4kx9q -d sort=popular
```

Page with `page.next_cursor` as in step 1. Each further page brings more top-level comments with their first replies.

### Step 3: put it together in Python

```python
import csv
import os
import requests

API = "https://api.okdata.online"
HEADERS = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
SEARCH_PAGES = 2
THREADS = 6  # first comment page of each; one call per thread


def get(path, **params):
    body = requests.get(API + path, headers=HEADERS, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']} (charged: {body['charged']})")
    return body


posts, cursor = [], None
for _ in range(SEARCH_PAGES):
    body = get("/v1/reddit/posts/search", query="air fryer", sort="popular", published_within="month", view="full", **({"cursor": cursor} if cursor else {}))
    posts += body["data"]["items"]
    if not body["page"]["has_more"]:
        break
    cursor = body["page"]["next_cursor"]

busiest = sorted(posts, key=lambda p: p["metrics"]["comments"] or 0, reverse=True)[:THREADS]
with open("reddit_comments.csv", "w", newline="", encoding="utf-8") as f:
    out = csv.writer(f)
    out.writerow(["community", "post_id", "post_title", "comment_id", "parent_id", "author", "score", "replies", "published_at", "text"])
    for p in busiest:
        for c in get("/v1/reddit/posts/comments/list", id=p["id"], sort="popular")["data"]["items"]:
            out.writerow([p["ext"]["subreddit"], p["id"], p["title"], c["id"], c["parent_id"], c["author"]["username"], c["likes"], c["replies"], c["published_at"], c["text"]])
```

Rows with an empty `parent_id` are top-level comments; the rest are replies. To read deeper threads, page the comments of the posts that matter most.

## Good to know

- **Score, not likes.** Reddit shows a score (upvotes minus downvotes), and that is what `metrics.likes` and a comment's `likes` hold. Scores near zero can mean a disputed comment, not an ignored one.
- **What is null.** Reddit shows no view counts, so `metrics.views` is null. Commenters' avatars, follower counts and locations are not returned; `replies` can be null when the count is not known.
- **Deleted content.** A removed post returns `not_found`, which costs nothing. Deleted comments can still appear in a thread with their text replaced by Reddit's placeholder; filter them out before analysis.
- **Search reach.** The results are what Reddit's own search returns for the query and period, not every post that mentions the words. Try a few phrasings for a full picture.
- **The official route.** Reddit has its own Data API. Its [Data API Terms](https://redditinc.com/policies/data-api-terms) say that commercial use, or research beyond its rate limits, needs a separate agreement with Reddit. For a personal or approved research project within those limits, it is a good option.
- **Retries without paying twice.** Send an `Idempotency-Key` header with each call; the same request with the same key within 24 hours returns the stored answer and no new charge.

For what comments cost across platforms, see [social media comments cost per 1,000](https://okdata.online/answers/social-media-comments-cost-per-1000/). Turning threads like these into findings is covered in [word of mouth](https://okdata.online/solutions/word-of-mouth/).

## What the example costs

Two pages of the top-scoring Reddit posts about air fryers from the past month, then the first page of comments under the six most commented

| Endpoint | Calls | Price | Subtotal |
|---|---|---|---|
| [Reddit post search](https://okdata.online/apis/reddit/posts/search/) | 2 | $0.004 | $0.008 |
| [Reddit post comments](https://okdata.online/apis/reddit/posts/comments/list/) | 6 | $0.002 | $0.012 |
| Total | 8 |  | $0.02 |

Prices in force when this page was built. A failed call costs nothing.

## In your AI (MCP)

Connect the MCP server once, then say what you want. The agent finds these endpoints, reads their prices and calls them on your balance.

Say: Search Reddit for air fryer posts from the past month, top score first, two pages. Take the six posts with the most comments, read the first page of comments under each by top score, and give me one table: community, post title, comment, score, whether it is a reply. Then sum up what people recommend and what they regret buying.

```json
{
  "endpoint": "reddit.posts.search",
  "params": {
    "query": "saturn rings"
  },
  "idempotency_key": "<a new UUID>"
}
```

MCP: `https://api.okdata.online/mcp`

## Endpoints in this guide

- [Reddit post search](https://okdata.online/apis/reddit/posts/search/) `reddit.posts.search`: $0.004 per call · about 25 posts per page
- [Reddit post comments](https://okdata.online/apis/reddit/posts/comments/list/) `reddit.posts.comments.list`: $0.002 per call · about 10 comments per page

## More about Reddit

- [Reddit API](https://okdata.online/apis/reddit/)
- [Comments API](https://okdata.online/roles/posts-comments-list/)
- [Post search API](https://okdata.online/roles/posts-search/)
- [Reddit trending searches: today’s list](https://okdata.online/tools/hot-search/reddit/)

## Sources

- [Reddit Data API Terms](https://redditinc.com/policies/data-api-terms) (read 2026-11-12)
