# Hacker News Search & Threads: Stories, Comments & Users (`data-done-right/hacker-news-search`) Actor

Search Hacker News stories, comments and users, fetch a story's full comment tree, or read the front page, from the official free Algolia HN API. Filter by query, tag, date range, points and author. Flat rows out, one per story or comment. Free on errors.

- **URL**: https://apify.com/data-done-right/hacker-news-search.md
- **Developed by:** [Data Done Right](https://apify.com/data-done-right) (community)
- **Categories:** Developer tools, News, Lead generation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.40 / 1,000 hacker news rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Hacker News Search & Threads: Stories, Comments & Users

This **Hacker News search** Actor reads the official, free Algolia HN Search API (hn.algolia.com/api) and returns flat rows: search stories and comments by keyword, tag, date range, points or author, export a story's **full comment tree**, look up user profiles, or read the front page. No API key, no browser, no proxy.

> **What it does not do.** It only reads what the public Algolia HN API offers. It does **not** log in, post, vote or read private data. It does **not** scrape news.ycombinator.com pages, and it is **not real-time monitoring** (Algolia's index can lag HN by a short while). A relevance search returns at most **1,000 hits** (an API limit); only newest-first searches can go further back. User rows carry karma and the "about" text only, no submission history (use search with `author` for that). Deleted and dead comments are not in the data. It is not affiliated with Y Combinator, Hacker News or Algolia.

**What you get**

- Four modes: `search`, `comments` (the whole thread of one or more stories), `user`, `frontPage`.
- One row per story, comment or user, with the same fields in every row (author, text, points, story title and link, parent id, depth, time, HN link).
- Comment text as plain text by default, links kept in full. Failed inputs go to a `FAILED` record and cost nothing.

### How to search Hacker News by keyword and date

1. Keep mode `search`, type a `query` (for example `apify`) and choose a `contentType` (stories, comments, Ask HN, Show HN, jobs, polls or everything).
2. Optionally set `dateFrom` and `dateTo` (UTC days), `minPoints`, `minComments` or `author`.
3. Set `sortBy` to `date` for newest first. Run it and read the dataset.

### How to export all comments of a Hacker News story

Use mode `comments` and put story ids or links in `storyIds` (`8863` or `https://news.ycombinator.com/item?id=8863`). Each story costs one API request, and the tree is flattened depth-first in reading order: `depth` 1 is a top-level comment, `parentId` points to the parent. `maxDepth` limits the nesting, `includeStoryRow` adds the story itself as a first row.

### How to look up Hacker News user profiles

Use mode `user` and list the names in `usernames`. You get `karma` and `about`. Unknown names produce no row and no charge; they are listed in `FAILED`. (The API answers HTTP 500 for unknown names, so a short outage looks the same.)

### How to get the Hacker News front page

Use mode `frontPage`. You get the stories the API currently tags as front page, in the order the API returns them.

### Input

| Field | Default | What it does |
|---|---|---|
| `mode` | `search` | `search`, `comments`, `user` or `frontPage`. Required. |
| `query` | `apify` (prefill) | Words to search for. |
| `contentType` | `stories` | `stories`, `comments`, `ask_hn`, `show_hn`, `jobs`, `polls`, `all`. |
| `sortBy` | `relevance` | `relevance` (max 1,000 hits) or `date` (newest first, can read further back). |
| `dateFrom`, `dateTo` | empty | UTC days, `YYYY-MM-DD`, both inclusive. |
| `author` | empty | Only items by this user. |
| `inStoryId` | empty | Search inside one story's thread. |
| `minPoints`, `minComments` | 0 | Filters (comments have no points). |
| `storyIds` | empty | Mode `comments`: story ids or links. |
| `maxDepth` | 0 | Comment tree depth limit, 0 = whole tree. |
| `includeStoryRow` | `true` | Add the story as a row before its comments. |
| `usernames` | empty | Mode `user`: user names. |
| `plainText` | `true` | Comments as plain text instead of HTML. |
| `maxItems` | 100 | Most rows delivered and charged (max 100,000). |
| `maxRequests` | 3000 | Safety cap on API requests per run. |

Input example:

```json
{"mode": "search", "query": "apify", "contentType": "stories", "maxItems": 20}
```

### Output

From a real local run of the input above (the first row):

```json
{
  "type": "story",
  "id": 4058874,
  "hnUrl": "https://news.ycombinator.com/item?id=4058874",
  "title": "HackerNews API: What if HN does not have API? Make API on the fly with APIfy",
  "author": "sathish316",
  "text": null,
  "points": 132,
  "numComments": 49,
  "storyId": 4058874,
  "storyTitle": "HackerNews API: What if HN does not have API? Make API on the fly with APIfy",
  "storyUrl": null,
  "parentId": null,
  "depth": null,
  "externalUrl": "http://apify.heroku.com/resources/4fca535156983f0001000002",
  "createdAt": "2012-06-02T19:16:33+00:00",
  "createdAtUnix": 1338664593,
  "karma": null,
  "about": null
}
```

A comment row from the tree of story 8863 (real run):

```json
{"type": "comment", "id": 8865, "hnUrl": "https://news.ycombinator.com/item?id=8865", "author": "dhouston",
 "text": "oh, and a mac port is coming :)", "storyId": 8863, "storyTitle": "My YC app: Dropbox - Throw away your USB drive",
 "parentId": 8863, "depth": 1, "createdAt": "2007-04-04T19:22:55+00:00", "createdAtUnix": 1175714575}
```

Fields that do not apply to a row type are `null` (shortened above). The `SUMMARY` record counts rows and API requests; `FAILED` lists inputs that could not be read; `NOTES` explains skipped items and limits.

### Rate limits and respect for the API

The API allows 10,000 requests per hour per IP. This Actor sends at most 2 requests per second, one at a time, stops at `maxRequests` (default 3,000), waits for `Retry-After` on HTTP 429 and gives up after a few attempts. It reads robots.txt of hn.algolia.com first (the site has none at the time of writing, which allows the API), talks only to `hn.algolia.com` over https, never follows redirects and uses no proxy. Many runs sharing one IP can still hit the hourly limit; if so the run ends with the rows already read and a clear message.

### Use with the Apify API, MCP, n8n and Make

Python:

```python
from apify_client import ApifyClient

client = ApifyClient("<APIFY_TOKEN>")
run = client.actor("data-done-right/hacker-news-search").call(run_input={
    "mode": "search", "query": "web scraping", "contentType": "comments", "sortBy": "date", "maxItems": 200})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(row["createdAt"], row["author"], (row["text"] or "")[:80])
```

JavaScript:

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: '<APIFY_TOKEN>' });
const run = await client.actor('data-done-right/hacker-news-search').call({ mode: 'comments', storyIds: ['8863'] });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

In n8n or Make use the Apify node with the Actor name and the same JSON. With Apify's MCP server (mcp.apify.com) an AI assistant can call it, for example "what did Hacker News say about my product this month?".

### Use cases

- Track mentions of your product, a competitor or a technology in stories and comments, newest first.
- Pull a whole discussion thread into a table or an LLM prompt for sentiment or objection mining.
- Read the comments of the monthly "Ask HN: Who is hiring?" thread (`comments` mode with its story id) into a spreadsheet.
- Collect the most upvoted Show HN posts in a date range (`minPoints`).
- Look up the karma of a list of HN accounts, or list everything one author posted.

### How much does it cost

Pay per event: **$0.0005 per row delivered** (`hn-row`, $0.50 per 1,000). Failed inputs, duplicates and empty items are free. Plan discounts apply (Silver about 10%, Gold and higher about 20%).

- 1,000 rows: $0.50.
- 10,000 rows: $5.
- 100,000 rows: $50.

`maxItems` caps rows and cost, and if you set a maximum spend per run the Actor stops cleanly when it is reached. Apify platform usage is included in the price.

### FAQ

#### Is this the official Hacker News API?

It uses the official search API run by Algolia for Hacker News (hn.algolia.com/api), free and without a key. It is the data behind the HN search page, not the Firebase API.

#### How far back can I search?

All of Hacker News history is indexed. A relevance search returns the best 1,000 hits only. With `sortBy: date` the Actor moves through time and can return more than 1,000 rows. That continuation is covered by unit tests with a mocked API; live, only one run of about 500 rows was tried.

#### Is the data complete and real-time?

No. Algolia's index can trail HN, and deleted or dead items are missing. Use it for research and monitoring on an hourly scale, not for exact counts.

#### Why do some comment rows have no depth?

`depth` is only known in comment-tree mode. Search hits do not carry it; they carry `parentId` and `storyId`.

#### What happens if the API fails or I hit the rate limit?

Requests are retried with backoff. If they keep failing, the run ends with the rows already read, a status message and the error in `SUMMARY`. Rows delivered are charged; nothing else is.

#### Can I read private or personal data?

No. Only public items and the public profile fields (name, karma, about) are returned.

### Related tools

- **RSS Feed Reader & Monitor: RSS/Atom to JSON, Full Text** to follow feeds of blogs and news sites next to Hacker News.
- **Remote Jobs & Work From Home Jobs: 5 Boards, Salaries, Alerts** for job boards beyond the Hacker News hiring threads.
- **Keyword Extractor: Extract Keywords & Keyphrases from Text** to pull topics out of the comment text you collect.

# Actor input Schema

## `mode` (type: `string`):

search = keyword/tag/date search. comments = every comment of the stories in 'Story IDs or links'. user = profiles of the names in 'Usernames'. frontPage = stories currently on the front page. Default: search.

## `query` (type: `string`):

Words to search for in stories or comments (search mode). Example: apify scraping. Leave empty if you filter by author or dates only.

## `contentType` (type: `string`):

What to search in (search mode). Default: stories.

## `sortBy` (type: `string`):

relevance returns at most the best 1000 hits. Newest first can read further back than 1000 rows by moving through time. Default: relevance.

## `dateFrom` (type: `string`):

Only items created on or after this UTC day. Format YYYY-MM-DD, example 2026-01-01.

## `dateTo` (type: `string`):

Only items created on or before this UTC day (inclusive). Format YYYY-MM-DD, example 2026-01-31.

## `author` (type: `string`):

Only items posted by this Hacker News user. Example: pg. 2-15 letters, digits, \_ or -.

## `inStoryId` (type: `string`):

Restrict the search to one story's thread: a story id or link. Example: 8863 or https://news.ycombinator.com/item?id=8863. Best with content type Comments.

## `minPoints` (type: `integer`):

Keep only items with at least this many points (stories and jobs have points, comments do not). Example: 100. Default 0 = no filter.

## `minComments` (type: `integer`):

Keep only stories with at least this many comments. Example: 50. Default 0 = no filter.

## `storyIds` (type: `array`):

For mode 'comments': one story id or link per line. Example: 8863 or https://news.ycombinator.com/item?id=8863. The full tree is read in one API request per story.

## `maxDepth` (type: `integer`):

Comment trees only: keep comments down to this nesting level (1 = top-level comments only). Default 0 = whole tree.

## `includeStoryRow` (type: `boolean`):

Comment trees only: add one row for the story itself before its comments. Default: on.

## `usernames` (type: `array`):

For mode 'user': one Hacker News user name per line. Example: pg. Gives karma and the 'about' text. Unknown names are listed in FAILED and are free.

## `plainText` (type: `boolean`):

Hacker News stores comments as HTML. On = readable plain text (links keep their full address); off = the original HTML. Default: on.

## `maxItems` (type: `integer`):

Most rows delivered (and charged) in this run. Example: 500. Default 100.

## `maxRequests` (type: `integer`):

Safety cap on requests to the Algolia API in one run. The API allows 10,000 requests per hour per IP; this Actor sends at most 2 per second. Default 3000.

## Actor input object example

```json
{
  "mode": "search",
  "query": "apify",
  "contentType": "stories",
  "sortBy": "relevance",
  "minPoints": 0,
  "minComments": 0,
  "maxDepth": 0,
  "includeStoryRow": true,
  "plainText": true,
  "maxItems": 100,
  "maxRequests": 3000
}
```

# Actor output Schema

## `results` (type: `string`):

One row per story, comment or user profile, as JSON, CSV, Excel and more.

## `records` (type: `string`):

Key-value store records: SUMMARY, plus FAILED (inputs that could not be read) and NOTES when present.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "query": "apify"
};

// Run the Actor and wait for it to finish
const run = await client.actor("data-done-right/hacker-news-search").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "query": "apify" }

# Run the Actor and wait for it to finish
run = client.actor("data-done-right/hacker-news-search").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "query": "apify"
}' |
apify call data-done-right/hacker-news-search --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,data-done-right/hacker-news-search"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/zTBCCSdDR0jofwe1q/builds/BpPy87n1eHIOnKg9F/openapi.json
