Tailrace
Integrations

NestJS

TailraceModule for Nest + Express - OpenAI-compatible middleware with 422 on policy block.

Enforce data policy on OpenAI-compatible chat routes in NestJS (Express adapter). Scan request messages before upstream, scan JSON and SSE responses on the way back.

Quickstart

import { createTailrace } from "@tailrace/core";
import { TailraceModule } from "@tailrace/nestjs";
import { Module } from "@nestjs/common";

@Module({
  imports: [
    TailraceModule.forRoot({
      tailrace: createTailrace(),
      forRoutes: ["v1/*path"],
      agent: (req) => String(req.headers["x-agent-id"] ?? "default"),
    }),
  ],
})
export class AppModule {}

Peer: @nestjs/common >=10. Primary CI target: Nest + Express. For Nest + Fastify, register @tailrace/fastify on the underlying Fastify instance.

Only mode: "openai-compatible" in v0.1. Nest 11 route globs use named splats (v1/*path).

Boundaries covered

LocationTailrace boundaryDirection
Chat request messages{ kind: "model", provider } (model field as-is)Outbound to upstream
JSON chat completionsame model boundaryInbound
SSE text/event-streamsame; carry-buffer across chunksInbound

Block → 422 { error: { type: "policy_violation", entity, rule } }. SSE: cancel upstream, emit one error data: event, close (abort-only; no streamBlockBehavior in v0.1).

Guides

Reference

On this page