Add Jev DevTools to an existing Next.js App Router app so requests from Route Handlers, Server Actions, and Server Components appear in one drawer.
Use the Node.js runtime for code that imports the server adapter or SDK. This setup keeps the API key on the server and enables inspection only in development. For a runnable example without a key, use the sample Next.js app.
Install and configure#
Install these packages in your Next.js app:
pnpm add jev-devtools @typesafe-ai/sdk server-onlynpm install jev-devtools @typesafe-ai/sdk server-onlyyarn add jev-devtools @typesafe-ai/sdk server-onlybun add jev-devtools @typesafe-ai/sdk server-onlyMerge the SDK externalization into your existing next.config.mjs:
export default {
serverExternalPackages: ["@typesafe-ai/sdk"],
};This lets Node load the SDK. Keep the jev-devtools React entry bundled so it uses Next's React instance during server rendering.
Set TYPESAFE_API_KEY in your server environment. Do not use a NEXT_PUBLIC_ variable for the key. Disabling inspection does not remove the SDK's need for credentials when making live calls.
Share your server adapter#
Create server/jev.ts. If your app uses src/app, put this file in src/server/jev.ts instead.
// server/jev.ts
import "server-only";
import { getJevDevtools } from "jev-devtools/server";
export const inspector = getJevDevtools("my-next-app", () => ({
enabled: process.env.NODE_ENV === "development",
origin: "http://localhost:3000",
}));
export const jev = inspector.createClient({
apiKey: process.env.TYPESAFE_API_KEY,
});Reuse an adapter for a stable key in the same Node realm. The options factory runs once per key; restart after configuration changes. Different processes do not share history.
getJevDevtools(key, createOptions)- key
- A stable, nonempty application key.
- createOptions
- Return the server options, including enabled and origin.
Opt into server capture and inspector endpoints. Defaults to false; disabling capture does not stop inference.
enabledThe exact browser origin, including scheme, hostname, and port.
originCreate an instrumented TypeSafe client. Captures systemOne calls when recording is enabled; otherwise returns an ordinary SDK client. Keep credentials on the server.
adapter.createClient(options, metadata?)- label
- Optional capture label. Defaults to Jev request.
- source
- Capture label: sample or live. Defaults to live. This does not switch transports or prevent inference.
API reference: getJevDevtools() · createJevDevtools() · adapter.createClient()
Use an app-specific key and set origin to the exact browser URL, including scheme and port. localhost and 127.0.0.1 are different origins.
Import this jev client wherever your server calls systemOne. Requests made through other clients will not appear in this adapter's history.
getJevDevtools() reuses the adapter across module reloads in the same Node realm. Its options factory runs once per key. Restart the server after changing options such as origin or redaction.
Expose the optional catch-all route#
Create this Route Handler under your app directory:
// app/api/jev-devtools/[[...path]]/route.ts
import { inspector } from "../../../../server/jev";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export const GET = (request: Request) => inspector.handleNodeRoute(request);
export const DELETE = (request: Request) => inspector.handleNodeRoute(request);Check Host, normalize a Node framework's internal request URL, and apply the adapter's access checks. Route the base endpoint and all subpaths here.
adapter.handleNodeRoute(request)API reference: adapter.handleNodeRoute()
The double brackets matter. [[...path]] serves both the base endpoint, which returns configuration, and child endpoints for the event stream and clearing history.
handleNodeRoute() checks the incoming Host and normalizes framework-internal request URLs. If you use a proxy, preserve Host and keep the event stream out of caches and buffering. Forwarded host headers are not trusted.
Mount a Client Component#
Create the wrapper:
// app/devtools.tsx
"use client";
import { JevDevtools } from "jev-devtools";
export function Devtools() {
return <JevDevtools enabled={process.env.NODE_ENV === "development"} />;
}Mount the inspector once near your application root. It connects after mounting when enabled; it renders nothing during SSR.
<JevDevtools enabled defaultOpen={false} />- enabled
- Load and connect the browser inspector. Defaults to false; enable the server adapter separately.
- defaultOpen
- Whether the drawer starts expanded. Defaults to true; false starts at the launcher.
- endpoint
- Same-origin inspector path. Defaults to /api/jev-devtools; must match the server adapter.
- redactAdditionalSensitiveData
- Mask supported personal fields in the display. Does not remove captured data. Available since 0.5.0; defaults to true.
Load and connect the browser inspector. Defaults to false; enable the server adapter separately.
enabledAPI reference: JevDevtools
Import it into your existing root layout and render it once inside <body>. A minimal layout looks like this:
// app/layout.tsx
import type { ReactNode } from "react";
import { Devtools } from "./devtools";
export const runtime = "nodejs";
export default function Layout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Devtools />
</body>
</html>
);
}The drawer renders nothing during SSR and connects after mounting. Its styles are included, so no stylesheet import is needed.
Run locally#
Bind the development server to loopback:
npx next dev --hostname 127.0.0.1Open http://localhost:3000, matching the configured origin. If Next uses another port, update origin and restart.
Check the connection before debugging capture:
- Open
/api/jev-devtoolson that origin. Expect JSON withenabled: trueandflows: true. - Open the drawer in your app. It will be empty until your application makes a request through the shared
jevclient. - Trigger an existing action that calls
jev.systemOne(...). Open the resulting record and inspect its input and answers.
The drawer shows actual SDK calls. Cached output or static rendering may not make a new call on each visit, and development rendering may repeat calls. For a failed connection or missing record, use Troubleshooting.
Adapt the setup#
For custom endpoints or a Next.js basePath, align the route location, server endpoint, and React endpoint with the browser-visible path.
For session-specific history, configure getSession() and wrap inference handlers in inspector.run(request, callback). Server Actions and Server Components need a trusted Request derived from server-side headers. The full Next.js reference covers these cases.
Route Handlers cannot inspect the connection's socket address. Keep the server bound to loopback for local use. Shared or tunneled access requires application authorization as described in Privacy & access.
This adapter stores history in one Node process. It does not combine captures from separate workers or serverless instances, and it does not support the Edge runtime.