Prompt Templates — Integration Guide
Overview
Prompt Templates let you store, categorise, and reuse system prompts across your AI features. Admins can create templates in the dashboard; the chat interface loads them dynamically.
Quick Start
npx chimerai add prompts
This scaffolds:
app/dashboard/prompts/page.tsx— CRUD UI for template managementapp/api/prompts/route.ts— GET / POST list endpointapp/api/prompts/[id]/route.ts— GET / PUT / DELETE single templateprisma/schema.prisma—PromptTemplatemodel
Database Model
model PromptTemplate {
id String @id @default(cuid())
name String
category String
description String?
content String @db.Text
language String @default("en")
tags String[] // Postgres array
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
API Endpoints
| Method | Path | Description |
|---|---|---|
GET | /api/prompts | List all active templates |
POST | /api/prompts | Create a new template |
GET | /api/prompts/:id | Get a single template |
PUT | /api/prompts/:id | Update a template |
DELETE | /api/prompts/:id | Delete a template |
Using a Template in the Chat UI
// Fetch templates
const { data: prompts } = useSWR<PromptTemplate[]>('/api/prompts', fetcher);
// Apply selected prompt to chat
const [systemPrompt, setSystemPrompt] = useState('');
function handleSelectPrompt(template: PromptTemplate) {
setSystemPrompt(template.content);
}
Access Control
Protect prompt management behind the admin role:
// app/dashboard/prompts/page.tsx
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { redirect } from 'next/navigation';
const session = await getServerSession(authOptions);
if (session?.user?.role !== 'admin') redirect('/');
Categories & Tags
Use categories to group prompts by domain (e.g. customer-support, coding, marketing) and tags for finer-grained filtering.
// Filter by category
const filtered = prompts.filter((p) => (category === 'all' ? true : p.category === category));