api reference

withAiReady

API reference for the Next.js config wrapper.

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/next"

Usage

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

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    // default: true
  fileTracing?: boolean // default: true
}
OptionTypeDefaultDescription
rewritesbooleantrueAdd URL rewrites for AI routes. Disable if you want to mount routes yourself.
fileTracingbooleantrueAdd outputFileTracingIncludes so .next-ai-ready/*.json ships with serverless bundles. Disable if your deployment adapter ships the whole project.

What it does

When rewrites is true, adds these rewrites:

SourceDestinationPurpose
/llms.txt/_ai-ready/llms-txtSite-wide LLM index
/llms-full.txt/_ai-ready/llms-fullFull 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/openapiOpenAPI spec
/tools.json/_ai-ready/toolsTool 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/_ai-ready/ — the rewrites just map clean URLs to them.