API

Free Random Facts API

A free, open JSON API that serves random facts. No API key, no sign-up, just fetch and go. Perfect for apps, bots, dashboards, and weekend projects.

Free forever
No API key
CORS enabled
10,000+ facts
Base URL Endpoints Try It Live Code Examples Rate Limits Attribution FAQ

Base URL

Endpoint https://factfacts.com/api.php

All requests use HTTPS. The API returns JSON with Content-Type: application/json. CORS is fully enabled so you can call it from any domain.

Endpoints

There is one endpoint with optional query parameters.

GET /api.php Get random fact(s)

Returns one or more random facts, optionally filtered by category.

ParameterTypeDescription
cat string Filter by category slug (e.g. science, space). Optional.
count integer Number of facts to return (1–10). Default: 1

Single Fact Response

200 OK — JSON
{ "ok": true, "fact": { "id": "42", "text": "Octopuses have three hearts and blue blood.", "category": "general" } }

Multiple Facts Response ?count=3

200 OK — JSON
{ "ok": true, "facts": [ { "id": "42", "text": "Octopuses have three hearts and blue blood.", "category": "general" }, { "id": "87", "text": "Venus rotates in the opposite direction of most planets.", "category": "general" }, { "id": "123", "text": "Sharks have existed longer than trees.", "category": "general" } ] }

Error Response

{ "ok": false, "error": "No facts found for category \"dinosaurs\".", "available_categories": ["general", "science", "space", ...] }

Try It Live

Hit the API right from this page. Edit the URL and press Send.

API Playground
Click "Send Request" to see the response...

Code Examples

Copy-paste snippets to start using the API in seconds.

JavaScript (Fetch)
// Get a random fact const res = await fetch('https://factfacts.com/api.php'); const data = await res.json(); console.log(data.fact.text); // Get 5 science facts const res2 = await fetch('https://factfacts.com/api.php?cat=science&count=5'); const data2 = await res2.json(); data2.facts.forEach(f => console.log(f.text));
Python (requests)
import requests # Get a random fact resp = requests.get("https://factfacts.com/api.php") data = resp.json() print(data["fact"]["text"]) # Get 5 facts filtered by category resp = requests.get("https://factfacts.com/api.php", params={"cat": "space", "count": 5}) for fact in resp.json()["facts"]: print(fact["text"])
cURL
# Get a random fact curl "https://factfacts.com/api.php" # Get 3 animal facts curl "https://factfacts.com/api.php?cat=animal&count=3" # Pretty-print with jq curl -s "https://factfacts.com/api.php?count=5" | jq .
Node.js
const response = await fetch('https://factfacts.com/api.php'); const { fact } = await response.json(); // Use in a Discord bot, Slack bot, or any project console.log(`Did you know? ${fact.text}`);

Rate Limits

60 requests per minute per IP address. If you exceed this limit, the API will return a 429 Too Many Requests response with a Retry-After header.

This is generous enough for most use cases. If you need higher limits, reach out and we'll work something out.

Attribution (Required)

The FactFacts API is completely free. All we ask is that you credit FactFacts.com with a visible link wherever you display the facts. Every API response includes an attribution object to make this easy.

Example attribution in your app or site:

Facts from FactFacts.com

HTML
Facts from <a href="https://factfacts.com">FactFacts.com</a>
Markdown
Facts from [FactFacts.com](https://factfacts.com)

The link should be visible to users (not hidden or no-follow). Footer placement is fine. If you're using the data in a mobile app, a link in your About or Credits screen works.

HTTP Status Codes

CodeMeaningWhen
200OKSuccessful request
405Method Not AllowedNon-GET request
429Too Many RequestsRate limit exceeded
500Server ErrorFacts database issue

Frequently Asked Questions

Do I need an API key?
No. The FactFacts API is completely free and open. Just send a GET request and you'll get a response. No sign-up, no authentication, no tokens.
Can I use this in a commercial project?
Yes! You can use the API in any project — personal, commercial, open-source. Just include a visible link back to factfacts.com as described in the attribution section.
What categories are available?
The most common category is general. If you pass an invalid category, the API will return a list of all available categories in the error response. Try ?cat=science, ?cat=space, etc.
How many facts are in the database?
Over 10,000 facts and growing. New facts are added regularly across all categories.
Does the API support CORS?
Yes. The API sends Access-Control-Allow-Origin: * so you can call it from any domain, including client-side JavaScript in the browser.
Can I get more than 10 facts at once?
The count parameter is capped at 10 per request. If you need more, make multiple requests. With the 60/min rate limit you can fetch up to 600 facts per minute.
Is there a POST or write endpoint?
Not currently. The API is read-only. Only GET requests are accepted.
What does the response look like if something goes wrong?
Error responses always include "ok": false and an "error" field explaining what went wrong. For category errors, you'll also get an available_categories array.