FastAPI llms.txt: How to Add and Check the File

Islom BaimatovIslom BaimatovOctober 24, 20267 min readUpdated October 17, 2026
FastAPI llms.txt: How to Add and Check the File

Short answer

FastAPI does not generate an llms.txt file automatically, but you can serve one by adding a route or mounting a static directory at the site root. Keep the file public and accurate, then verify that the deployed URL returns the intended text; do not treat llms.txt as a crawler permission setting or a guarantee of AI citations.

If you searched for fastapi llms txt, the implementation is small: publish a plain-text file at `https://your-domain.com/llms.txt`. The harder part is deciding whether that URL is live on the production hostname and whether its links point to pages you actually want discovered. FastAPI can serve the file, but its presence does not establish that an AI engine fetched it, used it, or cited your site.

This is a deployment guide for the person responsible for a FastAPI website—not a tutorial for putting an LLM behind an API. Those are different jobs. Here, the useful question is not how to generate text with FastAPI; it is whether the public file is reachable, current, and useful as an index of your site. For the broader AI discovery picture, see our guide to answer engine optimization and how it works.

What does FastAPI llms.txt mean?

It means serving a file named `llms.txt` from the root of your public website. FastAPI has no built-in `llms.txt` switch: you supply the contents and choose which layer serves them—the application, a web server, or a CDN. The relevant check is the deployed URL, not whether the file exists in your project directory.

The search results for this keyword largely cover building LLM APIs with FastAPI, including chatbot endpoints and local models. That material answers how to expose model functionality. It does not answer how to publish a site index. If your goal is to make important public pages easier to identify, keep the implementation focused on the website’s public root and the quality of the URLs in the file.

How do you add llms.txt to a FastAPI app?

For a fixed file, static hosting is usually the least complicated option. Put `llms.txt` in a directory served publicly and verify that the deployed host maps it to `/llms.txt`. If a reverse proxy or CDN already serves the site’s static assets, serving the file there can avoid adding an application route solely for one text file.

Example project layout:

```text project/ ├── main.py └── public/ └── llms.txt ```

Example FastAPI app:

```python from fastapi import FastAPI from fastapi.staticfiles import StaticFiles

app = FastAPI() app.mount("/", StaticFiles(directory="public", html=True), name="public") ```

A root static mount is broad: review its position and behavior against your existing routes before deploying it. In particular, do not assume that adding a mount at `/` is isolated to the `llms.txt` path. Test the routes your application already serves as well as the new file.

The file can be plain text. For example:

```text

Example Company

Public documentation for Example Company's product.

Product

  • https://example.com/product: Product overview and core use cases.
  • https://example.com/docs: Public product documentation.

Company

  • https://example.com/about: Company background and contact information.

```

Replace the sample URLs with real pages on your site. The descriptions should match the destination pages; do not use the file to make claims the pages do not support. Exclude private dashboards, login-only material, and temporary campaign URLs. A link in this file is not a way to make a private page public, and listing a page does not prove that it is accessible to a crawler.

If you need to assemble the contents dynamically, a dedicated route can return them as plain text. That approach adds code whose output and access behavior need to be maintained. For an unchanged file, prefer the simplest hosting layer your team can verify after deployment.

ApproachWorks well whenCheck before shipping
Static file mounted in FastAPIThe contents are stable and maintained with the siteThe mount does not intercept or break other routes
Dedicated FastAPI routeThe contents need to be generated or assembledThe response is plain text and the URL is not behind authentication
Web server or CDNThe site is already served through an edge or proxy layerThe deployed host serves the current file rather than a stale cached copy

How can you check that FastAPI llms.txt works?

Test the production URL, not only the local app. Request `https://your-domain.com/llms.txt` in a browser or with a command-line client. Confirm that the response succeeds, the contents are readable, and the version is the one you intended to deploy. Repeat the check on the canonical hostname and inspect any redirects between `www` and non-`www` versions; a successful response on a staging host does not verify the public site.

Then open several listed URLs. Check that each loads without signing in, resolves to the intended page, and has not been replaced by a redirect or an error page. This makes the file a testable deployment artifact rather than a list of URLs that merely looks complete in a repository.

A successful request proves only that the URL was reachable under the conditions you tested. It does not prove that a particular AI engine fetched the file or used its contents. Check crawler rules separately: `llms.txt` does not replace `robots.txt`. Our robots.txt review guide covers that separate access check, and testing Googlebot access explains why a successful browser visit does not by itself establish how a crawler sees a page.

For a wider review of discoverability and technical issues, use an SEO audit guide. Keep the checks distinct: the file can load while a listed page is inaccessible, and accessible pages do not prove that an assistant will cite them.

Does llms.txt make AI engines crawl or cite your site?

No. Publishing the file is not a crawler permission, a command to an AI engine, or a citation guarantee. It can serve as a readable guide to selected pages; whether an engine fetches or uses it depends on that engine’s behavior and implementation. The evidence available here does not establish that publishing `llms.txt` increases crawling or citations.

SeoVision’s scan corpus offers a reason to measure citations and brand mentions separately, but not evidence of an `llms.txt` effect. In a 28-day window, the corpus contained 12,301 completed AI-assistant answers across all engines, as of 2026-10-17. What we measured: 27% of those answers named the tracked brand, while 84% cited at least one source. What those figures mean: source citations and brand mentions are different observed outcomes. They do not show that the file caused either outcome, and they are not a comparison of sites with and without the file.

If the business question is whether assistants cite your site in response to buyer questions, test that outcome directly rather than treating deployment as a visibility result. A free AI citation check checks whether ChatGPT, Gemini, and Perplexity cite your site as a source for a buyer question. It checks citations, not brand mentions.

What should you put in an llms.txt file?

Choose a small set of public pages that help a reader understand what the business offers and where its authoritative information lives. Depending on the site, that might mean product documentation, service pages, or company information. Keep the description short and make each link’s label specific enough to distinguish the destination.

Before publishing, check each URL against three practical questions: can someone open it without signing in, does the description accurately represent the page, and is the page important enough to include? Remove links when destinations move or become outdated. If your site uses multiple applications or hostnames, decide which hostname is canonical and test the file there. The contents are only as useful as the public pages they point to.

What the data does not prove

SeoVision’s scan results describe answers in its own corpus, not every response from every AI assistant. The 27% brand-naming and 84% source-citation figures are overall measurements across the corpus; they do not isolate FastAPI websites or compare sites with and without `llms.txt`.

The figures therefore do not show that a file improves crawling, ranking, or citations. To test an effect for a particular site, you would need a comparison that accounts for other changes and measures relevant crawler behavior and outcomes over time. A single before-and-after observation cannot separate a file’s effect from ordinary changes in pages, prompts, or assistant behavior. We do not have that controlled evidence here, so the responsible conclusion is narrower: you can verify whether the file is deployed, but not infer an AI-visibility gain from its presence.

What to do next

  1. Write a plain-text `llms.txt` with an accurate site description and a small selection of important public pages. Confirm that every description matches its destination.
  2. Choose static hosting, a FastAPI route, or your web server based on where the file can be maintained and checked reliably. For a fixed file, use the simplest layer that fits your deployment.
  3. Deploy and request the exact public URL. Confirm the response is readable and current, and check for authentication or an unintended redirect.
  4. Check `robots.txt` independently and open several listed pages as public URLs. Availability of `llms.txt` does not establish that every destination is accessible.
  5. If the objective is AI visibility, measure whether assistants cite your site for relevant buyer questions. Use the free AI citation checker for a direct citation check; do not treat the file’s presence as evidence of visibility.

How we measured

The figures in this article come from SeoVision’s AI-visibility scan corpus of scheduled prompt runs: 12,301 completed assistant answers in a 28-day window, as of 2026-10-17. The reported brand-naming and source-citation rates cover all engines in that corpus. The corpus is not a controlled study of `llms.txt` and does not establish the file’s effect.

FAQ

How do I add an llms.txt file to FastAPI?

Create a plain-text file and serve it at the root URL `/llms.txt`, either by mounting a static directory or by adding a FastAPI route. After deployment, check the public URL to confirm it returns the expected text without authentication or an unintended redirect.

Does FastAPI create llms.txt automatically?

No. FastAPI does not automatically create or configure an `llms.txt` file. You must create the file and configure your app, web server, or CDN to serve it.

Where should llms.txt go on a FastAPI website?

It should be accessible at the root of the public website, such as `https://example.com/llms.txt`. If a reverse proxy or CDN serves the site, that layer can serve the file instead of FastAPI, provided the public URL is correct.

Does llms.txt make AI assistants crawl or cite my website?

No. The file does not force an AI assistant to crawl your site or cite its pages, and it does not replace `robots.txt`. Verify the file’s availability, then measure citations or brand mentions directly rather than assuming the file caused them.

Want this done for you?

SeoVision researches your keywords, writes the articles and publishes them to your site, then tracks how Google and AI assistants rank you. You get the work, not a to-do list.

See how SeoVision works

Reference: SEO & AI-search glossary · AI visibility tools compared · tool alternatives

Make SeoVision a preferred source

One tap and Google shows our articles more often in your Top Stories, Discover and AI answers. It only changes what you see, and you can undo it any time.

See if AI is citing your brand

Track how ChatGPT, Claude, Gemini and Perplexity talk about you — and get cited more.

Get started for free