ai-generation-persistence

Persist LLM generations with unique IDs, addressable URLs, database storage, and cost tracking.

Updated Jul 31, 2026
One-click install
npx skills add https://github.com/AarnavBaddam/skills --skill ai-generation-persistence-aarnavbaddam
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-generation-persistence
Source: https://github.com/AarnavBaddam/skills/tree/main/ai-generation-persistence
Command: npx skills add https://github.com/AarnavBaddam/skills --skill ai-generation-persistence-aarnavbaddam

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? LLM generations are expensive, non-reproducible outputs that are lost when apps stream to the client without saving, serve ephemeral base64 images, or keep state only in React or localStorage. This Skill enforces patterns so every generation gets an ID, a permanent URL, database storage, and cost metadata. ## Core Features & Use Cases - Generate-Then-Redirect Pattern: Create a database record with a nanoid before generation, then redirect to an addressable page like /chat/[id] for shareable URLs and refresh-safe streaming. - Persistence Schema & Storage Strategy: Drizzle/Postgres schema for text and metadata, Vercel Blob for generated images, and Upstash Redis for prompt dedup caching. - Cost Tracking: Capture token usage and estimated cost per generation for billing, budgeting, and abuse detection. - Use Case: Building an AI chat app where users can share conversation links, revisit generation history across devices, and avoid paying twice for identical prompts. ## Quick Start Set up my Next.js AI chat route so every generation is saved to the database with an ID and redirected to a shareable /chat/[id] page.

Frequently Asked Questions about ai-generation-persistence

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I save AI chat generations to a database in Next.js?

Create a database record with a nanoid before calling the LLM, then redirect to a /chat/[id] page that renders the generation. Update the record with the result, token usage, and status once streaming completes.

How do I make AI generations shareable with permanent URLs?

Assign each generation a unique ID using nanoid or cuid2 and route it through a dynamic segment like /chat/[id] or /generate/[id]. The page loads the saved record from the database, giving you shareable links and back-button support.

How do I store AI-generated images permanently with Vercel Blob?

Upload each generated image file to Vercel Blob using put() with public access right after generation, then save the returned URLs to your database record. Never serve images as ephemeral base64, which is lost when the component unmounts.

How do I avoid paying for duplicate LLM generations?

Hash the model name plus prompt with SHA-256 and check an Upstash Redis cache before generating. If a cached generation ID exists, return it; otherwise generate and cache the result with a TTL such as one hour.

Why is streaming AI responses without saving a problem?

Streaming only to the client loses the generation if the user refreshes or switches devices. Write tokens to the database as they arrive or on completion, and store model name, token counts, and timestamps for cost tracking and debugging.