SvelteKit
01 Prep
Prepare a SvelteKit app for Anvia server endpoints.
Use this path when Anvia runs behind SvelteKit endpoints, form actions, or server-only modules.
1. Create A SvelteKit Project
pnpm create svelte@latest anvia-sveltekit
cd anvia-sveltekit
pnpm installChoose TypeScript. Anvia code belongs in server-only files, not client components.
2. Install Anvia
pnpm add @anvia/core @anvia/openai zodInstall other providers when needed:
pnpm add @anvia/anthropic @anvia/gemini @anvia/mistral3. Add Environment Variables
OPENAI_API_KEY=sk_...Read secrets from $env/static/private inside server modules:
import { OPENAI_API_KEY } from "$env/static/private";
if (!OPENAI_API_KEY) {
throw new Error("OPENAI_API_KEY is required");
}4. Choose File Boundaries
| File | Purpose |
|---|---|
src/lib/server/ai/support-agent.ts | Provider client, model, tools, and reusable agent |
src/routes/api/support/+server.ts | JSON endpoint |
src/routes/api/support/stream/+server.ts | NDJSON stream endpoint |
src/hooks.server.ts | Auth and request-local locals |
Next
Build the reusable agent in Setup Anvia. Read Runtime Boundaries before importing Anvia into Svelte components.
