Tailrace
Integrations

Fastify

OpenAI-compatible Fastify plugin - scan chat bodies and SSE streams, return 422 on policy block.

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

Quickstart

import { createTailrace } from "@tailrace/core";
import { tailraceFastify } from "@tailrace/fastify";
import Fastify from "fastify";

const app = Fastify();
const tailrace = createTailrace();

await app.register(
  tailraceFastify(tailrace, {
    agent: (req) => String(req.headers["x-agent-id"] ?? "default"),
    workflowId: (req) => String(req.headers["x-workflow-id"] ?? "default"),
  }),
);

Peer: fastify >=4. Only mode: "openai-compatible" in v0.1. Uses preHandler + onSend / stream wrapping.

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