# AI SEO on Next.js: robots.ts, AI crawlers and JSON-LD

> How to write robots rules for AI crawlers in the Next.js App Router with robots.ts, allow AI search while opting out of training, and add JSON-LD.

Source: https://aiseotop.com/platforms/nextjs (updated 2026-12-01)

In the Next.js App Router, `robots.txt` is code, which makes it easy to get exactly right and just as easy to get wrong.

## robots.ts

Add `app/robots.ts` (or a static `app/robots.txt`). It returns a `Robots` object, and `rules` can be an array so each crawler gets its own group:

```ts
import type { MetadataRoute } from 'next'

export default function robots(): MetadataRoute.Robots {
  return {
    rules: [
      { userAgent: '*', allow: '/' },
      // Allow AI search; opt out of OpenAI and Anthropic training.
      { userAgent: ['OAI-SearchBot', 'Claude-SearchBot', 'PerplexityBot'], allow: '/' },
      { userAgent: ['GPTBot', 'ClaudeBot'], disallow: '/' },
    ],
    sitemap: 'https://example.com/sitemap.xml',
  }
}
```

Next.js writes one `User-Agent` group per entry. A crawler named in its own group ignores the `*` group, so be explicit about anything you block. Brave's crawler, which powers Claude's web search, has no name of its own and follows your `Googlebot` rules.

## How do you check what your Next.js site allows?

Environment-specific code is a common trap: a `disallow: '/'` meant for preview deployments that ends up in production. After deploying, run the live site through our [AI crawler checker](https://aiseotop.com/tools/ai-crawler-checker), and look up any crawler in the [AI crawler directory](https://aiseotop.com/bots).

## Server-render your content

AI crawlers and search engines read the HTML your server sends. Content that only appears after client-side JavaScript runs may not be seen. Server Components and static rendering, the App Router's defaults, avoid that.

## JSON-LD

Render a `<script type="application/ld+json">` in the page or layout with your `Organization`, `LocalBusiness` or `SoftwareApplication` data. Our [schema generator](https://aiseotop.com/tools/schema-generator) writes the JSON for you.

## Sources

- Next.js docs, [robots.txt file convention](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/robots)
