# NestJS

URL: https://tailrace.dev/docs/reference/nestjs

> Reference for @tailrace/nestjs - TailraceModule, TailraceMiddleware, and TailraceNestOptions.



`@tailrace/nestjs` provides `TailraceModule.forRoot` and `TailraceMiddleware` for NestJS. Primary CI target: Nest + Express adapter.

## Install [#install]

```bash
pnpm add @tailrace/core @tailrace/nestjs @nestjs/common @nestjs/core reflect-metadata
```

Peer dependency: `@nestjs/common` `>=10`. Depends on `@tailrace/core` + [`@tailrace/http`](/docs/reference/http).

## Exports [#exports]

| Export                  | Description                                |
| ----------------------- | ------------------------------------------ |
| `TailraceModule`        | `forRoot(options)` Nest dynamic module     |
| `TailraceMiddleware`    | Nest middleware implementing openai-compat |
| `TailraceNestOptions`   | Options type                               |
| `TAILRACE_NEST_OPTIONS` | Injection token for module options         |

## Options [#options]

| Option       | Default               | Notes                                                                 |
| ------------ | --------------------- | --------------------------------------------------------------------- |
| `tailrace`   | required              | `Tailrace` instance                                                   |
| `mode`       | `"openai-compatible"` | Only mode in v0.1                                                     |
| `agent`      | `"default"`           | `(req) => string` (Express `Request`)                                 |
| `workflowId` | `"default"`           | `string` or `(req) => string`                                         |
| `onDecision` | -                     | Audit callback                                                        |
| `forRoutes`  | `{*path}`             | Paths for `MiddlewareConsumer.forRoutes`. Prefer `v1/*path` (Nest 11) |

For Nest + Fastify, register [`@tailrace/fastify`](/docs/reference/fastify) on the underlying Fastify instance.

## Block shape [#block-shape]

**422** JSON `{ error: { type: "policy_violation", entity, rule } }`. SSE: one `data:` error event then close (abort-equivalent only). Maps from [`PolicyViolationError`](/docs/reference/errors/POLICY_VIOLATION).

## See also [#see-also]

* [Block secrets in a NestJS app](/docs/guides/block-secrets-in-nestjs)
* [NestJS integration](/docs/integrations/nestjs)
* [HTTP shared pipeline](/docs/reference/http)
