Skip to content

Search and Retrieval

Ayah lookup

GET /v1/tafsir/:surah/:ayah returns the scholars’ passages on one ayah, word for word, with every tafsir that explains it and how many passages each has. It runs no search and calls no model.

Why it is the main road

An app that shows the Qur’an already knows which ayah is on the screen. Asking what the mufassirun say about it needs no query to interpret. It is an indexed read by surah and ayah.

  • No searchNo embedding, no keyword index and no reranker take part. The answer is the passages the books themselves place on the ayah, in a fixed order.
  • The same answer for everyoneThe answer depends only on the URL, so Cloudflare keeps it at the edge for a day and most lookups never reach the Worker. See Caching.
  • Small on a missThe Worker reads D1 twice: once for two bounds the library records at each load (the widest range of ayahs a passage explains, and the widest a passage quotes), which keep the index scans short, then one batch for the books, the quote count and the page of passages.

One ayah can have many passages: on 28 November 2026 the live library had 627 on 2:255, in 63 books. So the answer is paged, and it lists every book that explains the ayah, for your app to offer the others.

Use search (POST /v1/search) for everything else: a topic, a phrase, a question. Search takes filter.surah and filter.ayah (see Filtering) when you want to search within the commentary on one ayah.

Request

GET https://grep.getbayan.app/v1/tafsir/{surah}/{ayah}

No body and no sign-in. Requests are limited by IP address (see Rate limits).

Path parameters

NameTypeRules
surahinteger1 to 114.
ayahinteger1 to the number of ayahs in the surah. An ayah the surah does not have is a 400: Surah 1 has no ayah 8.

Query parameters

NameTypeDefaultRules
booksbook ids, separated by commasthe default tafsirs1 to 10 ids, each above 0. Passages come in the order given. An id given twice counts once, at its first place.
limitinteger401 to 100 passages per page.
afterpassage idnoneThe next value of the page before. It must be a passage of one of the books in the order: the ones named in books, or the defaults when books is left out.

Rules for every parameter

  • Numbers are written in plain decimal digits, with no sign and no leading zeros. /v1/tafsir/2/01 is refused. Each number then has one spelling, so the edge never keeps the same answer twice under two spellings of it.
  • Each parameter may be given once. ?limit=1&limit=2 is refused.
  • An unknown parameter is refused, so a typo such as ?book=1503 fails instead of quietly answering for the default books.
  • An empty books= is refused. Leave the parameter out to get the default tafsirs.
  • The Qur’an’s own id, 0, is refused in books: the Qur’an is never an answer of the lookup.
TypeScript
const BASE = "https://grep.getbayan.app"; interface TafsirOptions {books?: number[];limit?: number;after?: string;} export async function tafsir(surah: number, ayah: number, { books, limit, after }: TafsirOptions = {}): Promise<TafsirResponse> {// books with plain commas, so the same request is always the same URLconst query = [books && `books=${books.join(",")}`, limit && `limit=${limit}`, after && `after=${after}`].filter(Boolean).join("&");const url = `${BASE}/v1/tafsir/${surah}/${ayah}` + (query ? "?" + query : "");const res = await fetch(url);const body = await res.json();if (!res.ok) throw new Error(`${res.status} ${body.error.code}: ${body.error.message}`);return body as TafsirResponse;} // al-Jalalayn, then al-Wajiz, on 112:2, one passage a pageconst page = await tafsir(112, 2, { books: [12876, 2547], limit: 1 }); for (const passage of page.passages) {console.log(passage.citation.text, passage.ayahs);}console.log(page.next); // "12876006229"

Default tafsirs

With no books, the lookup answers from these four tafsirs, in this order. Names and death years are turath.io’s, as the library stores them; the years are hijri.

OrderBook idBookAuthorDied (AH)Ayahs mapped, of 6,236
11503تفسير ابن كثير - ط ابن الجوزيابن كثير7746,236
241تفسير البغوي - طيبةالبغوي، أبو محمد5166,236
342تفسير السعدي = تيسير الكريم الرحمنعبد الرحمن السعدي13766,135
412876تفسير الجلالينالمحلي، جلال الدين8646,225

“Ayahs mapped” is how many ayahs have at least one of the book’s passages, as the current chunker maps them. A book with no passage on an ayah simply has none in the answer.

The defaults are a setting of the service (DEFAULT_TAFSIRS) and can change. If your app must show particular tafsirs, name them in books. Paging works the same way with the defaults: pass next as after and leave books out.

Which books answer

  • Ayah-ready books only. A book answers the lookup once its passages are mapped to ayahs well enough. Its first load marks it ready by its own mapping: only the ayahs the book names by its anchors, headings or printed ayah numbers count, and it must name at least 5,900 of the Qur’an’s 6,236 ayahs or be complete over what it covers. Otherwise a person who has checked the mapping decides. Books whose text has no ayah structure are found by search only. 80 of the 275 tafsirs are ayah-ready; GET /v1/books gives each book’s ayahReady, and Books lists them.
  • Every ayah-ready book is listed. The answer’s books lists every ayah-ready book with at least one passage on the ayah, by book id, whatever you asked for.
  • A book you name that has nothing gives nothing. A book that is not ayah-ready, has no passage on the ayah, or does not exist adds no passages and causes no error.
  • Never the Qur’an. The Qur’an is book 0 of the library, so that search can find the ayahs themselves. Its ayahs are not a commentary on themselves, so it is never listed or answered here.
  • A passage on a group of ayahs is returned for each ayah in the group, and its ayahs field gives the whole range. In the live answer of /v1/tafsir/112/2 with the defaults, al-Baghawi’s passage covers 112:1–2 and as-Sa’di’s covers 112:1–4.

Response

A 200 answer is a TafsirResponse. An ayah that no ayah-ready book explains is still a 200, with empty lists and next: null. Its quotedBy still counts the passages that quote it, so it need not be 0.

This is the answer to GET /v1/tafsir/112/2?books=12876,2547&limit=1:

Response
{"surah": 112,"ayah": 2,"books": […{"book": {"id": 2547,"name": "الوجيز للواحدي","edition": "الكتاب: الوجيز في تفسير الكتاب العزيز\nالمؤلف: أبو الحسن علي بن أحمد بن محمد بن علي الواحدي، النيسابوري، الشافعي (ت ٤٦٨هـ)\nتحقيق: صفوان عدنان داوودي\nدار النشر: دار القلم، الدار الشامية - دمشق، بيروت\nالطبعة: الأولى، ١٤١٥ هـ\nعدد الصفحات: ١٢٤٣\n[ترقيم الكتاب موافق للمطبوع]"},"author": { "id": 1, "name": "الواحدي", "died": 468 },"passages": 1},{"book": {"id": 12876,"name": "تفسير الجلالين","edition": "الكتاب: تفسير الجلالين\nالمؤلف: جلال الدين محمد بن أحمد المحلي (ت ٨٦٤هـ) وجلال الدين عبد الرحمن بن أبي بكر السيوطي (ت ٩١١هـ)\nالناشر: دار الحديث - القاهرة\nالطبعة: الأولى\nعدد الصفحات: ٨٢٧\n[ترقيم الكتاب موافق للمطبوع]"},"author": { "id": 210, "name": "المحلي، جلال الدين", "died": 864 },"passages": 1},…],"passages": [{"id": "12876006229","kind": "passage","book": {"id": 12876,"name": "تفسير الجلالين","edition": "الكتاب: تفسير الجلالين\nالمؤلف: جلال الدين محمد بن أحمد المحلي (ت ٨٦٤هـ) وجلال الدين عبد الرحمن بن أبي بكر السيوطي (ت ٩١١هـ)\nالناشر: دار الحديث - القاهرة\nالطبعة: الأولى\nعدد الصفحات: ٨٢٧\n[ترقيم الكتاب موافق للمطبوع]"},"author": { "id": 210, "name": "المحلي، جلال الدين", "died": 864 },"vol": "1","page": 826,"pageEnd": 826,"heading": ["الإخلاص", "٢"],"ayahs": { "surah": 112, "from": 2, "to": 2 },"text": "﴿اللَّه الصَّمَد﴾ مُبْتَدَأ وَخَبَر أَيْ الْمَقْصُود فِي الْحَوَائِج عَلَى الدَّوَام","notes": null,"quotes": [{ "surah": 112, "from": 2, "to": 2 }],"citation": {"text": "المحلي، جلال الدين (ت ٨٦٤هـ)، تفسير الجلالين، ص ٨٢٦","author": "المحلي، جلال الدين","died": 864,"diedLabel": null,"book": "تفسير الجلالين","edition": "الناشر: دار الحديث - القاهرة؛ الطبعة: الأولى","vol": "1","page": 826,"pageEnd": 826,"printed": true},"source": {"reader": "https://app.turath.io/book/12876?page=6921","pdf": {"url": "https://files.turath.io/pdf/%D8%A7%D9%84%D8%AA%D9%81%D8%A7%D8%B3%D9%8A%D8%B1/%D8%AA%D9%81%D8%B3%D9%8A%D8%B1%20%D8%A7%D9%84%D8%AC%D9%84%D8%A7%D9%84%D9%8A%D9%86%20%D8%A8%D9%87%D8%A7%D9%85%D8%B4%20%D8%A7%D9%84%D9%85%D8%B5%D8%AD%D9%81%20%D8%A7%D9%84%D8%B4%D8%B1%D9%8A%D9%81%20%D8%A8%D8%A7%D9%84%D8%B1%D8%B3%D9%85%20%D8%A7%D9%84%D8%B9%D8%AB%D9%85%D8%A7%D9%86%D9%8A%20-%20%D8%A7%D9%84%D9%85%D8%AD%D9%84%D9%8A%20%D9%88%D8%A7%D9%84%D8%B3%D9%8A%D9%88%D8%B7%D9%8A-%20%D8%B7%20%D8%AF%D8%A7%D8%B1%20%D8%A7%D9%84%D8%AD%D8%AF%D9%8A%D8%AB/158160.pdf","page": 826},"provider": "turath.io","attribution": null}}],"next": "12876006229","quotedBy": 212}

The live API’s answer, on 28 November 2026. It is abridged: it listed 57 books in books, and two are shown. books and quotedBy can change when books are loaded again. The passage’s text is al-Jalalayn’s, word for word as the library stores it.

Fields

FieldTypeMeaning
surahnumberThe surah asked for.
ayahnumberThe ayah asked for.
booksarrayEvery ayah-ready book with a passage on the ayah, by book id. Each entry is { book, author, passages }: the book (id, name, edition), its author, and how many of its passages are on the ayah. The same on every page, whatever books you asked for.
passagesPassage[]This page: passages of the books asked for (or of the default tafsirs), book by book in that order, each book’s passages in book order.
nextstring or nullWhen there are more passages, the id of the last passage on this page: pass it as after. null on the last page.
quotedBynumberHow many passages quote this ayah in ﴿…﴾, in any book of the library, the Qur’an’s own ayahs left out. GET /v1/quotes/:surah/:ayah lists them.

An author is { id, name, died }, with died a hijri year or null. When turath marks the year as not exact, it also has diedLabel: نحو (about), بعد (after), or ق (sometime in that century, when died is the century’s middle year).

Passage fields

FieldTypeMeaning
idstringThe book id × 1,000,000 + the passage’s position in the book: 12876006229 is position 6229 of book 12876. Use it as after, and with /v1/passages/:id/context and /v1/passages/:id/source.
kind"passage"Always "passage" here: a scholar’s words. ("ayah" marks an ayah of the Qur’an itself, which the lookup never returns.)
bookobject{ id, name, edition }. edition is turath’s description of the edition (title, author, editor, publisher, printing, as turath gives them), one item to a line, or null.
authorobjectAs in books. Never null in the lookup.
vol, page, pageEndstring, number, number (each or null)Where the passage stands in its book: the volume label, its first page and its last page.
headingstring[]The headings the passage sits under, outermost first: each as the page prints it, or as turath’s table of contents gives it where the page has no line for it.
ayahs{ surah, from, to }The ayahs the passage explains, from and to inclusive. It holds the ayah asked for, and may be wider.
textstringThe scholar’s words, cleaned of markup, words unchanged. Paragraphs are separated by \n. Qur’an quotes are in ﴿…﴾ where the book marks them so; al-Qurtubi, ar-Razi, ash-Shawkani and Ibn ‘Atiyya set them without.
notesstring or nullThe editor’s footnotes on the passage. null unless the service is set to serve them, which it is not by default: footnotes are the modern editor’s words.
quotes{ surah, from, to }[]The ayahs its ﴿…﴾ quotes were matched to, in the Qur’an’s order. Empty when none was matched, and always empty in a book that does not mark its quotes with ﴿…﴾.
citationobjectAn Arabic reference built from turath’s records, such as المحلي، جلال الدين (ت ٨٦٤هـ)، تفسير الجلالين، ص ٨٢٦, and its parts. printed is true when the page numbers are the printed edition’s, false when turath numbers the book some other way, and null when turath does not say. When it is not true, the reference adds (ترقيم النسخة الإلكترونية) after the page.
sourceobjectreader: turath’s reader at the passage’s page, or null for a passage with no position. pdf: turath’s scan of the printed page, { url, page }, or null; its page is null when the page numbers are not the printed edition’s, and the file then opens at its start. provider: "turath.io". attribution: null for a scholar’s passage.

Lookup passages carry no score or rerankScore. Those come with search results only.

TypeScript
interface TafsirResponse {surah: number;ayah: number;books: { book: BookRef; author: AuthorRef; passages: number }[];passages: Passage[];next: string | null;quotedBy: number;} interface BookRef { id: number; name: string; edition: string | null }interface AuthorRef { id: number; name: string; died: number | null; diedLabel?: string }interface AyahRange { surah: number; from: number; to: number } interface Passage {id: string;kind: "passage" | "ayah";book: BookRef;author: AuthorRef | null;vol: string | null;page: number | null;pageEnd: number | null;heading: string[];ayahs: AyahRange | null;text: string;notes: string | null;quotes: AyahRange[];citation: {text: string;author: string | null;died: number | null;diedLabel: string | null;book: string;edition: string | null;vol: string | null;page: number | null;pageEnd: number | null;printed: boolean | null;};source: {reader: string | null;pdf: { url: string; page: number | null } | null;provider: "turath.io" | "Tanzil Project";attribution: string | null;};}

These are the API’s own types from src/types.ts, with the comments left out and PassageKind, Citation, PassageSource and PdfPage written out in place. Passage there also has the optional score and rerankScore, which only search sends. The type is shared with search, which is why kind, author, ayahs and source allow values the lookup never sends.

Paging

  1. Passages come book by book, in the order of books (or the default order), and within a book in book order, by id.
  2. A page holds at most limit passages. When there are more, next is the id of the page’s last passage.
  3. Send the same request with after set to that id. The next page starts with the passage right after it, so nothing is repeated or skipped.
  4. Stop when next is null.
  • Keep books the same from page to page. A cursor is read by its place in the order, so after must be a passage of one of the books in it. One from another order is a 400: after must be a passage of the books asked for.
  • limit may change between pages.
  • books and quotedBy are the same on every page.

In the example above, the same request with after=12876006229 answers al-Wajiz’s passage 2547006156, and next: null.

TypeScript
// Every passage of the books asked for on one ayah, a page at a time.// tafsir() is the function from the Request section.async function* everyPassage(surah: number, ayah: number, books?: number[]): AsyncGenerator<Passage> {let after: string | undefined;do {const page = await tafsir(surah, ayah, { books, limit: 100, after });yield* page.passages;after = page.next ?? undefined;} while (after);} for await (const passage of everyPassage(2, 255, [1503, 20855])) {console.log(passage.id, passage.citation.text);}

Caching

A 200 answer carries these headers:

HeaderValue
Cache-Controlpublic, max-age=3600, s-maxage=86400
Content-Typeapplication/json; charset=utf-8
Strict-Transport-Securitymax-age=31536000; includeSubDomains
X-Content-Type-Optionsnosniff
  • A day at the edges-maxage=86400 lets Cloudflare’s cache keep the answer for 24 hours. The service has Workers Cache turned on, so a cached answer is served without running the Worker.
  • An hour in your appmax-age=3600 lets a client’s own HTTP cache keep it for an hour.
  • Purged when a book changesWhen a book is loaded again from turath.io, the edge cache is purged. Nothing can purge a copy in a client’s cache, so an app may show an answer up to an hour older than the edge’s.
  • One URL, one copyThe edge keys its cache on the path and the query string, and on the Worker’s version, so a new deployment starts with an empty cache. Requests written the same way share one cached answer. Parameter order counts: ?books=1503&limit=10 and ?limit=10&books=1503 are cached apart. The default lookup of an ayah, with no parameters, is one URL for every user of every app.
  • Errors are not cachedEvery error answer is Cache-Control: no-store.

Rate limits

Only requests that miss the edge cache reach the Worker, so only they count. The lookup shares the read limit with the API’s other GET calls: 300 requests in 60 seconds per caller, counted separately at each Cloudflare location. Cloudflare’s count is approximate: requests can pass the limit while the counts catch up. An IPv4 address counts as one caller, and an IPv6 address counts by its /64. Over the limit, the answer is 429 rate_limited with Retry-After: 60.

Errors

Errors use one envelope:

Response
{"error": {"code": "invalid_request","message": "Surah 1 has no ayah 8."}}

Only the first problem found is reported: the surah, then the ayah, then unknown parameters, then books, limit and after.

StatusCodeWhenMessage
400invalid_requestThe surah is not 1 to 114.surah must be a whole number from 1 to 114.
400invalid_requestThe ayah is not 1 to 286, the length of al-Baqarah.ayah must be a whole number from 1 to 286.
400invalid_requestThe surah has no such ayah.Surah 1 has no ayah 8.
400invalid_requestA parameter other than books, limit and after.Unknown parameter. Allowed: books, limit, after.
400invalid_requestA parameter given twice.limit may be given once.
400invalid_requestbooks is empty, malformed, holds 0, or names more than 10 books.books must be 1 to 10 ids, separated by commas.
400invalid_requestlimit is not 1 to 100.limit must be a whole number from 1 to 100.
400invalid_requestafter is not a whole number above 0.after must be an id: a whole number above 0.
400invalid_requestafter is a passage of a book outside the order.after must be a passage of the books asked for.
405method_not_allowedAny method but GET. The answer has Allow: GET. (Cloudflare’s cache answers a HEAD from the GET’s entry, and sends a HEAD on a cold cache to the Worker as a GET.)This method is not allowed here.
429rate_limitedOver the read limit. Wait the Retry-After seconds.Too many requests. Wait before trying again.
500internalSomething failed inside the service.Something went wrong. Try again later.

A 400 will fail again if sent again: fix the request. A 429 or a 500 can be tried again later.

After the lookup

  • GET /v1/passages/:id/context gives a passage with the passages around it in its book (before and after, 0 to 5 each, default 2), for reading it in place.
  • GET /v1/passages/:id/source gives the passage with the rest of its printed page.
  • GET /v1/quotes/:surah/:ayah lists the passages that quote the ayah, the ones quotedBy counts. It takes books, limit and after by the same rules; with no books, it lists every book’s, by book id.
  • GET /v1/books lists the books, with ayahReady for each.