wxdwu/new-api/ai-generation-persistence
Claude Code and agent skill by wxdwu/new-api
- community
Checking that the SKILL.md file is still in the repository.
AI generation persistence patterns — unique IDs, addressable URLs, database storage, and cost tracking for every LLM generation
Install
npx vskill@latest install wxdwu/new-api/ai-generation-persistenceSKILL.md
The same SKILL.md was published earlier as wxdwu/new-api/ai-generation-persistence.
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.
Core Rules
- Generate an ID before the LLM call — use
nanoid()orcreateId()from@paralleldrive/cuid2 - Persist every generation — text and metadata to database, images and files to Vercel Blob
- Make every generation addressable — URL pattern:
/chat/[id],/generate/[id],/image/[id] - Track metadata — model name, token usage, estimated cost, timestamp, user ID
- Never stream without saving — if the user refreshes, the generation must survive
Generate-Then-Redirect Pattern
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.
Persistence Schema
Storage Strategy
| 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 |
Image Persistence
Never serve generated images as ephemeral base64 or temporary URLs. Save to Blob immediately:
Cost Tracking
Extract usage from every generation and store it. This enables billing, budgeting, and abuse detection:
Prompt Dedup / Caching
Avoid paying for identical generations. Cache by content hash:
Anti-Patterns
- Streaming to client without saving — generation lost on page refresh. Always write to DB as tokens arrive or on completion.
- Routes without `[id]` segments —
/api/chatwith no ID means generations aren't addressable. Use/chat/[id]. - Re-generating identical prompts — check cache first. Same prompt + same model = same cost for no new value.
- Ephemeral base64 images — generated images served inline are lost when the component unmounts. Save to Vercel Blob.
- Missing metadata — always store model name, token counts, and timestamp. You need this for cost tracking and debugging.
- Client-only state — storing generations only in React state or localStorage. Use a database — generations must survive across devices and sessions.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/.tmp/plugins/plugins/vercel/skills/ai-generation-persistence/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wxdwu/new-api/ai-generation-persistence)