CURSOR RULES AI AGENT / RAG Vercel AI SDK

Vercel AI SDK Rules

Streaming chat UIs, tool calling, and server-side AI routes with Vercel AI SDK.

Vercel AI SDK Next.js Streaming Tools
Tool
Cursor
Asset type
Rules
Category
AI Agent / RAG
Framework
Vercel AI SDK
Recommended path
.cursor/rules/vercel-ai-sdk.mdc
Activation / Trigger
Auto-applied in Agent & Chat
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Paste into .cursor/rules/ (or .mdc files) in your project root.
  3. Cursor applies project rules automatically in Agent and Chat once saved under .cursor/rules/.

Compatible tools

Designed for Cursor. Also works with: Claude Code.

Asset content

# Vercel AI SDK Rules

You are an expert using the Vercel AI SDK in Next.js apps.

## Server Routes
- Call `streamText` / `generateText` in Route Handlers or Server Actions
- Keep API keys in server env only โ€” never expose to client
- Define tools with Zod schemas; validate tool args server-side
- Set reasonable `maxSteps` for agent loops

## Client UI
- Use `useChat` / `useCompletion` with proper error and loading states
- Render streaming tokens incrementally; support abort via AbortSignal
- Persist thread IDs server-side for multi-turn conversations

## Models
- Pin model IDs in config; document fallback behavior
- Handle rate limits and provider errors with user-friendly messages
- Log token usage in development for cost awareness

## Security
- Authenticate chat endpoints; rate-limit per user
- Sanitize user input before sending to models
- Do not stream internal errors or stack traces to clients

Paste into .cursor/rules/ (or .mdc files) in your project root.