Included Features
The three working AI features that ship with the template.
Three working features
They live at /dashboard/features, each a complete example of the pattern: migration, API route, component. Copy one to build your own, or ask your agent to add a feature like ContentWriter.
- AIChat: streaming multi-turn chat, conversations saved per user, 1 credit per message
- ContentWriter: long-form generation with blog, LinkedIn and email presets, history kept, 1 credit per run
- ImageStudio: gpt-image-1 images with a saved gallery, 5 credits per image, needs OPENAI_API_KEY
Where everything lives
lib/supabase/migrations/004_ai_features.sql # ai_conversations, ai_generations, ai_images
app/api/custom/chat/route.js # streaming; the credit is consumed before the stream starts
app/api/custom/generate-content/route.js # one-shot generation, presets held server-side
app/api/custom/create-image/route.js # gpt-image-1, 5 credits
components/features/AIChat.jsx
components/features/ContentWriter.jsx
components/features/ImageStudio.jsx
app/dashboard/features/page.jsx # the tabbed pageThe order every route follows
authenticate → rate limit → validate → consume_credit → call the model → persist → return. If the provider call fails, refund_credit returns the credit. The chat route keeps that order while streaming: the credit is taken before the first chunk is sent. Images come back as base64 and are stored inline; the create-image route contains the Supabase Storage snippet to move them out of the table before launch.