---
title: withAiReady
description: API reference for the Next.js config wrapper.
canonical_url: https://next-ai-ready.vercel.app/en/docs/api-reference/with-ai-ready
url: https://next-ai-ready.vercel.app/en/docs/api-reference/with-ai-ready
last_updated: 2026-08-01
updated: 2026-08-01
author: next-ai-ready team
summary: API reference for the Next.js config wrapper.
topics: [api, reference]
---

# withAiReady

`withAiReady()` is a Next.js config wrapper that adds URL rewrites and file tracing for AI-ready routes.

## Import

```ts
import { withAiReady } from "next-ai-ready"
```

Consumer apps should install only `next-ai-ready`. The focused `/config` subpath avoids loading build-time scanning and CLI modules while Next.js evaluates its configuration.

## Usage

```ts
// next.config.mjs
import { withAiReady } from "next-ai-ready"

export default withAiReady()({
  // your normal Next.js config
  reactStrictMode: true,
})
```

The function is curried: the first call accepts options, the second call accepts your Next.js config.

## Options

```ts
interface WithAiReadyOptions {
  rewrites?: boolean
  fileTracing?: boolean
  agentReadable?: boolean | {
    accept?: boolean
    userAgents?: boolean | string[]
  }
}
```

| Option          | Type                | Default | Description                                                                                                                                                 |
| --------------- | ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rewrites`      | `boolean`           | `true`  | Add URL rewrites for AI routes. Disable if you want to mount routes yourself.                                                                               |
| `fileTracing`   | `boolean`           | `true`  | Add `outputFileTracingIncludes` so `.next-ai-ready/*.json` ships with serverless bundles. Disable if your deployment adapter ships the whole project.       |
| `agentReadable` | `boolean \| object` | `false` | Opt in to `Accept: text/markdown` negotiation and, when enabled, Markdown responses for known or custom agent user agents. Adds the matching `Vary` header. |

Use `agentReadable: true` to enable both Accept and built-in agent User-Agent negotiation. Use `agentReadable: { accept: true }` for Accept-only behavior, or pass a custom `userAgents` list. API paths, Next.js internals, and paths with file extensions are excluded.

## What it does

When `rewrites` is `true`, adds these rewrites:

| Source            | Destination                 | Purpose                  |
| ----------------- | --------------------------- | ------------------------ |
| `/llms.txt`       | `/_ai-ready/llms-txt`       | Site-wide LLM index      |
| `/llms-full.txt`  | `/_ai-ready/llms-full`      | Full content dump        |
| `/:path*.md`      | `/_ai-ready/md/:path*`      | Per-page Markdown        |
| `/:path*.ai.json` | `/_ai-ready/ai-json/:path*` | Per-page structured JSON |
| `/openapi.json`   | `/_ai-ready/openapi`        | OpenAPI spec             |
| `/tools.json`     | `/_ai-ready/tools`          | Tool definitions         |

When `fileTracing` is `true`, adds:

```json
{
  "outputFileTracingIncludes": {
    "/_ai-ready/**/*": [".next-ai-ready/**/*"]
  }
}
```

This ensures the build artifacts are included in serverless function bundles (required for Vercel, AWS Lambda, etc.).

## Merging with existing config

`withAiReady()` merges with your existing config:

- If your config has a `rewrites()` function, the AI rewrites are appended.
- If your config has `outputFileTracingIncludes`, the AI entry is merged in.
- All other config properties are preserved unchanged.

## Disabling rewrites

If you want to control URL routing yourself:

```ts
export default withAiReady({ rewrites: false })({
  // rewrites are not added; you must mount /llms.txt etc. yourself
})
```

You still need the route handler files in `app/%5Fai-ready/` — the rewrites just map clean URLs to them.
