Random Fact API: The Complete Guide

Need to add interesting facts to your application? This guide covers everything you need to know about getting random facts via API, including categories, verification, and implementation examples.

Fact Categories

The API provides facts across numerous categories, from science and history to pop culture and nature. Each fact is curated for accuracy and interest value.

Facts are tagged by category and difficulty level, making it easy to filter for your specific needs.

Fact Quality and Verification

Available fact categories:

Science

Facts about physics, chemistry, biology, and other sciences. Great for educational apps.

History

Historical events, figures, and little-known stories from the past.

Nature

Facts about animals, plants, and the natural world.

Technology

Interesting facts about inventions, computing, and technological history.

Space

Facts about astronomy, planets, and the universe.

Verified Facts: All facts in our database are verified for accuracy. However, for educational purposes, we recommend citing primary sources when available.

Using the Random Fact API

TinyFn provides a simple endpoint to get random facts:

API Request
GET https://api.tinyfn.io/v1/random/fact?category=science
Headers: X-API-Key: your-api-key
Response
{
  "fact": "Honey never spoils. Archaeologists have found 3,000-year-old honey in Egyptian tombs that was still perfectly edible.",
  "category": "science",
  "tags": ["food", "preservation", "history"],
  "source": "Smithsonian Institution",
  "id": "sci_1842"
}

Parameters

Parameter Type Description
category string Category: science, history, nature, technology, space
tag string Filter by specific tag
max_length integer Maximum fact length in characters
count integer Number of facts to return (default: 1)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/random/fact?category=science',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const { fact, category } = await response.json();
console.log(`Did you know? ${fact}`);
// Did you know? Honey never spoils...

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/random/fact',
    params={'category': 'science'},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"Fact: {data['fact']}\nCategory: {data['category']}")

cURL

curl "https://api.tinyfn.io/v1/random/fact?category=science" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Educational Apps: "Did you know?" features for learning
  • Trivia Games: Fact-based quiz questions
  • Loading Screens: Interesting facts while users wait
  • Daily Widgets: Fact of the day features
  • Content Marketing: Shareable social media content

Best Practices

  1. Cite sources when possible: Include the source field if available
  2. Match audience: Choose appropriate categories and complexity
  3. Cache daily facts: "Fact of the day" should be consistent all day
  4. Encourage sharing: Facts make great social content

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-random": {
      "url": "https://api.tinyfn.io/mcp/random/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all random tools available via MCP in our Random MCP Tools for AI Agents guide.

Try the Random Fact API

Get your free API key and start displaying facts in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key