NestJS
01 Prep
Prepare a NestJS app for Anvia modules and controllers.
Use this path when Anvia runs inside a NestJS backend with modules, dependency injection, and controllers.
1. Create A NestJS Project
pnpm dlx @nestjs/cli new anvia-nestjs
cd anvia-nestjsUse TypeScript and the default Express HTTP adapter unless your app already uses Fastify.
2. Install Anvia
pnpm add @anvia/core @anvia/openai zod
pnpm add -D @types/expressInstall other providers when needed:
pnpm add @anvia/anthropic @anvia/gemini @anvia/mistral3. Add Environment Variables
OPENAI_API_KEY=sk_...Read secrets through your config layer or process.env:
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error("OPENAI_API_KEY is required");
}4. Choose Module Boundaries
| File | Purpose |
|---|---|
src/ai/anvia.module.ts | Nest module for Anvia providers |
src/ai/support-agent.service.ts | Provider client, model, tools, and agent methods |
src/support/support.controller.ts | HTTP prompt and stream endpoints |
src/approvals/approval-runtime.service.ts | User-owned approval runtime |
Next
Build the injectable service in Setup Anvia. Read Runtime Boundaries before wiring Anvia into Nest modules.
