SDK reference
createAtuneMiddleware()
Auto-capture behavior from every server request, fire-and-forget.
createAtuneMiddleware() returns a middleware that records every server request
as a signal. npx atune init installs it for you; add it by hand when you want
control or aren't on Next.js.
// middleware.ts
import { createAtuneMiddleware } from "atune";
const atune = createAtuneMiddleware();
export function middleware(request: Request) {
return atune(request);
}What it captures
- Each request is recorded as
http.<method>.<normalized-route>, resolved to the account and user from your auth session. - Fire-and-forget. The call is never awaited on your request path — a slow or down Atune can never delay or break your app.
- Bodies are never read. No passwords, tokens, or card numbers ever leave your app.
Chaining with an existing middleware
Already running Clerk (or any other) middleware? Call atune(request) inside
your handler so both run:
import { clerkMiddleware } from "@clerk/nextjs/server";
import { createAtuneMiddleware } from "atune";
const atune = createAtuneMiddleware();
export default clerkMiddleware((auth, request) => {
atune(request); // fire-and-forget
// ...your existing logic
});npx atune init performs this chaining automatically when it detects an existing
middleware.
Account resolution
The middleware auto-detects the account and user from Clerk, NextAuth, or Supabase sessions. If your app has teams or organizations, it uses the team/org; otherwise the signed-in user. See the Next.js guide for details and the escape hatch when your auth can't be auto-detected.