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-nestjs

Use 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/express

Install other providers when needed:

pnpm add @anvia/anthropic @anvia/gemini @anvia/mistral

3. 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

FilePurpose
src/ai/anvia.module.tsNest module for Anvia providers
src/ai/support-agent.service.tsProvider client, model, tools, and agent methods
src/support/support.controller.tsHTTP prompt and stream endpoints
src/approvals/approval-runtime.service.tsUser-owned approval runtime

Next

Build the injectable service in Setup Anvia. Read Runtime Boundaries before wiring Anvia into Nest modules.