ScavioScavio
Pricing
Tools
Sign InsGet Startedg
Blog
Reddit7 min readOct 27, 2026

How to Get Reddit Data Into an LLM: Search, Full Comment Trees and a Compact Prompt

Use Scavio's Reddit API: search posts, pull each thread's full comment tree with replies, flatten it to compact text and pass it to your LLM, 1 credit a call.

Scavio Team

Oct 27, 2026

Try the Reddit API free
scavio
LLM / Rag
Reddit

To get Reddit data into an LLM, use Scavio's Reddit API: POST /api/v1/reddit/search finds the threads, /api/v1/reddit/post/comments returns each thread's comments with nested replies in tree order and a depth field, and /post/comments/replies expands any branch Reddit collapses. Flatten that into indented text with the score on each line and pass it to the model. Every call costs 1 credit, about $0.002 on the Growth plan billed yearly, and needs no Reddit app or OAuth.

Reddit's own Data API is the other route, and it now requires an approved access request, a registered OAuth app and, for commercial use or AI training, explicit written approval from Reddit. If you qualify, PRAW is the standard Python client. The steps below use Scavio, and every response shown was captured on October 27, 2026.

Step 1: Search for the threads

Bash
curl -s https://api.scavio.dev/api/v1/reddit/search \
  -H "Authorization: Bearer $SCAVIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "best embedding model for RAG"}'

This returned 7 posts in 3.4 s, plus a next_cursor for the next 7. One row, as captured (body text trimmed):

JSON
{
  "post_id": "t3_1v2ebaq",
  "title": "Best embedding model for indexing ~17,000 scientific PDFs for a RAG system in 2026?",
  "text": "Hi everyone,\n\nI'm building a production RAG system focused on **scientific research papers** (desalination, chemistry, membranes, engineering). ...",
  "url": "https://www.reddit.com/r/Rag/comments/1v2ebaq/best_embedding_model_for_indexing_17000/",
  "subreddit": "Rag",
  "author": "Gintoki55",
  "score": 82,
  "upvote_ratio": 0.9880952380952381,
  "num_comments": 60,
  "created_at": "2026-07-21T10:16:56.369000+0000",
  "is_nsfw": false
}

Search returns the full post body, so the question is already in hand. To read a whole community instead of a query, page /api/v1/reddit/subreddit/posts with "sort": "NEW" or "TOP"; feed rows carry title, score and comment count but no body, so fetch the text with /api/v1/reddit/post.

Step 2: Pull the comment tree

Bash
curl -s https://api.scavio.dev/api/v1/reddit/post/comments \
  -H "Authorization: Bearer $SCAVIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"post_id": "t3_1v2ebaq"}'

The first page came back in 0.7 s. Comments arrive in tree order, so a reply follows its parent with a higher depth:

JSON
[
  {
    "comment_id": "t1_oyvtf9y",
    "text": "Before re indexing everything, I'd also benchmark a simple Elasticsearch BM25 baseline on your own scientific queries. ...",
    "author": "MashoodKiyani05",
    "score": 10,
    "created_at": "2026-07-21T14:50:56.547000+0000",
    "depth": 0,
    "reply_cursor": null
  },
  {
    "comment_id": "t1_oyx76zw",
    "text": "**Could you elaborate on that?**",
    "author": "Gintoki55",
    "score": 1,
    "created_at": "2026-07-21T18:22:22.702000+0000",
    "depth": 1,
    "reply_cursor": null
  },
  {
    "comment_id": "t1_oyxefvj",
    "text": "I think they mean just using Elasticsearch - BM25 is the standard in most cases for inverted indexing. ...",
    "author": "5d10_shades_of_grey",
    "score": 3,
    "created_at": "2026-07-21T18:53:26.977000+0000",
    "depth": 2,
    "reply_cursor": null
  }
]

Pass next_cursor back as cursor while has_more is true. This 60-comment thread took 6 pages. sort accepts TOP (the default), BEST, HOT, NEW and CONTROVERSIAL.

Step 3: Expand collapsed branches

When Reddit collapses a branch, the parent comment carries a reply_cursor instead of its replies:

Bash
curl -s https://api.scavio.dev/api/v1/reddit/post/comments/replies \
  -H "Authorization: Bearer $SCAVIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"post_id": "t3_1v2ebaq", "cursor": "commenttree:07d44405,::1:d1:t1_oyumg52"}'
JSON
{
  "replies": [
    {
      "comment_id": "t1_oyx7jet",
      "text": "**Thanks for** **advise** **!**",
      "author": "Gintoki55",
      "score": 2,
      "created_at": "2026-07-21T18:23:52.174000+0000",
      "depth": 1,
      "reply_cursor": null
    }
  ],
  "next_cursor": null,
  "has_more": false
}

Across the 14 threads that search returned, 12 of 45 calls were expansions like this one, and they returned 243 comments, 127 of them replies, nested as deep as depth 6.

Step 4: Flatten the thread into compact text

JSON is a poor prompt format: keys, ids, cursors and timestamps cost tokens and carry nothing the model needs. This function fetches a whole thread, puts expanded replies under their parent, and writes one indented line per comment with its score:

Python
import requests

API = "https://api.scavio.dev/api/v1/reddit"
HEADERS = {"Authorization": "Bearer sk_live_your_key"}

def call(path, **body):
    r = requests.post(f"{API}/{path}", headers=HEADERS, json=body, timeout=60)
    r.raise_for_status()
    return r.json()["data"]

def fetch_tree(post_id):
    comments, cursor = [], None
    while True:
        page = call("post/comments", post_id=post_id, **({"cursor": cursor} if cursor else {}))
        comments += page["comments"]
        cursor = page["next_cursor"]
        if not page["has_more"] or not cursor:
            break
    tree = []
    def add(c):
        tree.append(c)
        rc = c.get("reply_cursor")
        while rc:  # collapsed branch: expand it under this comment
            page = call("post/comments/replies", post_id=post_id, cursor=rc)
            for r in page["replies"]:
                add(r)
            rc = page["next_cursor"] if page["has_more"] else None
    for c in comments:
        add(c)
    return tree

def to_text(post, tree):
    lines = [f"# {post['title']} (r/{post['subreddit']}, score {post['score']}, {post['num_comments']} comments)"]
    if post.get("text"):
        lines.append(post["text"])
    for c in tree:
        text = (c.get("text") or "").strip()
        if text in ("", "[deleted]", "[removed]"):
            continue
        lines.append("  " * c["depth"] + f"- [{c['score']}] " + text.replace("\n", " "))
    return "\n".join(lines)

Measured with the o200k_base tokenizer, the 14 threads came to 44,593 tokens as JSON with every field and 23,289 as compact text: 48% fewer, dropping only 3 comments that had no text. The scores let the model weigh a reply with 10 upvotes above one with 1.

Step 5: Ask the model

Python
from openai import OpenAI

posts = call("search", query="best embedding model for RAG")["results"][:3]
context = "\n\n".join(to_text(p, fetch_tree(p["post_id"])) for p in posts)

client = OpenAI()
answer = client.responses.create(
    model="gpt-5.5",
    input="Using only these Reddit threads, which embedding models do practitioners "
          "recommend for RAG over technical documents, and why? Cite the subreddit.\n\n" + context,
)
print(answer.output_text)

Three threads with every comment is a few thousand tokens: the largest thread in our sample, 60 comments, was 3,656 tokens. For a RAG index, chunk per top-level comment with its replies and keep the post title on every chunk, so a retrieved reply still says what question it answers. For an agent, skip the glue code: Scavio's MCP server exposes the Reddit search and comment endpoints as tools that Claude, Cursor and other MCP clients call directly.

Why the comments are worth the extra calls

In those 14 threads the posts were 4,890 tokens and the comments 16,960, so comments held 78% of the text and replies below the top level 30%. The median thread was 5.6 times longer with its comments than the post alone. The chart and the vendor comparison are in the best Reddit data APIs for LLMs.

All 14 Reddit endpoints

EndpointWhat it returnsCredits
/api/v1/reddit/searchPosts by keyword with body text, score and comment count1
/api/v1/reddit/search/commentsComments by keyword with their post and subreddit1
/api/v1/reddit/search/subredditsSubreddits by keyword with subscriber counts1
/api/v1/reddit/search/suggestionsThe terms and subreddits Reddit's search box proposes1
/api/v1/reddit/postOne post by id or URL with full body1
/api/v1/reddit/post/commentsComments and nested replies in tree order with depth1
/api/v1/reddit/post/comments/repliesA collapsed branch under one comment1
/api/v1/reddit/subredditA subreddit's description and subscribers1
/api/v1/reddit/subreddit/postsA subreddit's feed by hot, new, top, rising or controversial1
/api/v1/reddit/userKarma, account age and profile1
/api/v1/reddit/user/postsAn account's posts1
/api/v1/reddit/user/commentsAn account's comments1
/api/v1/reddit/popularThe r/popular feed1
/api/v1/reddit/trendingTrending subreddits and searches1

Before you index Reddit content

Reddit's Data API Terms grant no right to train a machine learning or AI model on Reddit content without the rightsholders' permission, and its Data API Wiki asks API users to delete content once it is deleted on Reddit. Scavio returns public data only; you remain responsible for how you store and use it. A retrieval index that refreshes threads on a schedule, rather than a frozen copy, keeps deletions out of your answers.

Getting started

  1. Sign up at dashboard.scavio.dev/sign-up: 50 free credits, no card required.
  2. Copy your API key from the dashboard.
  3. Send a POST to /api/v1/reddit/search with your key in the Authorization header, then pass a post_id to /post/comments.

Try the Reddit API free in the playground first, or read any thread as text with the free Reddit thread reader.

Reference: Reddit API overview · search · post comments · comment replies · subreddit posts

Frequently asked questions

How do I get Reddit comments into ChatGPT or Claude?

Fetch the thread's comments as JSON, flatten them into indented text with the score on each line, and put that text in the prompt. Scavio's /api/v1/reddit/post/comments returns comments and nested replies in tree order with a depth field, so indenting by depth rebuilds the conversation. Agents in Claude, Cursor and other MCP clients can call the same endpoints as tools through Scavio's MCP server.

Do I need a Reddit API key to feed Reddit into an LLM?

Not with a third-party API. Reddit's own Data API requires a registered OAuth app, an approved access request and, for commercial use, explicit written approval. Scavio needs only a Scavio API key, and new accounts get 50 free credits with no card.

Should I index Reddit comments or only posts for RAG?

Comments. In 14 Reddit threads about embedding models we pulled on October 27, 2026, the comments held 78% of the text and replies below the top level held 30%, and the median thread was 5.6 times longer with its comments than the post alone. Indexing only posts keeps the questions and drops the answers.

Can I train a model on Reddit data?

Not without permission. Reddit's Data API Terms grant no right to use Reddit content to train a machine learning or AI model without the rightsholders' permission, and its Responsible Builder Policy requires express written approval for AI training. Reading threads at question time for retrieval is a different use, but check yours against Reddit's terms with your own counsel.

Reddit threads as JSON for your LLM

  • Post search and full comment trees
  • Replies in tree order with depth
  • 1 credit a call, no Reddit app or OAuth
Try the Reddit API free

50 free credits, no credit card

On this page

  1. Step 1: Search for the threads
  2. Step 2: Pull the comment tree
  3. Step 3: Expand collapsed branches
  4. Step 4: Flatten the thread into compact text

Related articles

View all
  • scavio
    Comparison / LLM
    Reddit
    5 Best Reddit Data APIs for LLMs in 2026: Scavio Returns the Comments That Hold 78% of a Thread
  • scavio
    LLM / Claude
    Reddit
    What's the Best Way to Scrape Reddit Posts and Comments for an LLM? Use an API, Then Trim the Thread
ScavioScavio

One scraper API for every social, search, e-commerce and real estate platform. Built for AI agents.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative
  • Serper Alternative
  • Tavily vs Scavio
  • SerpAPI vs Scavio
  • All alternatives
  • Compare Scavio vs alternatives

Search APIs

  • Google Search API
  • Amazon Product API
  • YouTube API
  • Reddit API
  • Walmart Product API
  • TikTok API
  • Instagram API

Tools

  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy