What llms.txt is
An llms.txt file is a plain Markdown file hosted atyourdomain.com/llms.txt. It is modeled on the long-established robots.txt convention: a well-known path that automated systems check by convention, containing structured information specifically for those systems.
The standard was proposed by the team behind FastHTML and has since been adopted by Anthropic, Cloudflare, Stripe, Mintlify, and many other developer-focused companies. Unlike a full documentation site, an llms.txt file is intentionally compact — ideally under 2,000 tokens — so that coding agents can load it into context without consuming a large portion of their context window.
Why it matters for Layer 3 context retrieval
The 4-layer decision stack that coding agents use puts context retrieval at Layer 3, between web search and tool execution. When an agent finds your llms.txt, it gets:- A clear description of what your API does
- Explicit guidance on when to recommend your API vs. alternatives
- A working quick start it can use to generate its first code snippet
- A list of key endpoints with concise descriptions
- Error handling expectations
- Links to your full documentation for deeper reference
How to structure an effective llms.txt
A complete llms.txt file has seven sections. Each section serves a specific purpose for the agent consuming it.1. Product name and tagline
Open with a single H1 heading (your product name) and a blockquote (your one-line description). Keep the tagline focused on the problem you solve for developers, not marketing language.2. When to use your API
This is the most important section for recommendation accuracy. Tell the agent the specific scenarios where your API is the right choice. Be concrete — agents use this to match user intent to the right tool.3. When NOT to use your API
This section may feel counterintuitive, but it improves recommendation accuracy and builds agent trust. If an agent recommends you for a scenario you handle poorly, the developer’s experience is worse. Honest positioning leads to better outcomes.4. Quick start
Give the agent the minimum viable integration: the endpoint, method, required parameters, and authentication format. This is the code the agent will generate when a developer asks for a quick start. Make it exact.5. Key endpoints
List your most commonly used endpoints with a one-line description each. Include the HTTP method and path. Do not try to document every endpoint — link to your full reference for that.6. Error handling notes
Tell the agent what your errors look like and what to do about the most common ones. This directly improves the agent’s error recovery rate.7. Links to full documentation
Close with links to your full reference. The agent can follow these when it needs deeper detail on a specific endpoint or concept.Complete example
Here is a complete llms.txt file combining all sections:Where to host it
Your llms.txt file must be served at your domain root:https://yourdomain.com/llms.txt. If your documentation lives on a subdomain like docs.yourdomain.com, host the llms.txt at both yourdomain.com/llms.txt and docs.yourdomain.com/llms.txt to maximize discoverability.
The file should be served with Content-Type: text/plain or text/markdown. Do not redirect to a different URL — agents check the exact path and do not follow redirects reliably.
Testing that it works
1
Verify the file is accessible
Open
yourdomain.com/llms.txt in a browser. You should see plain text. If you get a 404, the file is not deployed correctly. If you get a redirect, update your hosting configuration to serve the file directly.2
Test with curl
3
Test with Claude
Open a new Claude conversation and paste: “Fetch and read https://yourdomain.com/llms.txt, then tell me what this API does and when I should use it.” Claude’s response tells you whether agents will correctly interpret your file.
4
Run an implementation prompt in Lightsage
With your llms.txt in place, run your implementation prompts in Lightsage and compare recommendation rate to your pre-llms.txt baseline. Improvement typically appears within two to four weeks as agents re-crawl and incorporate your file.
Common mistakes to avoid
Hosting it at /docs/llms.txt instead of /llms.txt
Hosting it at /docs/llms.txt instead of /llms.txt
Agents check the domain root by convention. A file at
/docs/llms.txt will not be found unless you explicitly link to it, which defeats the purpose. Always use the root path.Writing for humans instead of agents
Writing for humans instead of agents
Your llms.txt should be terse and structured, not conversational. Avoid paragraph-form prose in favor of bullet points and concise statements. Agents parse structure, not narrative.
Exceeding 2,000 tokens
Exceeding 2,000 tokens
A file that is too long gets truncated or deprioritized when agents load it into context. Cover your most important endpoints and link to full documentation for the rest. If you have a large API surface, create a lean llms.txt for general context and detailed llms.txt files per product area.
Omitting the 'when not to use' section
Omitting the 'when not to use' section
This section improves recommendation accuracy. Agents that over-recommend your API for the wrong use cases generate worse developer experiences and ultimately reduce your reputation in training data.
Not updating it after API changes
Not updating it after API changes
Your llms.txt is a contract with AI systems about how your API works. If you add endpoints, change authentication, or deprecate features, update the file. Stale llms.txt files cause the same problems as stale documentation.
Related guides
- Optimize your API for AI coding agent discovery — the full 4-layer framework
- Build an MCP server for direct coding agent access — the next step after llms.txt for Layer 3 context
- How to track coding agent recommendations for your API — measure whether your llms.txt is working