Generate an llms.txt markdown manifest from your FastAPI OpenAPI schema for AI agents. This results in a ~40-50% size reduction vs the output of a OpenAPI spec JSON.
Inspired by the llms.txt specification for LLM-friendly documentation.
OpenAPI and FastAPI's support for it are excellent, but the specification is designed for deterministic machine interpretation. It must be complete and precise. Every schema, every $ref, every possible response. This results in a very large document.
AI agents have different needs:
- Context windows are limited. A 50KB OpenAPI spec consumes tokens that could be used for reasoning.
- Agents can infer. A
Taskmentioned in one endpoint is probably the sameTaskconcept elsewhere. They don't need every relationship spelled out. - Agents recover from errors. If an API responds that
fooneeds to be an integer, the agent adapts. It doesn't need perfect type information upfront.
This project applies the llms.txt philosophy, Concise, readable documentation for LLMs—to APIs.
uv add fast-llms-txtfrom fastapi import FastAPI
from fast_llms_txt import create_llms_txt_router
app = FastAPI(title="My API", description="A sample API")
@app.get("/users")
def list_users(limit: int = 10):
"""List all users."""
return []
# Mount the llms.txt endpoint
app.include_router(create_llms_txt_router(app), prefix="/docs")The prefix determines the final URL path. For example:
prefix="/docs"→GET /docs/llms.txtprefix="/api/v1/docs"→GET /api/v1/docs/llms.txt
Now GET /docs/llms.txt returns:
# My API
> A sample API
## Endpoints
### `GET /users` - List all users.
- **Request Parameters**:
- `limit` (integer, optional)
- **Returns** (200): Successful ResponseCreates a FastAPI router that serves the llms.txt endpoint.
app: Your FastAPI application instancepath: The endpoint path (default:/llms.txt)
Directly convert an OpenAPI schema dict to llms.txt markdown string.
This project uses semantic versioning:
- PATCH (0.1.x): Bug fixes, no API changes
- MINOR (0.x.0): New features, backward compatible
- MAJOR (x.0.0): Breaking API changes
- GitHub CLI installed and authenticated (
gh auth login)
Run the release script:
./scripts/release.sh 0.2.0This will:
- Update version in
pyproject.tomlandfast_llms_txt/__init__.py - Show diff and prompt for confirmation
- Commit the version bump
- Prompt for release notes (or auto-generate from commits)
- Push and create GitHub release (triggers PyPI publish via GitHub Actions)
- PyPI: pypi.org/project/fast-llms-txt
- Trusted Publishing: No tokens required; GitHub Actions authenticates via OIDC
- Environment:
releaseenvironment in GitHub repo settings restricts publishing tov*tags