npx skills add ...
npx skills add openai/plugins --skill ai-generation-persistence
AI generation persistence patterns — unique IDs, addressable URLs, database storage, and cost tracking for every LLM generation
npx skills add openai/plugins --skill ai-generation-persistence
AI generations are expensive, non-reproducible assets. Never discard them.
Every call to an LLM costs real money and produces unique output that cannot be exactly reproduced. Treat generations like database records — assign an ID, persist immediately, and make them retrievable.
nanoid() or createId() from @paralleldrive/cuid2/chat/[id], /generate/[id], /image/[id]The standard UX flow for AI features: create the resource first, then redirect to its page.
This gives you: shareable URLs, back-button support, multi-tab sessions, and generation history for free.
| Data Type | Storage | Why |
|---|---|---|
| Text, metadata, history | Neon Postgres via Drizzle | Queryable, relational, supports search |
| Generated images & files | Vercel Blob (@vercel/blob) | Permanent URLs, CDN-backed, no expiry |
| Prompt dedup cache | Upstash Redis | Fast lookup, TTL-based expiry |
Never serve generated images as ephemeral base64 or temporary URLs. Save to Blob immediately:
Extract usage from every generation and store it. This enables billing, budgeting, and abuse detection:
Avoid paying for identical generations. Cache by content hash:
[id] segments — /api/chat with no ID means generations aren't addressable. Use /chat/[id].