Skip to content

About

Reddit API examples in Python and curl: search posts by keyword, read a single post and its comments, list a subreddit's posts, and look up a user's profile. No Reddit account or cookie needed. Works as an MCP tool.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Reddit API

English · 中文

English

This repo reads public Reddit data with Python or curl. You can search posts by keyword, read a single post and its comments, list a subreddit's posts, and look up a user's profile. You need one EveryInfra API key. You do not need a Reddit account or cookie. The same API also works as an MCP tool in Claude and Cursor. Billing is per call: these 5 capabilities cost $0.56 to $0.79 per 1,000 calls. Failed calls and empty results are not charged. The EveryInfra Reddit API has 24 capabilities, all listed on the platform page: https://everyinfra.com/en/reddit-api?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

Quick start

git clone https://github.com/everyinfra/reddit-api.git
cd reddit-api
pip install -r requirements.txt
export EVERYINFRA_API_KEY=<your API key>
python main.py search "camping gear" --out posts.csv
python main.py post "<post url>" --out post.json
python main.py comments "<post url>" --out comments.csv
python main.py subreddit CampingGear --out subreddit_posts.csv
python main.py user <username>

curl

curl -X POST https://api.everyinfra.com/api/v1/social \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"platform":"reddit","action":"search","params":{"keyword":"camping gear"}}'

All capabilities use the same URL. Change action and params to call another one. Examples for post_detail, comments, subreddit_posts, and profile are in examples/curl.sh.

Claude and Cursor (MCP)

The remote MCP URL is https://api.everyinfra.com/mcp. Add the Authorization: Bearer header with your API key. EveryInfra runs the server, so you install no local program.

Claude Code:

claude mcp add --transport http everyinfra https://api.everyinfra.com/mcp --header "Authorization: Bearer <API Key>"

Cursor and other clients that read mcp.json (examples/mcp.json):

{
  "mcpServers": {
    "everyinfra": {
      "url": "https://api.everyinfra.com/mcp",
      "headers": {
        "Authorization": "Bearer <API Key>"
      }
    }
  }
}

Custom connectors in Claude on the web and desktop, and ChatGPT, accept only a URL. Enter https://api.everyinfra.com/mcp/all, sign in to EveryInfra when asked, and allow access. You do not need to enter a key. Full steps: https://everyinfra.com/en/mcp-server?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

Price

action Per 1,000 calls
search $0.79
post_detail $0.56
comments $0.79
subreddit_posts $0.56
profile $0.79

Fields

These are the fields that the 5 capabilities returned in our test. Each meaning is the first sentence of the field's entry in the API documentation. The link under each table has the full text.

search (keyword search)

Field Meaning
id The record's unique ID on the platform.
url Link to the record on the platform.
title Title. null when the platform has no titles (for example text-only posts).
text Body text with HTML removed, returned in full and never cut short (on a few platforms the list results themselves carry only an excerpt; the platform's field notes say so).
author_username Author's username (@handle), usually usable in URLs.
community Name of the subreddit it belongs to, without the r/ prefix.
like_count Likes. null means the platform or this capability does not disclose it; it is not 0.
comment_count Comments. null means not disclosed, not 0.
posted_at Publish time in ISO 8601, UTC (for example 2026-08-07T12:34:56+00:00).
platform Source platform identifier, the same as platform in the request (for example xiaohongshu, tiktok).

All parameters and fields: https://everyinfra.com/en/reddit-api/search?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

post_detail (post details)

Field Meaning
id The record's unique ID on the platform.
url Link to the record on the platform.
title Title. null when the platform has no titles (for example text-only posts).
text Body text with HTML removed, returned in full and never cut short (on a few platforms the list results themselves carry only an excerpt; the platform's field notes say so).
author_username Author's username (@handle), usually usable in URLs.
community Name of the subreddit it belongs to, without the r/ prefix.
like_count Likes. null means the platform or this capability does not disclose it; it is not 0.
comment_count Comments. null means not disclosed, not 0.
posted_at Publish time in ISO 8601, UTC (for example 2026-08-07T12:34:56+00:00).
flair The post's flair (category label), as written.
domain Domain of the post's link (for text posts, self. or reddit.com).
image_urls Array of image links in the platform's display order; absent when there are no images.
platform Source platform identifier, the same as platform in the request (for example xiaohongshu, tiktok).

All parameters and fields: https://everyinfra.com/en/reddit-api/post_detail?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

comments (comments)

Field Meaning
id The record's unique ID on the platform.
text Body text with HTML removed, returned in full and never cut short (on a few platforms the list results themselves carry only an excerpt; the platform's field notes say so).
author_username Author's username (@handle), usually usable in URLs.
like_count Likes. null means the platform or this capability does not disclose it; it is not 0.
url Link to the record on the platform.
posted_at Publish time in ISO 8601, UTC (for example 2026-08-07T12:34:56+00:00).
platform Source platform identifier, the same as platform in the request (for example xiaohongshu, tiktok).

All parameters and fields: https://everyinfra.com/en/reddit-api/comments?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

subreddit_posts (subreddit posts)

Field Meaning
id The record's unique ID on the platform.
url Link to the record on the platform.
title Title. null when the platform has no titles (for example text-only posts).
text Body text with HTML removed, returned in full and never cut short (on a few platforms the list results themselves carry only an excerpt; the platform's field notes say so).
author_username Author's username (@handle), usually usable in URLs.
community Name of the subreddit it belongs to, without the r/ prefix.
like_count Likes. null means the platform or this capability does not disclose it; it is not 0.
comment_count Comments. null means not disclosed, not 0.
posted_at Publish time in ISO 8601, UTC (for example 2026-08-07T12:34:56+00:00).
flair The post's flair (category label), as written.
domain Domain of the post's link (for text posts, self. or reddit.com).
platform Source platform identifier, the same as platform in the request (for example xiaohongshu, tiktok).
image_urls Array of image links in the platform's display order; absent when there are no images.
thumbnail_url Thumbnail link, lower resolution than image_url.

All parameters and fields: https://everyinfra.com/en/reddit-api/subreddit_posts?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

profile (profile or object details)

Field Meaning
user_id User's unique ID on the platform.
username Username (@handle).
display_name Display name; can differ from username.
url Link to the record on the platform.
avatar_url Avatar image link.
karma The user's total karma (profile); post_karma and comment_karma give the parts earned from posts and from comments.
post_karma Karma the user earned from posts (profile).
comment_karma Karma the user earned from comments (profile).
post_count Total posts. null means not disclosed, not 0.
comment_count Comments. null means not disclosed, not 0.
created_at Creation time, same format as posted_at.
is_nsfw Whether the community (search_suggest) or the user (profile) is marked NSFW.
content_hidden Whether the user has hidden their posts and comments (profile).
trophy_count How many older trophies the user has in the Trophy Case on their profile (profile).
achievement_count How many achievements the user has unlocked (profile).
platform Source platform identifier, the same as platform in the request (for example xiaohongshu, tiktok).

All parameters and fields: https://everyinfra.com/en/reddit-api/profile?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

FAQ

Do I need a Reddit account or cookie to call the API?

No. Send the Authorization: Bearer header with your API key. The request body holds platform, action, and the capability parameters. You do not scan a QR code, keep a login session, or open a browser.

How much does it cost? Are failed calls charged? Is there a free allowance?

Billing is per call, from $0.56 per 1,000 calls. Failed calls, empty results, parameter errors, and authentication failures are not charged. When urls holds several links, each link counts as one call. A new account gets a $1 trial allowance, valid for 24 hours. No credit card is needed. How to claim it: https://everyinfra.com/en/pricing?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

Can I connect the Reddit API to Claude or Cursor?

Yes. The remote MCP URL is https://api.everyinfra.com/mcp. Add the Authorization: Bearer header with your API key. You install no local program. Setup for Claude, Cursor, ChatGPT, and Claude Code: https://everyinfra.com/en/mcp-server?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api. An agent can then search Reddit content, read comments, and look up accounts by itself.

What legal points apply when I use Reddit data?

The EveryInfra Terms of Service require you to make sure your use of the data follows applicable law and the terms of the relevant platform. Do not use the data for anything illegal or anything that violates privacy or intellectual property rights. Do not use bulk scraping for harassment, fraud, or other abuse. When you use personal information such as nicknames and avatars, keep only the fields your business needs.

Which Reddit data can I get?

The EveryInfra Reddit API has 24 capabilities:

  • keyword search
  • subreddit posts
  • post details
  • comments
  • user content
  • comments by user
  • pain point research
  • trending posts
  • popular posts
  • news posts
  • games posts
  • subreddit highlights
  • search suggestions
  • trending searches
  • active communities
  • user achievements
  • explore
  • topic communities
  • subreddit info
  • subreddit rules
  • profile or object details
  • posts in bulk
  • comments by link
  • comment replies

Parameters and return fields for each capability are on the platform page: https://everyinfra.com/en/reddit-api?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

Tested

Before release, we ran the 5 commands in Quick start against the live API with this repo's code.

Command Time (Singapore, UTC+8) Rows Charged
python main.py search "camping gear" --out posts.csv 2026-11-25 12:12 7 $0.000792
python main.py post "<post url>" --out post.json 2026-11-25 12:13 1 $0.000556
python main.py comments "<post url>" --out comments.csv 2026-11-25 12:13 10 $0.000792
python main.py subreddit CampingGear --out subreddit_posts.csv 2026-11-25 12:14 10 $0.000556
python main.py user <username> 2026-11-25 12:14 1 $0.000792

中文

本仓库用 Python 或 curl 读 Reddit 公开数据:按关键词搜帖子,读单帖和评论,看社区(subreddit)帖子,查用户资料。只需一把 EveryInfra API Key,不用 Reddit 账号和 Cookie,也能作为 MCP 工具接进 Claude、Cursor。按调用次数计费,这 5 个能力每千次 $0.56 到 $0.79,失败和空结果不收费。Reddit 共 24 个能力:https://everyinfra.com/reddit-api?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

快速开始

git clone https://github.com/everyinfra/reddit-api.git
cd reddit-api
pip install -r requirements.txt
export EVERYINFRA_API_KEY=<你的 API Key>
python main.py search "camping gear" --out posts.csv
python main.py post "<帖子链接>" --out post.json
python main.py comments "<帖子链接>" --out comments.csv
python main.py subreddit CampingGear --out subreddit_posts.csv
python main.py user <username>

用 curl 调

curl -X POST https://api.everyinfra.com/api/v1/social \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"platform":"reddit","action":"search","params":{"keyword":"camping gear"}}'

所有能力都发到同一个地址,换 action 和 params 就行;post_detail、comments、subreddit_posts、profile 的写法见 examples/curl.sh。

接进 Claude、Cursor(MCP)

远程 MCP 地址是 https://api.everyinfra.com/mcp,请求头加 Authorization: Bearer 和 API Key;服务器由 EveryInfra 运行,不用装本地程序。

Claude Code:

claude mcp add --transport http everyinfra https://api.everyinfra.com/mcp --header "Authorization: Bearer <API Key>"

Cursor 等读 mcp.json 的客户端(examples/mcp.json):

{
  "mcpServers": {
    "everyinfra": {
      "url": "https://api.everyinfra.com/mcp",
      "headers": {
        "Authorization": "Bearer <API Key>"
      }
    }
  }
}

Claude 网页版和桌面版的自定义连接器、ChatGPT 只能填网址:填 https://api.everyinfra.com/mcp/all,连接时登录 EveryInfra 并允许,不用填 Key。完整步骤见 https://everyinfra.com/mcp-server?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

价格

能力 action 每千次
关键词搜索 search $0.79
内容详情 post_detail $0.56
评论 comments $0.79
社区帖子 subreddit_posts $0.56
主页或对象详情 profile $0.79

返回字段

下面是这 5 个能力实测返回的字段,含义取自接口文档每条说明的第一句,完整说明在每张表下面的链接里。

search(关键词搜索)

字段 含义
id 该记录在原平台上的唯一标识。
url 该记录在原平台上的可访问链接。
title 标题。
text 正文内容,已去除 HTML 标签,全文返回、不截断(个别平台的列表结果本身只有摘要,以该平台的字段说明为准)。
author_username 作者用户名(@handle),通常可用于拼 URL。
community 所属 subreddit 名称(不含 r/ 前缀)。
like_count 点赞数。
comment_count 评论数。
posted_at 发布时间,ISO 8601 格式、UTC 时区(如 2026-08-07T12:34:56+00:00)。
platform 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。

完整参数和字段:https://everyinfra.com/reddit-api/search?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

post_detail(内容详情)

字段 含义
id 该记录在原平台上的唯一标识。
url 该记录在原平台上的可访问链接。
title 标题。
text 正文内容,已去除 HTML 标签,全文返回、不截断(个别平台的列表结果本身只有摘要,以该平台的字段说明为准)。
author_username 作者用户名(@handle),通常可用于拼 URL。
community 所属 subreddit 名称(不含 r/ 前缀)。
like_count 点赞数。
comment_count 评论数。
posted_at 发布时间,ISO 8601 格式、UTC 时区(如 2026-08-07T12:34:56+00:00)。
flair 帖子的分类标签(flair)原文。
domain 帖子链接的域名(文字帖为 self.版块名 或 reddit.com)。
image_urls 帖子里的图片地址。
platform 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。

完整参数和字段:https://everyinfra.com/reddit-api/post_detail?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

comments(评论)

字段 含义
id 该记录在原平台上的唯一标识。
text 正文内容,已去除 HTML 标签,全文返回、不截断(个别平台的列表结果本身只有摘要,以该平台的字段说明为准)。
author_username 作者用户名(@handle),通常可用于拼 URL。
like_count 点赞数。
url 该记录在原平台上的可访问链接。
posted_at 发布时间,ISO 8601 格式、UTC 时区(如 2026-08-07T12:34:56+00:00)。
platform 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。

完整参数和字段:https://everyinfra.com/reddit-api/comments?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

subreddit_posts(社区帖子)

字段 含义
id 该记录在原平台上的唯一标识。
url 该记录在原平台上的可访问链接。
title 标题。
text 正文内容,已去除 HTML 标签,全文返回、不截断(个别平台的列表结果本身只有摘要,以该平台的字段说明为准)。
author_username 作者用户名(@handle),通常可用于拼 URL。
community 所属 subreddit 名称(不含 r/ 前缀)。
like_count 点赞数。
comment_count 评论数。
posted_at 发布时间,ISO 8601 格式、UTC 时区(如 2026-08-07T12:34:56+00:00)。
flair 帖子的分类标签(flair)原文。
domain 帖子链接的域名(文字帖为 self.版块名 或 reddit.com)。
platform 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。
image_urls 帖子里的图片地址。
thumbnail_url 缩略图链接,分辨率低于 image_url。

完整参数和字段:https://everyinfra.com/reddit-api/subreddit_posts?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

profile(主页或对象详情)

字段 含义
user_id 用户在原平台的唯一 ID。
username 用户名(@handle)。
display_name 显示名,可能与 username 不同。
url 该记录在原平台上的可访问链接。
avatar_url 头像图片链接。
karma 用户的 karma 总数。
post_karma 用户发帖得到的 karma。
comment_karma 用户评论得到的 karma。
post_count 发布内容总数。
comment_count 评论数。
created_at 创建时间,格式同 posted_at。
is_nsfw 是否标记为成人内容(NSFW)。
content_hidden 用户是否把自己的帖子和评论设成了隐藏;为 true 时 user_posts、user_comments、user_subreddits 返回空。
trophy_count 个人页上旧版奖杯的个数。
achievement_count 个人页 Achievements 里已解锁的成就个数。
platform 数据来源平台标识,与请求里的 platform 一致(如 xiaohongshu、tiktok)。

完整参数和字段:https://everyinfra.com/reddit-api/profile?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

常见问题

调用时要不要提供 Reddit 账号或 Cookie?

不用,请求头带 Authorization: Bearer 和 API Key 就能调,请求体写 platform、action 和能力参数。不用扫码、维护登录状态,也不用开浏览器。

怎么收费?失败了收不收钱?有免费额度吗?

按调用次数计费,每千次 $0.56 起。失败、空结果、参数错误和鉴权失败都不收费;urls 传多个链接时每个算一次。新账号有 $1 试用额度,24 小时内有效,不用信用卡,领取方式见定价页 https://everyinfra.com/pricing?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

能把 Reddit 接口接进 Claude、Cursor 吗?

能,远程 MCP 地址是 https://api.everyinfra.com/mcp,请求头加 Authorization: Bearer 和 API Key,不用装本地程序。Claude、Cursor、ChatGPT、Claude Code 配置见 https://everyinfra.com/mcp-server?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api。Agent 能自己搜 Reddit 内容、读评论、查账号。

用 Reddit 数据要注意哪些合规问题?

EveryInfra 服务条款要求你自行确保数据用法符合适用法律和相关平台条款,禁止用于违法、侵犯隐私或知识产权,或批量抓取用于骚扰、欺诈等恶意用途。用到昵称、头像等个人信息时,只留业务用得上的字段。

可以拿到 Reddit 的哪些数据?

Reddit 有 24 个能力:关键词搜索、社区帖子、内容详情、评论、用户内容、用户评论、痛点调研、全站热帖、热门帖子(按国家和排序)、新闻帖子、游戏版帖子、社区置顶帖、搜索联想词、热搜词、用户活跃的社区、用户成就、创作者发现、分类下的社区、社区资料、社区规则、主页或对象详情、批量查帖子、按链接查评论、评论回复。每个能力的参数和返回字段见平台页 https://everyinfra.com/reddit-api?utm_source=github&utm_medium=example_repo&utm_campaign=reddit-api

实测记录

发布前用本仓的代码对线上接口跑过一遍,命令就是「快速开始」里的 5 条。

命令 时间(新加坡时间) 返回条数 扣费
python main.py search "camping gear" --out posts.csv 2026-11-25 12:12 7 $0.000792
python main.py post "<帖子链接>" --out post.json 2026-11-25 12:13 1 $0.000556
python main.py comments "<帖子链接>" --out comments.csv 2026-11-25 12:13 10 $0.000792
python main.py subreddit CampingGear --out subreddit_posts.csv 2026-11-25 12:14 10 $0.000556
python main.py user <username> 2026-11-25 12:14 1 $0.000792

post_detail 返回的一条(正文截到 60 字,作者字段没放进来):

{
  "id": "1xut8a7",
  "title": "My ultra heavy & ultra cheap backpacking setup",
  "text": "Only just started getting back into backpacking and camping …",
  "like_count": 250,
  "comment_count": 96,
  "posted_at": "2026-11-13T00:15:48.090000+00:00"
}

License

MIT

About

Reddit API examples in Python and curl: search posts by keyword, read a single post and its comments, list a subreddit's posts, and look up a user's profile. No Reddit account or cookie needed. Works as an MCP tool.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages