How to use the Hacker News API from Python

Hacker News has two free APIs. The official one at hacker-news.firebaseio.com/v0 gives top, new and best story ids and each item by id, with no key and, per its README, no rate limit; it has no search. For search, hn.algolia.com/api/v1/search?query=...&tags=story is free too, and our Hacker News Search API wraps it with plain-text comments and discussion links for $0.002 per search.

Try it free Hacker News Search API — stories and comments, $0.002 · $0.002 / call

Top stories with the official API

topstories returns up to 500 ids and each item is a separate request, so fetch them in parallel. Comments are items too, linked through kids, which makes reading a whole thread many requests.

import requests
from concurrent.futures import ThreadPoolExecutor

BASE = "https://hacker-news.firebaseio.com/v0"
ids = requests.get(f"{BASE}/topstories.json", timeout=10).json()[:20]

def item(i):
    return requests.get(f"{BASE}/item/{i}.json", timeout=10).json()

with ThreadPoolExecutor(8) as pool:
    for s in pool.map(item, ids):
        print(s.get("score"), s.get("title"), s.get("url"))

Search with Algolia

Comment hits come back with HTML in comment_text and the parent story under story_title. Plan to strip tags before you show or store them.

r = requests.get("https://hn.algolia.com/api/v1/search", params={
    "query": "cloudflare workers", "tags": "story", "hitsPerPage": 10}, timeout=10)
for h in r.json()["hits"]:
    print(h["points"], h["title"], f"https://news.ycombinator.com/item?id={h['objectID']}")

# Newest first: /api/v1/search_by_date   Comments: tags=comment

Which to use

NeedUse
Today's front pageFirebase topstories and item
Live updatesFirebase (it supports streaming through Firebase clients)
Everything HN said about a productAlgolia search, tags=story or comment
Newest mentions for monitoringAlgolia search_by_date
Search from an AI agent with clean outputHacker News Search (iamai.markets)

The paid wrapper, honestly

Our Hacker News Search API uses the same Algolia search. You send query, type (story or comment), sort (relevance or date) and limit (1 to 30), and get hits with id, title, url, plain-text text cut to 600 characters, points, comments, author, created_at and the hn_url discussion link. For comments, title and url are the story they reply to. No matches means no charge.

At $0.002 per search it's for agents and no-code flows that pay with x402 and want a stable, tidy shape. A Python developer can call Algolia directly for free, as above.

r = pay_session.post("https://iamai.markets/api/x402/services/VCxxJc6CSZqE", json={
    "query": "cloudflare workers", "type": "comment", "sort": "date", "limit": 10})
for h in r.json()["result"]["hits"]:
    print(h["created_at"], h["author"], h["text"][:80], h["hn_url"])

The product

Questions

Does the Hacker News API need a key?

No. Neither the Firebase API nor Algolia's HN search needs a key.

Can I post or vote through the API?

No. Both APIs are read-only.

How fresh are points and comment counts?

Algolia's index can lag the live site by a few minutes; the Firebase item endpoint is current.

Related

Updated 2026-12-02