# Lemmy 关键词搜索 API (lemmy.search)

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

Lemmy 关键词搜索按 `keyword` 在 `instance` 指定的实例上找帖子，默认 20 条，单次最多 200 条，返回的字段和信息流是同一套：标题、正文、外部链接、社区、得分和评论数。它回答「这个词在 Lemmy 上有没有人讨论、在哪个社区」，适合找某个自托管工具或开源项目的讨论串，或者确认一个话题有没有人聊。

这是对单个实例的检索，不是对全部联邦实例的完整搜索，所以搜不到不等于联邦里没有；想看别的实例，换 `instance` 再搜一次。信息流不需要关键词，单次最多 100 条；搜索的上限更高，每行的 `community` 和 `instance` 说明帖子在哪个社区、哪台服务器。

## Health

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

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| keyword | not declared | yes | not declared | Lemmy 帖子搜索词，在 instance 指定实例上执行；不是对全部联邦实例进行完整搜索的保证。 |
| instance | not declared | no | not declared | Lemmy 实例域名，例如 lemmy.world，默认 lemmy.world；可以传带协议的实例 URL，最终只保留主机名。它指定查询入口，不是社区名称。 |
| 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 | 20 | 这次调用最多返回的条数，整数，1–200；不传按默认值，实际返回可能少于这个数。超过上限会在扣费前返回 422。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| id | 该记录在原平台上的唯一标识。仅在同一平台内唯一，跨平台可能重复。 |
| title | 标题。平台无标题概念时（如纯文本帖）为 null。 |
| body | 正文。 |
| url | 该记录在原平台上的可访问链接。 |
| external_url | 帖子指向的外部链接。 |
| community | 社区名。 |
| community_url | 社区链接。 |
| instance | 所在实例(服务器)。Lemmy 是联邦宇宙社区，同名社区可存在于不同实例。 |
| author_username | 作者用户名（@handle），通常可用于拼 URL。 |
| author_url | 作者在原平台的主页链接。 |
| score | 净得分（顶减踩）。 |
| upvote_count | 顶数。 |
| downvote_count | 踩数。 |
| comment_count | 评论数。null 表示不公开，不等于 0。 |
| thumbnail_url | 缩略图链接，分辨率低于 image_url。 |
| embed_title | 外链的标题。 |
| is_nsfw | 是否为成人内容。 |
| is_locked | 是否锁定（禁止新评论）。 |
| is_featured | 是否为置顶精选。 |
| posted_at | 发布时间，ISO 8601 格式、UTC 时区（如 2026-08-07T12:34:56+00:00）。平台只给非标准字符串时原样透传，解析前建议做容错。null 表示平台未公开。 |
| updated_at | 编辑时间。 |
| 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": "search",
  "params": {
    "keyword": "self hosting"
  }
}'
```

```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": "search",
        "params": {
            "keyword": "self hosting",
        },
    },
    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 20. `id`, `billing` and `quota` differ on every call, so only their shape is shown.

```text
{
  "id": "req_…",
  "platform": "lemmy",
  "action": "search",
  "results": [
    {
      "id": "81293",
      "title": "'Every Taxpayer... Should Be Outraged': Anger Spreads Over 'Illegal' US-Funded Pro-Trump Ad",
      "body": "![](https://www.commondreams.org/media-library/a-screenshot-of-trump-s-love-me-ad-shows-him-standing-before-hundreds-of-troops-in-a-red-maga-hat.png?id=67857926&width=1200&height=400&coordinates=0%2C148%2C0%2C235)  \n  \n\nOutrage mounted Friday over a taxpayer-funded television adv…",
      "url": "https://news.abolish.capital/post/81293",
      "external_url": "https://www.commondreams.org/news/trump-taxpayer-funded-propaganda",
      "community": "pravda_news",
      "community_url": "https://news.abolish.capital/c/pravda_news",
      "instance": "lemmy.world",
      "author_username": "•••",
      "author_url": "https://news.abolish.capital/•••",
      "score": 23,
      "upvote_count": 23,
      "downvote_count": 0,
      "comment_count": 0,
      "thumbnail_url": "https://lemmy.world/pictrs/image/5f73fc38-2c80-456a-984b-ea8f0f1c03a5.png",
      "embed_title": "'Every Taxpayer... Should Be Outraged': Anger Spreads Over 'Illegal' US-Funded Pro-Trump Ad | Common Dreams",
      "is_nsfw": false,
      "is_locked": false,
      "is_featured": false,
      "posted_at": "2026-09-25T19:21:32.337190+00:00",
      "platform": "lemmy"
    },
    {
      "id": "45972083",
      "title": "Thoughts on Vikunja and the tension between self-hosting, ownership, and corporate branding",
      "body": "cross-posted from:  https://discuss.online/post/45939555\n\n> See [my post on their forum](https://community.vikunja.io/t/the-tension-between-self-hosting-ownership-and-corporate-branding/5110/1), which I hope is well received.",
      "url": "https://discuss.online/post/45972083",
      "external_url": "https://community.vikunja.io/t/the-tension-between-self-hosting-ownership-and-corporate-branding/5110/1",
      "community": "selfhosted",
      "community_url": "https://lemmy.world/c/selfhosted",
      "instance": "lemmy.world",
      "author_username": "•••",
      "author_url": "https://discuss.online/•••",
      "score": 9,
      "upvote_count": 12,
      "downvote_count": 3,
      "comment_count": 3,
      "thumbnail_url": "https://lemmy.world/pictrs/image/3c6d53ab-8c3b-4818-8d02-4f7b70943fed.png",
      "embed_title": "The Tension Between Self-Hosting, Ownership, and Corporate Branding",
      "is_nsfw": false,
      "is_locked": false,
      "is_featured": false,
      "posted_at": "2026-09-25T17:05:38.204140+00:00",
      "platform": "lemmy"
    }
  ],
  "count": 20,
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 搜索结果是整个 Lemmy 联邦的吗？

不是。搜索在 `instance` 指定的实例上执行，不保证覆盖全部联邦实例，搜不到不代表别处没有。`instance` 默认是 lemmy.world；想比较两个实例，各搜一次，两次的 `keyword` 保持一致。

### 能搜帖子里的评论吗？

这一页搜的是帖子，返回字段里的正文是帖子的 `body`。要读帖子的评论，用 Lemmy 评论那一页：那边要先给社区，再从社区的帖子里展开评论，没法只指定某一个帖子。

### 搜索结果怎么排序？

不传 `sort` 按 `hot` 排，改成 `new` 看最新，`top` 看高分；用 `top` 时再配 `top_range` 选积分的时间窗，不传按 `week`。`score` 是顶数减踩数的净得分，也可以拿它对结果二次排序。

## 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
