Developer documentation

Random Hadith API

Building an Islamic app, dashboard, home-screen widget, or learning tool? Fetch authentic hadith narrations as structured JSON — Arabic text, English translation, book metadata, and chapter information — without hosting your own database.

The API is read-only, returns application/json, and is designed for simple integration in any language that can make HTTP requests.

Free for personal and educational projects. Commercial or high-volume use may require a separate license — see our licensing page for terms, and contact us if you need a commercial agreement or higher limits.

Quick start

The fastest way to display a random hadith is a single request to GET /api:

fetch("https://randomhadith.com/api")
  .then((res) => res.json())
  .then((hadith) => {
    console.log(hadith.text_en);
    console.log(hadith.book, hadith.chapter_name_en);
  });

All responses are JSON. No API key is required. Requests must use HTTPS.

At a glance

EndpointReturnsTypical use
GET /apiFull random hadith objectDaily hadith widgets, one-call integrations
GET /api/random{ "id": number }Pick an ID first, resolve content later
GET /api/hadith?id=Full hadith by IDDeep links, bookmarks, saved favorites

Base URL

https://randomhadith.com

Combine the base URL with the endpoint path. Example: https://randomhadith.com/api/hadith?id=42

Supported collections

Responses draw from verified entries across major Sunni hadith compilations, including Sahih al-Bukhari, Sahih Muslim, Sunan Abi Dawud, Jami` at-Tirmidhi, Sunan an-Nasa'i, Sunan Ibn Majah. Each record includes the source book, chapter number, hadith number, and chapter titles in Arabic and English.

Browse the same content on the website via our hadith collections pages.

Endpoints

GET/api200 OK

Returns a complete random hadith record.

Best for: Apps that need one request for a ready-to-display narration.

Example request

curl "https://randomhadith.com/api"

Example response — 200 OK

{
  "id": 12345,
  "book": "Sahih al-Bukhari",
  "chapter_no": 1,
  "hadith_no": "1",
  "chapter_name_en": "How the Divine Revelation started",
  "chapter_name_ar": "باب كيف كان بدء الوحي",
  "text_ar": "...",
  "text_en": "...",
  "text_ur": "..."
}
GET/api/random200 OK

Returns a random hadith ID without the full text.

Best for: Flows where you store or shuffle IDs before fetching full records.

Example request

curl "https://randomhadith.com/api/random"

Example response — 200 OK

{
  "id": 12345
}

Follow with GET /api/hadith?id=12345 to load the full narration.

GET/api/hadith?id={id}200 OK

Returns a specific hadith by numeric ID.

Best for: Permalinks, user favorites, or revisiting a previously shown hadith.

Query parameters

  • id (required) — integer from 1 to 34,477

Example request

curl "https://randomhadith.com/api/hadith?id=12345"

Example response — 200 OK

{
  "id": 12345,
  "book": "Sahih al-Bukhari",
  "chapter_no": 1,
  "hadith_no": "1",
  "chapter_name_en": "How the Divine Revelation started",
  "chapter_name_ar": "باب كيف كان بدء الوحي",
  "text_ar": "...",
  "text_en": "...",
  "text_ur": "..."
}

Response fields

Full hadith endpoints (/api and /api/hadith) return the same object shape:

FieldTypeDescription
idnumberUnique identifier used across the site and API
bookstringSource collection name
chapter_nonumberChapter number within the book
hadith_nostringHadith number as referenced in the collection
chapter_name_enstringChapter title in English
chapter_name_arstringChapter title in Arabic
text_arstringHadith text in Arabic
text_enstringHadith text in English
text_urstringUrdu text when available; may be an empty string

Code examples

JavaScript (fetch)

const res = await fetch("https://randomhadith.com/api/hadith?id=12345");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const hadith = await res.json();

Python (requests)

import requests

response = requests.get("https://randomhadith.com/api", timeout=10)
response.raise_for_status()
hadith = response.json()
print(hadith["text_en"])

For production apps, call the API from your backend when possible so you can cache responses, respect rate limits, and handle errors consistently.

Rate limiting

Public API routes share one rate limit per client IP to keep the service available for all users. Plan your integration to avoid unnecessary repeat calls.

Rate limit headers

HeaderDescription
X-RateLimit-LimitMaximum requests allowed in the current window
X-RateLimit-RemainingRequests remaining in the current window
X-RateLimit-ResetUnix timestamp (seconds) when the window resets

Rate limit error response — 429

{
  "error": "Rate limit exceeded. Please try again later."
}

Error responses

StatusWhenExample body
400Missing or invalid id on /api/hadith{ "error": "Missing required parameter: id" }
404Hadith ID not found{ "error": "Hadith not found", "id": 99999 }
429Rate limit exceeded{ "error": "Rate limit exceeded. Please try again later." }
500Unexpected server error{ "error": "Failed to fetch hadith", "details": "..." }

Best practices

API behavior and rate limits may change as the service evolves. This page documents the current public endpoints on Random Hadith. Last updated: June 2025.

Developer FAQ

Common questions about integrating the Random Hadith API, rate limits, licensing, and production use.

Is the Random Hadith API free to use?
Yes. The API is free for personal projects, prototypes, and non-commercial educational use. You can call the endpoints without signing up or paying a fee. If you plan to use the API in a commercial product, at high volume, or in a way that requires a separate license, review our licensing terms and contact us before launch.
Do I need an API key or authentication?
No API key is required. All public endpoints accept unauthenticated GET requests over HTTPS. Rate limits are applied per IP address to keep the service fair and stable for everyone.
What is the difference between /api and /api/random?
GET /api returns a complete random hadith in one response — Arabic text, English translation, book name, chapter details, and metadata. GET /api/random returns only a random numeric ID. Use /api when you want the full narration immediately. Use /api/random when you only need an ID and will fetch the full record separately via GET /api/hadith?id=....
Which hadith collections does the API include?
The API serves narrations from major Sunni collections including Sahih al-Bukhari, Sahih Muslim, Sunan Abi Dawud, Jami at-Tirmidhi, Sunan an-Nasa'i, and Sunan Ibn Majah. Each response includes the source book, chapter number, chapter titles in Arabic and English, and the hadith reference number.
What are the rate limits?
Each client IP is allowed 60 requests per 60-second window across all API routes. Every response includes X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers so you can track usage. If you exceed the limit, the API returns HTTP 429 with a JSON error message. Cache responses where possible and implement backoff before retrying.
Can I use the API in a commercial mobile app or SaaS product?
Non-commercial and educational integrations are welcome under our standard terms. Commercial use — including paid apps, subscription services, or products that monetize hadith content — may require a separate commercial license. See the licensing page for details and contact us with your use case if you need written permission or higher limits.
Can I call the API directly from a browser (client-side JavaScript)?
Server-side requests from your backend, scripts, or mobile apps are the most reliable approach. Browser-based calls from another website may be blocked by cross-origin restrictions depending on your setup. For production apps, proxy API calls through your own server so you can cache results, handle errors gracefully, and stay within rate limits.
How should I attribute hadith content from the API?
When displaying hadith text publicly, credit Random Hadith and link back to randomhadith.com where practical. Our licensing page includes recommended attribution wording and explains permitted use under CC BY-NC 4.0 for hadith content. Do not remove source references or present our translations as your own original work.
What valid ID range can I use with /api/hadith?
Hadith IDs are numeric values from 1 to 34,477. Requests with a missing, non-numeric, or out-of-range ID return a 400 error. If the ID is valid but no record exists, the API returns 404 with an error object that includes the requested ID.
How do I request higher rate limits or bulk access?
If your project needs sustained traffic beyond the public limits, contact us through the contact page with a brief description of your application, expected request volume, and timeline. We review requests individually and can discuss custom arrangements for approved commercial or high-traffic use.