How to Publish llms.txt with Astro
Serve llms.txt from Astro’s public folder or create a text endpoint with a Markdown content type.
Setup steps
Choose a static file or a generated endpoint
For a hand-edited file, put UTF-8 Markdown in public/llms.txt. Astro copies it into the build unchanged. If you need generated links or control over headers on a server adapter, use src/pages/llms.txt.ts instead.
Return the Markdown directly from an endpoint
This example sets the response header for on-demand rendering on a project with a server adapter. Replace the sample links or supply your own links from an Astro content collection.
import type { APIRoute } from "astro"; export const prerender = false; export const GET: APIRoute = () => { const body = "# Example Site\n\n> Product documentation and support for Example Site.\n\n## Documentation\n- [Getting started](https://example.com/docs): Setup steps for new users.\n- [Support](https://example.com/support): Find help and contact details.\n"; return new Response(body, { headers: { "Content-Type": "text/markdown; charset=utf-8" }, }); };Verify the deployed URL
With static output, let the host serve the generated .txt artifact or public file as text/plain; charset=utf-8. Check the final route after deploy because hosting rewrites and headers can change the response.
Verify the published llms.txt
Replace example.com with the published hostname and fetch the file. The final response should be HTTP 200 with the expected Markdown body and a Content-Type of text/markdown; charset=utf-8 or text/plain; charset=utf-8.
curl -fsSL -i https://example.com/llms.txtIf status 200 comes back with an HTML homepage, sign-in screen or error page, you have an HTML fallback (a soft 404). Check the final URL and fix the route or rewrite, then fetch it again.
Frequently asked questions
Do I need a server adapter for public/llms.txt?
No. Astro copies public files into the build, and your static host serves them.
Can Astro generate llms.txt during the build?
Yes. Create src/pages/llms.txt.ts and use a prerendered endpoint. The output filename is llms.txt, and the static host controls its delivered headers.
Why does a .txt URL return Astro’s HTML fallback?
A host rewrite can catch a missing file. Confirm the artifact or endpoint is deployed, and make sure the fallback leaves that route intact.
Scan your published site
Check the live page and its robots.txt and llms.txt. The scan is free. If you want files tailored to the report, the $12 Auto-Generated Fix Pack is available from the results.
Run a free scan