# Fastify

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

> Reference for @tailrace/fastify - tailraceFastify plugin and TailraceFastifyOptions.



`@tailrace/fastify` provides an OpenAI-compatible Fastify plugin. It scans chat request bodies and JSON / SSE responses at the model boundary via `preHandler` and `onSend` / stream wrapping.

## Install [#install]

```bash
pnpm add @tailrace/core @tailrace/fastify fastify
```

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

## Exports [#exports]

| Export                   | Description              |
| ------------------------ | ------------------------ |
| `tailraceFastify`        | Returns a Fastify plugin |
| `TailraceFastifyOptions` | Options type             |

## Options [#options]

| Option       | Default               | Notes                         |
| ------------ | --------------------- | ----------------------------- |
| `mode`       | `"openai-compatible"` | Only mode in v0.1             |
| `agent`      | `"default"`           | `(req) => string`             |
| `workflowId` | `"default"`           | `string` or `(req) => string` |
| `onDecision` | -                     | Audit callback                |

Boundary provider is the request body's `model` string as-is (no `${providerId}/${modelId}` rewrite).

## 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 Fastify app](/docs/guides/block-secrets-in-fastify)
* [Fastify integration](/docs/integrations/fastify)
* [HTTP shared pipeline](/docs/reference/http)
