Inspekt Documentation
Inspekt is a real-time observability engine for Node.js APIs. Simply initialize the bridge and attach the middleware to automatically capture every 4xx/5xx error. Inspekt delivers a full AI diagnosis covering the cause, fix, security flags and much more directly to your terminal and dashboard.
Socket Server
Low-latency WebSocket transport layer for real-time log streaming between your host server and the Inspekt dashboard
SDK & Adapters
Non-intrusive middleware that intercepts the request-response cycle across Express, Fastify, and NestJS.
Dashboard
Next.js-powered brain that displays live log streams and renders AI-generated diagnoses for your active API key.
Quickstart
Install the package, initialise an Inspekt instance, call connect(), and register the adapter for your framework. That's the entire setup.
1. Install
npm install @inspekt/js2. Initialise
Create an instance and call connect(). The connect() call is compulsory, it establishes the WebSocket bridge that enables real-time log streaming and AI analysis.
import { Inspekt } from '@inspekt/js';
const inspekt = new Inspekt({
apiKey: "ins_live_...", // 57-character unique key
terminalOutput: true, // Renders AI diagnosis cards in the console
analysisMode: 'errors', // 'errors' | 'always' | 'never'
redactKeys: ["password"] // Custom keys to scrub from headers/body
});
// COMPULSORY: Establishes the WebSocket bridge
inspekt.connect();connect() before mounting your middleware. Without it, logs won't stream to the dashboard and AI diagnoses won't run.3. Get your API key
Generate a key from the API Keys section of your dashboard and pass it as apiKey option. Keys follow the format ins_live_... and are 57 characters long.
Frameworks
Inspekt ships a dedicated adapter for each supported framework. Every adapter uses the framework's native hooks to capture the full request-response cycle with zero-latency overhead.
Express
The Express adapter hijacks res.json and listens for the finish event to calculate response times and capture payloads. Mount it early in your middleware stack so it captures all downstream errors.
import { Inspekt } from '@inspekt/js';
import { inspektExpress } from '@inspekt/js/express';
import express from 'express';
const inspekt = new Inspekt({ apiKey: "ins_live_..." });
inspekt.connect();
const app = express();
// Place early in the middleware stack
app.use(inspektExpress(inspekt));app.use(inspektExpress(inspekt)) before your route definitions but after any body-parser middleware so request bodies are available for logging.Fastify
Register Inspekt as a plugin to monitor traffic with minimal overhead using Fastify's native onRequest, preSerialization, and onResponse hooks.
import { Inspekt } from '@inspekt/js';
import { inspektFastify } from '@inspekt/js/fastify';
import Fastify from 'fastify';
const inspekt = new Inspekt({ apiKey: "ins_live_..." });
inspekt.connect();
const fastify = Fastify();
fastify.register(inspektFastify(inspekt));NestJS
Implemented as a NestInterceptor that uses RxJS tap to monitor successful responses and caught exceptions. Provide the Inspekt instance via your module and apply the interceptor at the controller or global level.
import { Module, Controller, Get, UseInterceptors } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Inspekt } from '@inspekt/js';
import { InspektInterceptor } from '@inspekt/js/nest';
const inspekt = new Inspekt({
apiKey: "ins_live_...",
// 'authorization', 'cookie' and 'set-cookie' are redacted by default.
redactKeys: ['x-api-secret', 'password', 'ssn']
});
inspekt.connect()
@Module({
providers: [
{
provide: 'INSPEKT',
useFactory: inspekt,
},
],
})
export class AppModule { }
@Controller()
@UseInterceptors(InspektInterceptor)
export class AppController {}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
console.log('🚀 Server ready at http://localhost:3000');
}
bootstrap();Configuration
Options
All options are passed to the Inspekt constructor.
| Prop | Type | Default | Description |
|---|---|---|---|
| apiKey | string | - | The unique 57-character identifier for your project. Required for authentication and data streaming. |
| terminalOutput | boolean | true | Toggles structured AI diagnosis cards in your terminal. Prints color-coded analysis for requests processed by analysisMode. |
| analysisMode | 'errors' | 'always' | 'never' | 'errors' | Determines if Inspekt processes only failing requests, every request, or stays in logging-only mode. |
| redactKeys | string[] | ['authorization'] | Additional keys to scrub before transmission. The 'authorization' header is always redacted by default. |
Analysis Modes
The analysisMode option allows you to balance detailed observability against your monthly analysis quota.
'errors'AI diagnosis runs only on 4xx and 5xx responses. This is recommended for most production environments to ensure minimal overhead and quota usage.
'always'AI runs on every request regardless of status code. Useful during active debugging sessions but will consume quota faster.
'never'AI analysis is completely disabled. Inspekt functions as a structured logging layer only with no quota consumed.
Redaction
Inspekt redacts the authorization header from all payloads by default before anything is transmitted. Extend this with the redactKeys array to scrub any additional header or body keys.
const inspekt = new Inspekt({
apiKey: "ins_live_...",
// 'authorization' is always redacted by default.
// Add any additional sensitive keys here:
redactKeys: ["x-api-secret", "password", "token", "ssn"]
});Features
Real-time Streaming
On connect(), the SDK performs a handshake that synchronises your redactKeys and analysisMode configuration with the socket server. From that point, every intercepted request is streamed in real-time to your dashboard with no polling or batch delays.
API key validation and config sync happen once at connection time. The key is never re-sent per request.
Log payloads are emitted over the existing WebSocket connection without the need for a new HTTP round-trip per request.
Terminal Output
When terminalOutput: true is enabled, Inspekt transforms raw socket data into structured, color-coded diagnosis cards. These cards are rendered immediately upon a successful handshake with the AI engine, providing a real-time debugging interface without leaving your development environment.
Cards are visually categorized by impact. Critical status codes or security exposures trigger high-contrast warnings to ensure immediate visibility
If a 500 error occurs without a body, the engine automatically flags the missing debug context to help you identify silent failures
Each terminal card decomposes the request into six primary focus areas:
- Summary: A high-level overview of the event categorized by its severity level.
- Technical Diagnosis: A deep-dive analysis of the root cause derived from the HTTP exchange and stack traces.
- Issues and Anomalies: Specific problems identified within the request lifecycle or payload structure.
- Security and Headers: Assessment of notable headers, missing requirements, and active security flags.
- Performance and Logic: Identification of bottlenecks, timing issues, or unexpected status code behaviors.
- Actionable Fixes: Concrete, code-level recommendations to resolve the identified error immediately.
Reconnection
Network stability is rarely guaranteed. If the WebSocket connection drops due to a network blip, server restart, or deployment, Inspekt initiates an automated, infinite recovery sequence using an exponential backoff strategy.
The SDK will persist through long outages or deployments without ceasing operations.
1000msFast initial recovery window to catch transient network blips and quick restarts.
30sExponential backoff ceiling to protect server resources while maintaining connectivity.
Inspekt uses a capped exponential backoff. The delay between retries doubles with every failure but is capped at a maximum of 30 seconds. This allows the SDK to recover instantly from quick 'blips' while preventing excessive network traffic during long-term outages
| Attempt | Delay | Behaviour |
|---|---|---|
| 1 | 2s | Initial reconnection attempt after a drop. |
| 2 | 4s | Exponential backoff doubles the wait time. |
| 3 | 8s | Continued backoff to reduce server strain. |
| 4 | 16s | Approaching maximum delay window. |
| 5∞ | 30s | Persistent retry mode at the maximum allowed delay. |
connect() again after a network drop because Inspekt restores the session and re-syncs configuration once the connection is re-established.