
# Search Reddit with Python, Node.js and cURL

Search public Reddit posts in one community: here, the year's top r/SaaS posts about usage-based pricing.

It is one call to [`POST /v1/reddit/search`](/reference/reddit/searchReddit), which costs 1 credit a request, plus 3 per Reddit post. Every snippet below ran against the live API on 27 October 2026, and the output is what the Python printed.

Set your key first. Create one at https://weirapp.io/dashboard/keys; every account gets 5,000 free credits a month.

```bash
export WEIR_API_KEY=weir_live_...
```

## Python

```python
import os

import requests

response = requests.post(
    "https://api.weirapp.io/v1/reddit/search",
    headers={"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"},
    json={"query": "usage-based pricing", "subreddit": "SaaS", "sort": "top", "time": "year", "limit": 5},
    timeout=60,
)
response.raise_for_status()
page = response.json()

for post in page["data"]:
    print(post["score"], post["numComments"], post["title"][:60])
print("credits charged:", response.headers["X-Credits-Charged"])
```

## Node.js

```js
// Node.js 18 or later, as an ES module (save as example.mjs).
const response = await fetch("https://api.weirapp.io/v1/reddit/search", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEIR_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    query: "usage-based pricing",
    subreddit: "SaaS",
    sort: "top",
    time: "year",
    limit: 5,
  }),
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const page = await response.json();

for (const post of page.data) console.log(post.score, post.numComments, post.title.slice(0, 60));
console.log("credits charged:", response.headers.get("x-credits-charged"));
```

## cURL

```bash
curl --request POST \
  --url 'https://api.weirapp.io/v1/reddit/search' \
  --header "Authorization: Bearer $WEIR_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"query":"usage-based pricing","subreddit":"SaaS","sort":"top","time":"year","limit":5}'
```

## Output

```text
78 66 We killed our $15/mo subscription for our SaaS. Here’s why.
34 20 Made a game, pricing it like a SaaS app - over $1k in revenu
29 12 Your job posting says "Competitive Salary" and you're wonder
28 15 I spent 2 years building someone else's SaaS. Here's what I
25 134 I need advice for the pricing
credits charged: 16
```

## The next page

A page ends with `meta.nextCursor`. Send it back as `cursor`, with every other parameter unchanged, until it is `null`. Each page is its own request and is charged as one.

```python
import os

import requests

headers = {"Authorization": f"Bearer {os.environ['WEIR_API_KEY']}"}
cursor = None
for number in range(1, 3):  # two pages; each page is its own charged request
    response = requests.post(
        "https://api.weirapp.io/v1/reddit/search",
        headers=headers,
        json={"query": "usage-based pricing", "subreddit": "SaaS", "sort": "top", "time": "year", "limit": 5, **({"cursor": cursor} if cursor else {})},
        timeout=60,
    )
    response.raise_for_status()
    page = response.json()
    print(f"page {number}: {len(page['data'])} posts, {response.headers['X-Credits-Charged']} credits")
    cursor = page["meta"]["nextCursor"]
    if not cursor:  # null means there is nothing more
        break
```

```text
page 1: 5 posts, 16 credits
page 2: 5 posts, 16 credits
```

## If a call fails

Failed calls are free. A `429` means too many requests a minute: wait the seconds in `Retry-After` and send it again. A `402` means the account is out of credits. A `503` means the source is busy and is safe to retry. Every code is on [Errors](/errors), and paging is on [Pagination](/pagination).
