LangChain Reddit Search & Nested Comment Tree Tool (Python + MCP)
Drop-in langchain-core @tool functions for /v1/reddit/search and /v1/reddit/post/comments — or connect all 9 endpoints in 10 lines via Streamable HTTP MCP.
01 · PAY-AS-YOU-GO
$0.10 / 1K items · Never expires
0 Credits charged on empty keyword polls or 4xx/5xx upstream errors.
02 · ZERO OAUTH / ZERO COOKIES
No Reddit account or proxies needed
Skip 6-week commercial OAuth reviews, refresh tokens, and AWS/GCP 403 blocks.
03 · 10×–24× LOWER UNIT COST
Beats Official $0.24/1K calls & $1.50 actors
Up to 100 posts or 200 nested comments per call ($0.04–$0.06/1K with bonus).
04 · INSTANT FREE SANDBOX
2,500 Free Credits ($0.25) on sign-up
No credit card required · 60 RPM (5 RPS) unlocked · Indie PAYG from $7.50 Crypto.
Option A · Runnable langchain-core @tool Functions (Search + 200-Comment Tree)
Calls GET /v1/reddit/search and GET /v1/reddit/post/comments directly with depth-indented Markdown output optimized for LLM context windows.
import os
import requests
from langchain_core.tools import tool
FORUMDATA_API_KEY = os.environ["FORUMDATA_API_KEY"] # rd_live_... (2,500 free credits at forumdataapi.com/signup)
BASE_URL = "https://api.forumdataapi.com"
HEADERS = {"x-api-key": FORUMDATA_API_KEY, "accept": "application/json"}
@tool
def reddit_keyword_search(
query: str,
subreddit: str = "",
sort: str = "new",
limit: int = 20,
) -> str:
"""Search real-time public Reddit threads by boolean query (e.g. 'supabase OR clerk') or subreddit.
Costs 1 Credit/post ($0.10/1K posts, min 2 Credits) and 0 Credits when 0 posts match."""
params: dict[str, str | int] = {
"query": query,
"sort": sort,
"limit": max(1, min(limit, 100)),
}
if subreddit.strip():
params["subreddit"] = subreddit.strip().removeprefix("r/")
resp = requests.get(f"{BASE_URL}/v1/reddit/search", params=params, headers=HEADERS, timeout=15)
resp.raise_for_status()
items = resp.json().get("data", {}).get("items", [])
if not items:
return f"No Reddit posts matched query={query!r} (0 Credits charged)."
lines = [
f"[post_id={p['id']}] r/{p.get('subreddit')} | +{p.get('score', 0)} | {p.get('num_comments', 0)} comments | {p.get('title')}\n"
f" URL: https://www.reddit.com{p.get('permalink', '')}"
for p in items
]
return "\n".join(lines)
@tool
def reddit_post_comment_tree(
post_id: str,
sort: str = "top",
limit: int = 100,
) -> str:
"""Fetch up to 200 flattened nested comments (with integer depth and parent_id) for any Reddit post_id or URL.
Costs 1 Credit/comment ($0.10/1K comments, min 2 Credits)."""
resp = requests.get(
f"{BASE_URL}/v1/reddit/post/comments",
params={"post_id": post_id, "sort": sort, "limit": max(1, min(limit, 200))},
headers=HEADERS,
timeout=15,
)
resp.raise_for_status()
items = resp.json().get("data", {}).get("items", [])
if not items:
return f"No comments found for post_id={post_id!r}."
rendered = []
for c in items:
indent = " " * min(6, int(c.get("depth") or 0))
op_badge = " (OP)" if c.get("is_submitter") else ""
body = str(c.get("body") or "").strip().replace("\n", " ")
rendered.append(f"{indent}- [+{c.get('score', 0)}] u/{c.get('author', 'deleted')}{op_badge}: {body}")
return "\n".join(rendered)
# Bind directly to any LangChain / LangGraph chat model:
# from langchain_anthropic import ChatAnthropic
# llm = ChatAnthropic(model="claude-sonnet-4-5").bind_tools([reddit_keyword_search, reddit_post_comment_tree])
Option B · Zero-Boilerplate MultiServerMCPClient (Streamable HTTP MCP)
Auto-discover all 9 read-only ForumData API tools in LangGraph via https://api.forumdataapi.com/mcp.
import asyncio
import os
from langchain_mcp_adapters.client import MultiServerMCPClient
async def load_forumdata_mcp_tools():
client = MultiServerMCPClient(
{
"forumdataapi": {
"transport": "streamable_http",
"url": "https://api.forumdataapi.com/mcp",
"headers": {"x-api-key": os.environ["FORUMDATA_API_KEY"]},
}
}
)
# Discovers all 9 read-only Reddit tools automatically over Streamable HTTP MCP
tools = await client.get_tools()
return tools
if __name__ == "__main__":
print([t.name for t in asyncio.run(load_forumdata_mcp_tools())])
Agent Tool Signatures & Unit Economics
| Tool Function | Gateway Endpoint | LLM Context Output | Credit Rate |
|---|---|---|---|
| reddit_keyword_search | GET /v1/reddit/search | Compact post_id, subreddit, score, comments & URL list | 1 Credit/post ($0.10/1K; $0 if empty) |
| reddit_post_comment_tree | GET /v1/reddit/post/comments | Up to 200 replies indented by depth (0..6) with OP & score tags | 1 Credit/comment ($0.10/1K, min 2 Credits) |
| MultiServerMCPClient | POST /mcp | All 9 tools (feeds, search, comments, entities — 2 Credits / $0.20 per 1K lookups) | $0.0398/1K items on Business (+65% bonus) |
LangChain Reddit Tool FAQ
Why shouldn't I use langchain_community's legacy RedditSearchRun (PRAW) wrapper in production?
Legacy PRAW-based LangChain tools require Reddit OAuth client credentials, hit 100 QPM rate caps across multi-agent runs, and fail with 403 blocks on cloud worker IPs. ForumData API's @tool functions use stateless HTTPS requests with a single x-api-key header and return pre-flattened 200-comment trees in one call.
Should I use the Python @tool functions or MultiServerMCPClient?
Use the Python @tool functions when you want tight token formatting or custom post-filtering inside Python. Use MultiServerMCPClient pointing to https://api.forumdataapi.com/mcp when you want instant access to all 9 read-only ForumData API tools without maintaining tool schemas locally.
How are LangChain tool calls billed?
reddit_keyword_search (/v1/reddit/search) and reddit_post_comment_tree (/v1/reddit/post/comments) cost 1 Credit per returned post or comment ($0.10/1K base PAYG, minimum 2 Credits per non-empty call; $0.0398/1K on Business with +65% bonus). Empty search queries deduct 0 Credits ($0.00), and single post/subreddit/user lookups cost 2 Credits ($0.20/1K).