MarkdownCopies this page as Markdown, ready to paste into an AI assistant.
Hacker News API
4 Hacker News endpoints behind one key, priced in credits per call and routed to the cheapest healthy source.
On this page
Social · 4 endpoints · from 1 credit per call
Endpoints
- POSTHacker News Profile
/v1/run/hackernews.profileA Hacker News user's public profile: karma, about text and account creation date.1 creditper call - POSTHacker News Search
/v1/run/hackernews.searchFull-text search of Hacker News stories and comments with title, link, author, points and comment count.1 creditper call - POSTHacker News Story
/v1/run/hackernews.storyOne Hacker News story or item by id: title, link, author, points, comment count and timestamp.1 creditper call - POSTHacker News Story Comments
/v1/run/hackernews.story_commentsEvery comment of a Hacker News story, flattened depth-first with parent ids, authors, timestamps and depth.1 creditper call
Calling them
Every endpoint on this page is one POST to https://api.primaryapi.com/v1/run/{sku} with your API key and a JSON body. Responses share one envelope, so code written for one endpoint handles the others. For example, hackernews.profile:
curl -sS -X POST "https://api.primaryapi.com/v1/run/hackernews.profile" \
-H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"handle":"pg"}'const res = await fetch('https://api.primaryapi.com/v1/run/hackernews.profile', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRIMARYAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
handle: 'pg',
}),
});
const body = await res.json();
if (!res.ok) throw new Error(`${body.code}: ${body.error}`);
// found:false is a successful answer ("does not exist"), not an error
console.log(body.output.found ? body.output.data : body.output.reason, body.credits);import os
import requests
res = requests.post(
"https://api.primaryapi.com/v1/run/hackernews.profile",
headers={"Authorization": f"Bearer {os.environ['PRIMARYAPI_API_KEY']}"},
json={
"handle": "pg",
},
timeout=60,
)
body = res.json()
if not res.ok:
raise RuntimeError(f"{body['code']}: {body['error']}")
# found=False is a successful answer ("does not exist"), not an error
print(body["output"]["data"] if body["output"]["found"] else body["output"]["reason"], body["credits"])New to PrimaryAPI? Start with the Quickstart, then read Making requests.