⚡ You're viewing a live demo of ChimerAI. Data resets daily at midnight UTC.Get the CLI →

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 management
  • app/api/prompts/route.ts — GET / POST list endpoint
  • app/api/prompts/[id]/route.ts — GET / PUT / DELETE single template
  • prisma/schema.prismaPromptTemplate model

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

MethodPathDescription
GET/api/promptsList all active templates
POST/api/promptsCreate a new template
GET/api/prompts/:idGet a single template
PUT/api/prompts/:idUpdate a template
DELETE/api/prompts/:idDelete 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));

Further Reading

ChimerAI Docs · Back to Demo