Playground Sign in Start free

How to Generate an llms.txt File for Any Website

Download runnable code Sign in to prefill your key
Generate llms.txt Download
1

What llms.txt is, and how to generate it

llms.txt is a Markdown file at the root of a website that tells language models what the site contains: the site name, a one-line summary, then the key pages as links with one line each, grouped under sections. To generate it, crawl the site, take each page's title and meta description, group the pages by section and write them in that format. Our run on ujeebu.com read 60 pages for 60 credits and wrote an llms.txt of 59 links in 7 sections.

A crawl bill you can trust

A free quote gives the most a crawl can cost before it starts, and max_credits is a hard cap: the job stops before a page that would pass it. Plain HTML costs 1 credit a page.

llms.txt is an index. For the full text of every page in one file (llms-full.txt), see Convert a website to Markdown for LLMs. To list every URL of a site first, see Find all pages on a website. Both feed the use case Website to RAG knowledge base.

2

The llms.txt format

The proposal at llmstxt.org defines a small Markdown structure, in this order:

  1. an H1 with the name of the site or project (the only required part);
  2. a blockquote with a short summary;
  3. optional paragraphs with more detail;
  4. sections under ## headings, each a list of - [Title](url): description lines.
llms.txt (shape)
# Site name

> One-line summary of the site.

## Section
- [Page title](https://example.com/page): what the page is about
3

Crawl the site as plain HTML

A page's title and meta description sit in its HTML head, so plain HTML without JavaScript is enough, and it is the cheapest page. The crawl starts at the home page and follows its links one level deep (max_depth: 1): the pages a site links from its home page are usually the ones worth listing. Exclude patterns leave out sign-in and legal pages.

SITE = "https://ujeebu.com/"
CRAWL = {
    "urls": [SITE],
    "scope": {"max_depth": 1, "max_pages": 60,
              "exclude": ["/signin", "/signup", "/forgot", "/privacy", "/terms"]},   # pages no reader needs
    "format": "html",
    "page": {"js": False},
}
quote = api("POST", "/crawl/quote", json=CRAWL)
job = api("POST", "/crawl", json={**CRAWL, "max_credits": quote["credits_ceiling"]})

A pattern without a wildcard matches that exact path, and ignores the query string: /signup also leaves out /signup?from=pricing. Then read the finished pages with content=true to get their HTML, 10 at a time.

4

Take each page's title and description

For each page: the <title>, then the meta description, else the Open Graph description, else the first paragraph of at least 40 characters. The home page also gives the site name (og:site_name) and the summary.

class HeadParser(HTMLParser):
    """The <title>, the <meta> name/property values and the first real paragraph of a page."""

    def __init__(self):
        super().__init__()
        self.title, self.meta, self.paragraph = "", {}, ""
        self._in, self._text = None, ""

    def handle_starttag(self, tag, attrs):
        a = dict(attrs)
        if tag == "meta" and (a.get("name") or a.get("property")):
            self.meta[(a.get("name") or a.get("property")).lower()] = a.get("content") or ""
        elif tag in ("title", "p"):
            self._in, self._text = tag, ""

    def handle_endtag(self, tag):
        if tag == self._in:
            text = " ".join(self._text.split())
            if tag == "title" and not self.title:
                self.title = text
            elif tag == "p" and not self.paragraph and len(text) >= 40:
                self.paragraph = text
            self._in = None

    def handle_data(self, data):
        if self._in:
            self._text += data
5

Group the pages and write llms.txt

Pages are grouped by their first path segment when they have two or more (/use-cases/... goes under "Use cases"); single-segment pages such as /pricing go under "Pages", listed first. The site name is cut from the end of each title (Pricing | Ujeebu becomes Pricing).

def section(url):
    """The group of a page: its first path segment when it has two or more, else "Pages"."""
    parts = urlparse(url).path.strip("/").split("/")
    return parts[0].replace("-", " ").capitalize() if len(parts) > 1 else "Pages"


home_title, home_summary, site_name = describe(pages[0]["html"])
site_name = site_name or urlparse(SITE).netloc
groups = collections.defaultdict(list)
for page in pages[1:]:
    title, summary, _ = describe(page["html"])
    title = title.rsplit(" | ", 1)[0] or page["url"]          # "Pricing | Ujeebu" -> "Pricing"
    groups[section(page["url"])].append(f"- [{title}]({page['url']})" + (f": {summary}" if summary else ""))

lines = [f"# {site_name}", "", f"> {home_summary}", ""]
for name in sorted(groups, key=lambda g: (g != "Pages", g)):
    lines += [f"## {name}", "", *groups[name], ""]
with open("llms.txt", "w", encoding="utf-8") as f:
    f.write("\n".join(lines))
llms.txt (trimmed)
# ujeebu.com

> Scrape and extract data from any web page within minutes with Ujeebu's scraper API. Forget managing proxies & gather data at scale. Get your free trial now.

## Pages

- [Web Scraping API: JavaScript Rendering, Rotating Proxies, Pay Only for Success](https://ujeebu.com/scrape): Scrape any website with one API call: JavaScript rendering, rotating, premium and residential proxies and anti-bot handling. ...
- [Markdown for LLM API - AI-Ready Markdown Generation](https://ujeebu.com/markdown): Convert webpages to LLM-optimized markdown for RAG systems, AI training, and chatbots. ...
- [Integrations & SDKs - Node.js, Python, Go](https://ujeebu.com/integrations): Integrate Ujeebu into your stack with official SDKs for Node.js, Python, and Go. ...
- [Ujeebu API Documentation: Scrape, SERP, Extract, Markdown](https://ujeebu.com/docs): Reference docs for the Ujeebu Scrape, Google SERP, Article Extractor, Markdown, ChatGPT and Gemini APIs, ...
...

## Blog

- [https://ujeebu.com/blog/rss](https://ujeebu.com/blog/rss)

## Case study

- [Scaling to 200 Requests/Second - Cline Case Study](https://ujeebu.com/case-study/cline): How Cline scaled their scraper to 200 requests per second with a custom Ujeebu plan. ...

## Use cases

- [Lead Generation & B2B Contact Scraping](https://ujeebu.com/use-cases/lead-generation): Build a B2B prospecting pipeline with the Ujeebu Scrape API. ...
- [Markdown API - Convert Web Pages to Clean Markdown for AI](https://ujeebu.com/use-cases/markdown): Convert any web page to clean, structured Markdown optimized for LLMs and RAG pipelines. ...
...
6

The complete script

Change SITE and the exclude patterns for your site. The Python version needs only requests; the Node.js version needs nothing.

#!/usr/bin/env python3
"""Generate an llms.txt file for any website, with the Ujeebu Crawl API.

Crawls the site as plain HTML (no JavaScript: the cheapest page), takes each page's title and meta
description (or its first paragraph), groups the pages by their first path segment and writes
llms.txt in the llmstxt.org format: the site name as an H1, a one-line summary, then one
"## Section" list of links per group.

    pip install requests
    UJEEBU_API_KEY=your-key python3 generate_llms_txt.py
"""
import collections
import os
import time
from html.parser import HTMLParser
from urllib.parse import urlparse

import requests

API_KEY = os.environ.get("UJEEBU_API_KEY", "YOUR_API_KEY")
API = "https://api.ujeebu.com"

SITE = "https://ujeebu.com/"
CRAWL = {
    "urls": [SITE],
    "scope": {"max_depth": 1, "max_pages": 60,
              "exclude": ["/signin", "/signup", "/forgot", "/privacy", "/terms"]},   # pages no reader needs
    "format": "html",
    "page": {"js": False},
}

http = requests.Session()
http.headers["ApiKey"] = API_KEY


def api(method, path, **kwargs):
    """Call the Crawl API. A GET is tried again after a network error or a timeout."""
    for attempt in range(1, 4):
        try:
            response = http.request(method, API + path, timeout=300, **kwargs)
            break
        except (requests.ConnectionError, requests.Timeout):
            if method != "GET" or attempt == 3:
                raise
            time.sleep(5 * attempt)
    if response.status_code >= 400:
        raise SystemExit(f"{method} {path}: {response.status_code} {response.text}")
    return response.json()


class HeadParser(HTMLParser):
    """The <title>, the <meta> name/property values and the first real paragraph of a page."""

    def __init__(self):
        super().__init__()
        self.title, self.meta, self.paragraph = "", {}, ""
        self._in, self._text = None, ""

    def handle_starttag(self, tag, attrs):
        a = dict(attrs)
        if tag == "meta" and (a.get("name") or a.get("property")):
            self.meta[(a.get("name") or a.get("property")).lower()] = a.get("content") or ""
        elif tag in ("title", "p"):
            self._in, self._text = tag, ""

    def handle_endtag(self, tag):
        if tag == self._in:
            text = " ".join(self._text.split())
            if tag == "title" and not self.title:
                self.title = text
            elif tag == "p" and not self.paragraph and len(text) >= 40:
                self.paragraph = text
            self._in = None

    def handle_data(self, data):
        if self._in:
            self._text += data


def describe(html):
    page = HeadParser()
    page.feed(html)
    summary = page.meta.get("description") or page.meta.get("og:description") or page.paragraph
    return page.title, " ".join(summary.split()), page.meta.get("og:site_name", "")


def section(url):
    """The group of a page: its first path segment when it has two or more, else "Pages"."""
    parts = urlparse(url).path.strip("/").split("/")
    return parts[0].replace("-", " ").capitalize() if len(parts) > 1 else "Pages"


# 1. Price the crawl, cap it at the quote, and wait for it.
quote = api("POST", "/crawl/quote", json=CRAWL)
job = api("POST", "/crawl", json={**CRAWL, "max_credits": quote["credits_ceiling"]})
while not job.get("finished"):
    time.sleep(5)
    job = api("GET", f"/crawl/{job['job_id']}")

# 2. Read every page with its HTML, 5 at a time (whole HTML pages make large answers).
pages, after = [], 0
while True:
    batch = api("GET", f"/crawl/{job['job_id']}/pages", params={"after": after, "limit": 5, "content": "true"})
    pages += [p for p in batch["pages"] if p["state"] == "done" and p.get("html")]
    if not batch["has_more"]:
        break
    after = batch["next_after"]

# 3. One line per page, grouped by section, in the llms.txt format.
home_title, home_summary, site_name = describe(pages[0]["html"])
site_name = site_name or urlparse(SITE).netloc
groups = collections.defaultdict(list)
for page in pages[1:]:
    title, summary, _ = describe(page["html"])
    title = title.rsplit(" | ", 1)[0] or page["url"]          # "Pricing | Ujeebu" -> "Pricing"
    groups[section(page["url"])].append(f"- [{title}]({page['url']})" + (f": {summary}" if summary else ""))

lines = [f"# {site_name}", "", f"> {home_summary}", ""]
for name in sorted(groups, key=lambda g: (g != "Pages", g)):
    lines += [f"## {name}", "", *groups[name], ""]
with open("llms.txt", "w", encoding="utf-8") as f:
    f.write("\n".join(lines))
print(f"llms.txt: {len(pages)} pages in {len(groups)} sections; job {job['stop_reason']}, {job['credits_used']} credits")
Run it
# Python 3, the script saved as generate_llms_txt.py
pip install requests
UJEEBU_API_KEY=your-key python3 generate_llms_txt.py

# Node.js 18 or later, the script saved as generate-llms-txt.js
UJEEBU_API_KEY=your-key node generate-llms-txt.js
Output
llms.txt: 60 pages in 7 sections; job max_pages, 60 credits

The job read 60 pages for 60 credits, the quote's ceiling, and recorded one more URL as a duplicate of another page. The file lists the 59 pages other than the home page. On the same job, the Python and Node.js versions wrote the same llms.txt, byte for byte.

7

Review and publish

  • Read it before you publish it. Meta descriptions are written for search results. In our run the summary came out as the home page's sales line ("Get your free trial now") and the blog's RSS feed was listed with no title: both need a hand edit. Rewrite what reads like an ad, and drop pages that do not help a reader.
  • Put it at the root: https://example.com/llms.txt, served as plain text.
  • Keep it current: run the script on a schedule, or when the site's structure changes; the free quote tells you what each run will cost.
  • Add the full text if you have docs: an llms-full.txt next to it, built by the website to Markdown tutorial.

Size the site first

The free sizer lists a site's sitemap URLs and quotes the crawl before you spend a credit.

?

Frequently Asked Questions

How do I generate an llms.txt file?

List the site's useful pages with a one-line description each, grouped under "## " sections, below an H1 with the site name and a one-line summary. The script on this page crawls the site, takes each page's title and meta description, groups the pages by their first path segment and writes llms.txt.

What is llms.txt?

llms.txt is a Markdown file at the root of a website (/llms.txt) that tells language models what the site contains and where its key pages are, as proposed at llmstxt.org. It holds an H1 with the site name, a short summary in a blockquote, and sections of links with one line each.

What is the difference between llms.txt and llms-full.txt?

llms.txt is an index: one link and one line per page. llms-full.txt holds the full text of the pages in one Markdown file. Convert a website to Markdown for LLMs (/tutorials/website-to-markdown-for-llms) writes llms-full.txt.

How much does it cost to generate llms.txt for a website?

The crawl reads plain HTML, 1 credit a page, and the free quote gives the most it can cost before it starts. The 60-page crawl of this example was capped at 60 credits.

Where do I put the llms.txt file?

At the root of your domain, for example https://example.com/llms.txt, served as plain text. Review the generated file before you publish it: rewrite descriptions that read like ads and drop pages that do not help a reader.