@adaptif/next
v0.1.0
Published
Next.js App Router route for Adaptif.
Readme
@adaptif/next
Next.js App Router route for POST /api/adaptif/evaluate and POST /api/adaptif/outcome. The same adaptif.config.ts object is the allowlist in every environment.
npm install @adaptif/react @adaptif/nextRequires Next.js 15.1 or later.
import { createAdaptifRoute } from "@adaptif/next";
import { adaptif } from "../../adaptif.config";
export const { POST } = createAdaptifRoute({ config: adaptif });By default the route builds its provider with providerFromEnv() from @adaptif/server on the first request: the first of TYPESAFE_API_KEY, OPENROUTER_API_KEY, or AI_GATEWAY_API_KEY that's set. Because that happens on the first request rather than when the module loads, next build works without the API key; with no key, that request fails with a 500 and the app renders its fallbacks. Pass provider (an adapter, or a function that returns one) to choose the provider or model yourself.
Mount it at app/api/adaptif/[...path]/route.ts and point <AdaptifProvider endpoint="/api/adaptif"> at that path.
waitUntil defaults to after from next/server, so outcome sink writes finish after the 204. Pass waitUntil to replace that. There is no default client IP: forwarded headers are not trusted unless your platform overwrites them. Pass clientIp with the header that host sets, for example (request) => request.headers.get("x-real-ip").
