# Lemmy 评论 API (lemmy.comments)

- Canonical page: [https://everyinfra.com/lemmy-api/comments](https://everyinfra.com/lemmy-api/comments?utm_medium=ai_doc&utm_campaign=page_md)
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "lemmy", "action": "comments", "params": {...}}
- Price: $0.001389 per call ($1.39 per 1,000 requests); failed calls and empty results are not charged
- Returns: list, default 10, max 200 per call
- Mode: sync; add "mode": "async" for slow tasks

Lemmy 评论按 `community` 先读社区里的帖子，再把每个帖子的评论展开返回，不能直接传单个帖子的链接。每行是一条评论：全文 `text`、作者、得分和发布时间，加上 `depth` 和 `parent_comment_id` 说明它在评论树里的位置，`post_title` 和 `post_url` 说明属于哪个帖子。它回答「这个社区的帖子里大家怎么说」，适合做情感分析。

默认返回 10 条，单次最多 200 条。`sort` 在这里选的是帖子的顺序，不传按 `most_comments`，评论多的帖子先读；`top_range` 只在 `sort` 为 `top` 时生效，也不是评论发布时间的过滤。`is_deleted` 标出已删除的评论，统计前可以先按它过滤。

## Health

- Live health (24h percent, hourly and daily trends): https://api.everyinfra.com/api/v1/social/availability?platform=lemmy&action=comments

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| community | not declared | yes | not declared | Lemmy 社区名或 name@instance 形式的跨实例社区标识。community 列社区帖子；comments 按社区读取帖子并展开评论，不是直接按单个帖子 URL 查询。 |
| instance | not declared | no | not declared | Lemmy 实例域名，例如 lemmy.world，默认 lemmy.world；可以传带协议的实例 URL，最终只保留主机名。它指定查询入口，不是社区名称。 |
| max_comments | integer | no | not declared | comments 每个帖子最多读取的评论数，默认 50，限制 1–200；不是整个请求的帖子数或评论总数，超范围会截取到边界。 |
| sort | enum: active / hot / most_comments / new / new_comments / top | no | not declared | 帖子排序：hot 热门、active 活跃、new 新帖、top 高分、most_comments 评论最多、new_comments 新评论活动。search/community 默认 hot，feed 默认 active，comments 默认 most_comments。 |
| top_range | enum: all / day / hour / month / ninemonths / sixhour / sixmonths / threemonths / twelvehour / week / year | no | not declared | 只在 sort=top 时生效的积分时间窗：hour 1 小时、sixhour 6 小时、twelvehour 12 小时、day 1 天、week 1 周（默认）、month 1 月、threemonths 3 月、sixmonths 6 月、ninemonths 9 月、year 1 年、all 全部。不是评论发布时间过滤。 |
| limit | integer (1–200) | no | 10 | 这次调用最多返回的条数，整数，1–200；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| text | 正文内容，已去除 HTML 标签，全文返回、不截断（个别平台的列表结果本身只有摘要，以该平台的字段说明为准）。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_url | 作者在原平台的主页链接。 |
| score | 净得分（顶减踩）。 |
| upvote_count | 顶数。 |
| downvote_count | 踩数。 |
| depth | 评论层级深度。 |
| parent_comment_id | 父评论 ID。 |
| is_deleted | 是否已删除。 |
| post_url | 帖子链接。 |
| post_title | 帖子标题。 |
| community | 社区名。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |

## Example

```bash
curl -X POST 'https://api.everyinfra.com/api/v1/social' \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "platform": "lemmy",
  "action": "comments",
  "params": {
    "community": "technology@lemmy.world"
  }
}'
```

```python
import os
import requests

response = requests.post(
    "https://api.everyinfra.com/api/v1/social",
    headers={"Authorization": f"Bearer {os.environ['EVERYINFRA_API_KEY']}"},
    json={
        "platform": "lemmy",
        "action": "comments",
        "params": {
            "community": "technology@lemmy.world",
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

Real response to the example request above, captured 2026-09-26T08:56:04Z. `results` and `count` are real with personal information (names, handles, avatars, profile links, contact details) removed; the list keeps the first 2 of 500. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "lemmy",
  "action": "comments",
  "results": [
    {
      "id": 1362670,
      "text": "The best time to switch to Firefox was 5 years ago. The second best is today.",
      "author_username": "•••",
      "author_url": "https://feddit.de/•••",
      "score": 386,
      "upvote_count": 390,
      "downvote_count": 4,
      "depth": 1,
      "is_deleted": false,
      "post_url": "https://lemmy.world/post/1611939",
      "post_title": "If you value privacy, ditch Chrome and switch to Firefox now",
      "community": "technology",
      "posted_at": "2023-07-17T03:48:33.161642+00:00",
      "platform": "lemmy"
    },
    {
      "id": 1363333,
      "text": "Most people aren’t concerned about privacy outside of places like here and Reddit. ",
      "author_username": "•••",
      "author_url": "https://lemmy.world/•••",
      "score": 211,
      "upvote_count": 223,
      "downvote_count": 12,
      "depth": 1,
      "is_deleted": false,
      "post_url": "https://lemmy.world/post/1611939",
      "post_title": "If you value privacy, ditch Chrome and switch to Firefox now",
      "community": "technology",
      "posted_at": "2023-07-17T04:18:40.724748+00:00",
      "platform": "lemmy"
    }
  ],
  "count": 500,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 怎么把评论还原成评论树？

把每行的 `parent_comment_id` 对到父评论的 `id`，`depth` 是层级深度，按它缩进就能还原成树。

### `max_comments` 和 `limit` 有什么区别？

`max_comments` 管每个帖子最多读多少条评论，默认 50，范围 1–200，超出会截到边界；它不是整个请求的帖子数，也不是评论总数。`limit` 管整次返回的条数，默认 10，上限 200。

### 评论和社区资料返回的东西有什么不同？

社区资料返回帖子本身，带正文、外部链接、缩略图、是否置顶和是否锁定这些字段；评论返回帖子下的评论，只保留 `post_title` 和 `post_url` 来指回帖子。两页都用 `community` 定位社区。

## Also

- Capability catalog (no key): https://api.everyinfra.com/api/v1/social/catalog?platform=lemmy
- OpenAPI: https://everyinfra.com/openapi.json · Agents guide: https://everyinfra.com/agents.md
