# Reddit Subreddit Search (`reddit.subreddit_search`)

Search posts inside one subreddit by query, sort order and time window, cursor paged.

Docs: https://primaryapi.com/docs/api-reference/reddit/subreddit_search

- Endpoint: `POST https://api.primaryapi.com/v1/run/reddit.subreddit_search`
- Category: Social · Platform: `reddit` · Kind: search · Status: live
- Price: 2 credits per call; up to 44 credits if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=reddit.subreddit_search`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `subreddit` | string | yes |  | max 100 chars | Subreddit name without the r/ prefix (e.g. 'Fitness'). |
| `query` | string | no |  | max 500 chars | Optional search query to match posts (e.g. 'push ups'). |
| `sort` | enum | no |  | one of: relevance, hot, top, new, comments | Optional sort order (default relevance). |
| `timeframe` | enum | no |  | one of: all, year, month, week, day, hour | Optional time filter (default all). |
| `limit` | integer | no | 25 | 1–100 | Maximum number of results to return (1-100, default 25). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `posts` | object[] |  |
| `posts[].id` | string | Post id (base36, without the t3_ prefix) |
| `posts[].title` | string \| null |  |
| `posts[].selftext` | string \| null | Self-post body (markdown); null for link posts or when the source omits it |
| `posts[].author` | string \| null | Author username; null when deleted or not exposed by the source |
| `posts[].authorId` | string \| null | Author account id (without the t2_ prefix) |
| `posts[].subreddit` | string \| null |  |
| `posts[].score` | integer \| null |  |
| `posts[].upvoteRatio` | number \| null | Upvote ratio 0-1 when the source exposes it |
| `posts[].numComments` | integer \| null |  |
| `posts[].createdUtc` | integer \| null | Creation time, UTC epoch seconds |
| `posts[].permalink` | string \| null | Absolute reddit.com URL of the post |
| `posts[].url` | string \| null | Link target (external URL for link posts, the post itself for self posts) |
| `posts[].domain` | string \| null |  |
| `posts[].nsfw` | boolean \| null |  |
| `posts[].isLocked` | boolean \| null |  |
| `posts[].isArchived` | boolean \| null |  |
| `posts[].media` | object[] | Images / videos attached to the post (may be empty) |
| `posts[].media[].type` | enum | Media kind |
| `posts[].media[].url` | string | Direct media URL |
| `nextCursor` | string \| null | Pass as `cursor` to get the next page; null at the end |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/reddit.subreddit_search" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"subreddit":"webscraping","query":"proxy","sort":"relevance","timeframe":"year"}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "posts": [
        {
          "id": "string",
          "title": "string",
          "selftext": "string",
          "author": "string",
          "authorId": "string",
          "subreddit": "webscraping",
          "score": 0,
          "upvoteRatio": 0,
          "numComments": 0,
          "createdUtc": 0,
          "permalink": "string",
          "url": "https://example.com",
          "domain": "string",
          "nsfw": true,
          "isLocked": true,
          "isArchived": true,
          "media": [
            {
              "type": "image",
              "url": "https://example.com"
            }
          ]
        }
      ],
      "nextCursor": null
    }
  },
  "provider": "PrimaryAPI",
  "credits": 2,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 2 credits per call
- Price ceiling: up to 44 credits if a call is retried elsewhere. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=reddit.subreddit_search`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Cursors are source-specific.

## Legal

Served from third-party scrapers: Reddit’s Data API Terms (rev. 2026-07-20, §3.1-3.2) forbid reselling its own API, and Reddit sued scraping vendors in 2025 (Reddit v. SerpApi et al., SDNY 25-cv-08736). Usernames and user content are personal data under GDPR/CCPA even when pseudonymous: use for lawful purposes only, honour deletions, do not keep removed content, and do not train AI models on it without rightsholder permission (Data API Terms §2.4).

