|
| 1 | +--- |
| 2 | +title: Markdown access |
| 3 | +description: Access your documentation as Markdown — through per-page URLs, `llms.txt`, and `llms-full.txt` — for AI agents and tooling. |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | +Fern serves clean Markdown for any documentation page — including API Reference pages — so agents can consume your content efficiently. Agents fetch the source by appending `.md` or `.mdx` to a page URL, or by sending an `Accept: text/markdown` header via [content negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation). Combined with [`llms.txt`](/learn/docs/ai-features/llms-txt), this reduces token consumption by 90%+ compared to HTML. |
| 8 | + |
| 9 | +<Frame caption="For example, `https://buildwithfern.com/learn/docs/ai-features/markdown.md` displays the Markdown source for this page."> |
| 10 | + <img src="./markdown.png" |
| 11 | + alt="Example showing a page's underlying Markdown" |
| 12 | + className="rounded-lg border border-gray-200 dark:border-gray-700" |
| 13 | + /> |
| 14 | +</Frame> |
| 15 | + |
| 16 | +The same Markdown is used everywhere — single pages, `llms.txt`, and `llms-full.txt` — and respects the same `<llms-only>` and `<llms-ignore>` content controls. |
| 17 | + |
| 18 | +A [default per-page directive](/learn/docs/ai-features/agent-directives) is automatically prepended to every page's Markdown output when served to AI agents, pointing them to your `.md` URLs, `llms.txt`, and `llms-full.txt`. You can [override or disable this directive](/learn/docs/configuration/site-level-settings#agents-configuration) in `docs.yml`. The directive is only visible to agents — human-facing documentation is unaffected. |
| 19 | + |
| 20 | +## Accessing protected docs |
| 21 | + |
| 22 | +On sites with [authentication](/learn/docs/authentication/overview) enabled, agents must include a JWT on every Markdown request — whether for an individual page, `llms.txt`, or `llms-full.txt`. Exchange your [Fern token](/learn/cli-api/cli-reference/commands#fern-token) for a [JWT](/learn/docs/fern-api-reference/get-jwt): |
| 23 | + |
| 24 | +```bash Get a JWT |
| 25 | +curl https://docs.example.com/api/fern-docs/get-jwt \ |
| 26 | + -H "FERN_API_KEY: $FERN_TOKEN" |
| 27 | +# → { "fern_token": "eyJ...", "roles": [] } |
| 28 | +``` |
| 29 | + |
| 30 | +Send the returned JWT as the `FERN_TOKEN` header on subsequent requests: |
| 31 | + |
| 32 | +```bash Fetch protected content |
| 33 | +curl https://docs.example.com/platform/overview \ |
| 34 | + -H 'Accept: text/markdown' \ |
| 35 | + -H "FERN_TOKEN: $JWT" |
| 36 | +``` |
| 37 | + |
| 38 | +JWTs are valid for 30 days — cache and refresh as needed. |
| 39 | + |
| 40 | +## Markdown for troubleshooting |
| 41 | + |
| 42 | +Viewing the Markdown directly is also useful for troubleshooting layout problems. A **View as Markdown** button is enabled by default on every page and can be configured through the [page actions configuration](/learn/docs/configuration/site-level-settings#page-actions-configuration). |
0 commit comments