Next.js
The zero-config path on Next.js, how account detection works, and the escape hatch.
Next.js is the first-class path. npx atune init detects your framework and
auth, installs the package, patches middleware.ts, and writes your env keys.
Run init
npx atune init# When prompted, paste your workspace API key: <YOUR_API_KEY>Sign in to see this sample with your own workspace API key.
Behavior capture starts
init patches your middleware with createAtuneMiddleware(),
chaining it after an existing middleware (like Clerk) if there is one. Every
server request now becomes a signal.
Ask
import { understand } from "atune";
const r = await understand("account:acme", "how healthy is this account?");How account detection works
Atune auto-detects the account and user from your auth session — Clerk, NextAuth, or Supabase. If your app has teams or organizations, it uses the team/org; otherwise the signed-in user. You write nothing.
Escape hatch: custom auth
Using an auth system Atune can't auto-detect? Provide the account explicitly. The rule of thumb: return the account this request belongs to — not just the logged-in user.
What is your account?
If you're unsure what your "account" is, ask: what would you bill this customer as one unit? That's the account.
For per-route named events with a custom account accessor, see Track named events.
Ask a grounded question POST
Answers a question about an account, user, feature, or portfolio from the workspace's existing signals. The endpoint returns `knows: false` instead of guessing when the bundle does not support an answer.
Express / manual
Use Atune outside Next.js — capture behavior and query understanding from any Node server.