DEV Community

Cover image for I Built a Random Facts API on Apify — Here's How to Integrate It in Under 5 Minutes
Akash Kumar Naik
Akash Kumar Naik

Posted on

I Built a Random Facts API on Apify — Here's How to Integrate It in Under 5 Minutes

What is the Random Facts API?

The Random Facts API is an Apify Actor I built that gives developers instant access to a database of 1,000+ verified facts covering science, history, nature, and technology.

It's designed for anyone who needs a reliable, structured, cost-efficient source of interesting facts — without scraping, hardcoding, or maintaining a database yourself.


Why I Built This

While building a chatbot side project, I wanted to enrich responses with interesting trivia. Every solution I found was either:

  • A scraper that broke regularly
  • A free API with aggressive rate limits and no bulk support
  • A paid service charging for monthly subscriptions I didn't need

So I built one on Apify's pay-per-event model. You only pay for the facts you actually retrieve. No idle costs.


Modes

The Actor supports four modes via a simple JSON input:

Mode Description
random Get one random fact instantly
batch Download up to 10 facts at once
today Get the featured Fact of the Day
stats View database size and version info

Quick Start: JavaScript

npm install apify-client
Enter fullscreen mode Exit fullscreen mode
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });

const run = await client.actor("akash9078/random-facts-api").call({
  mode: "random"
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0]);
// { text: "Octopuses have three hearts and blue blood.", source: "...", url: "...", html: "..." }
Enter fullscreen mode Exit fullscreen mode

Quick Start: Python

pip install apify-client
Enter fullscreen mode Exit fullscreen mode
from apify_client import ApifyClient

client = ApifyClient("YOUR_API_TOKEN")

run = client.actor("akash9078/random-facts-api").call(run_input={"mode": "random"})

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)
Enter fullscreen mode Exit fullscreen mode

Batch Mode: Download 10 Facts at Once

{
  "mode": "batch",
  "limit": 10
}
Enter fullscreen mode Exit fullscreen mode

MCP Server Setup (for Claude, n8n, etc.)

{
  "mcpServers": {
    "apify": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://mcp.apify.com/?tools=akash9078/random-facts-api",
        "--header",
        "Authorization: Bearer YOUR_API_TOKEN"
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Output Format

Every fact comes back as a clean JSON object:

{
  "text": "Octopuses have three hearts and blue blood.",
  "source": "www.example.com",
  "url": "https://www.example.com/facts/octopuses",
  "html": "
Octopuses have three hearts and blue blood.
Source: www.example.com
"
}
Enter fullscreen mode Exit fullscreen mode

The html field is especially handy for dropping facts directly into blog widgets or emails.


Pricing

Pay-Per-Event model: $0.01 per 1,000 facts.

  • No compute fees
  • No hourly billing
  • No subscription required
  • Pay only for results retrieved

Use Cases

  • Chatbots — enrich AI assistant responses with interesting facts
  • Quiz apps — build trivia databases programmatically
  • Social media — automate daily "Did You Know?" posts
  • Educational platforms — create flashcards and learning materials
  • Website widgets — drop a daily fact into any blog or site
  • Data enrichment — add interesting context to datasets

Try It

🔗 https://apify.com/akash9078/random-facts-api

I'd love to hear what you build with it — drop a comment below! Happy to answer any questions about the implementation or Apify in general. 🚀

Top comments (0)