Hacker News

News API · Works globally · Firebase real-time API · Y Combinator

TL;DR

The Hacker News API provides real-time access to everything on Hacker News — top stories, new submissions, best stories, Ask HN, Show HN, jobs, polls, and individual comments. The API is hosted on Firebase and uses a simple REST/JSON interface. Stories are returned as arrays of IDs; individual items (stories/comments) are fetched by ID. It is one of the fastest and most reliable social news APIs, with no rate limiting for reasonable use.

Quick start: https://hacker-news.firebaseio.com/v0/topstories.json

No API key needed — just make a request!

How to Use This API

1. Top Stories (IDs)

https://hacker-news.firebaseio.com/v0/topstories.json

2. Get Story Details

https://hacker-news.firebaseio.com/v0/item/8863.json

3. New Stories

https://hacker-news.firebaseio.com/v0/newstories.json?print=pretty

4. JavaScript — Top 10 Headlines

fetch('https://hacker-news.firebaseio.com/v0/topstories.json')
  .then(r => r.json())
  .then(ids => ids.slice(0, 10))
  .then(ids => Promise.all(ids.map(id =>
    fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`).then(r => r.json())
  )))
  .then(stories => {
    stories.forEach(s => {
      console.log(s.title, '—', s.score, 'points,', s.descendants, 'comments');
    });
  });

5. Python — Fetch Stories

import requests

# Get top story IDs
resp = requests.get('https://hacker-news.firebaseio.com/v0/topstories.json')
top_ids = resp.json()[:10]

# Fetch each story
for sid in top_ids:
    story = requests.get(f'https://hacker-news.firebaseio.com/v0/item/{sid}.json').json()
    print(f"{story['title']} ({story['url']}) [{story['score']} pts]")
Try it: https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty

Frequently Asked Questions

What feeds are available?
topstories, newstories, beststories, askstories, showstories, jobstories. Each returns an array of item IDs.
How do I get a user's info?
Use /v0/user/{username}.json to get a user's profile including karma, created date, and submitted items.
How many items does topstories return?
Top stories returns up to 500 item IDs (the current front page history). Individual items are then fetched by ID.
What fields does an item have?
id, type (story/comment/job/poll), by, title, url, text, score, descendants, kids (comment IDs), time (Unix timestamp), and deleted/dead flags.
Can I get comments recursively?
Yes, each comment in the kids array has its own kids array. You traverse comment trees by fetching child items recursively.

What You Can Build