Integration
IndexNow for Next.js
Three small pieces: a key file in public/, a deploy step that calls a hook, and an honest sitemap. Everything else is protocol.
Protocol facts last checked 2026-09-24.
Serve the key file
Put public/<key>.txt in the repository. Next.js serves it at the root as text/plain. If you prefer not to commit it, a route handler works too:
// app/[key]/route.ts is overkill; a fixed path is clearer:
// app/3f9a2c7e0b1d4e8fa6c5b4d3e2f1a0b9.txt/route.ts
export function GET() {
return new Response("3f9a2c7e0b1d4e8fa6c5b4d3e2f1a0b9", {
headers: { "content-type": "text/plain; charset=utf-8" },
});
}Submit after deploy
Create a deploy hook for the site in AutoIndexNow and call it as the last step of your pipeline. The call re-scans the sitemap, checks every tracked page and submits only what changed. It is a plain GET with the token in the header; it takes no body and no query string.
# GitHub Actions, after the deploy step
- name: Notify AutoIndexNow
run: |
curl -fsS "$AIN_HOOK_URL" \
-H "Authorization: Bearer $AIN_HOOK_TOKEN"
env:
AIN_HOOK_URL: ${{ secrets.AIN_HOOK_URL }}
AIN_HOOK_TOKEN: ${{ secrets.AIN_HOOK_TOKEN }}Submit on revalidation
If content changes without a deploy (a CMS webhook calling revalidatePath), submit from the same handler with the API, using the site id and an API key:
await fetch(`https://autoindexnow.com/api/v1/sites/${SITE_ID}/submit`, {
method: "POST",
headers: { authorization: `Bearer ${process.env.AIN_API_KEY}`, "content-type": "application/json" },
body: JSON.stringify({ urls: [`https://example.com/blog/${slug}`] }),
});Keep previews and staging quiet
Only call the hook from the production job. Preview deployments should not submit: their URLs are on another host and would be rejected with 422, and their content is not what you want indexed. Gate the step on the branch or environment.
Keep sitemap lastModified honest
Engines that do not use IndexNow (Google) still read lastmod. In app/sitemap.ts, use real content dates, never new Date() on every build; AutoIndexNow's crawl history shows you which pages actually changed if you need a source of truth.
A 200 or 202 from an IndexNow endpoint means the request was accepted, not that the URL is indexed. Google does not participate in IndexNow.