vercel-ai-sdk

vercel-ai-sdk is a cursor rule for coding agents from nedcodes-ok/cursorrules-collection. It costs 654 tokens per session, scanned A, original, MIT.

A set of coding rules for the Vercel AI SDK, a JavaScript toolkit for building applications that use AI models. It covers streaming responses, tool calls, structured data, model providers, and chat-interface hooks.

In plain words
What is it for?
Use it when building AI chat interfaces, streamed responses, tool-calling workflows, structured results validated with schemas, or multi-step model interactions.
Why use it?
It provides consistent implementation patterns for common AI application features and helps avoid unsafe or error-prone handling of structured output and streaming.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/vercel-ai-sdk
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for vercel-ai-sdk

README.md
[![agentmods](https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/vercel-ai-sdk.svg)](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/vercel-ai-sdk)
Your own site
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/vercel-ai-sdk"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/vercel-ai-sdk.svg" alt="Measured on agentmods" height="20"></a>
Per session 654 This file is loaded in full into every session.
When invoked 654 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00654 $0.00654
Opus 5 $0.00327 $0.00327
Sonnet 5 $0.00131 $0.00131
Haiku 4.5 $0.00065 $0.00065

Measured yesterday against content hash 6b969dee361a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

vercel-ai-sdk scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules-mdc/tools/vercel-ai-sdk.mdc · 58 lines

How it starts

The opening of the file, as written. The whole thing — 58 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Vercel AI SDK Cursor Rules

You are an expert in the Vercel AI SDK (ai package). Follow these rules:

Core Patterns

  • Use generateText for single completions, streamText for streaming responses
  • Use generateObject with Zod schemas for structured output, never parse JSON manually
  • Prefer streamObject when showing structured data progressively
  • Always specify the model with provider prefix: openai('gpt-4o'), anthropic('claude-sonnet-4-20250514')
  • Use the unified provider interface, not provider-specific SDKs directly

Streaming

  • Use useChat hook for chat UIs, useCompletion for single-turn completions
  • Always handle the error state from hooks, not just isLoading
  • Set maxSteps on useChat when using multi-step tool calls
  • Use onFinish callback for logging/persistence, not useEffect watching messages
  • Stream responses with toDataStreamResponse() in API routes, not manual SSE

Tool Calling

  • Define tools with tool() helper including Zod parameter schemas and execute functions
  • Keep tool descriptions clear and specific, they are the prompt for the model
  • Use maxSteps to allow multi-step tool use (model calls tool, gets result, continues)
  • Handle tool call errors gracefully with try/catch inside execute functions
  • Return structured data from tools, not formatted strings

Structured Output

  • Always use Zod schemas with generateObject/streamObject
  • Set mode: 'json' for models that support native JSON mode
  • Use schemaDescription to help the model understand the output shape
  • Prefer enums and literals over free-form strings in schemas
  • Validate output even with structured generation, models can still produce edge cases

API Routes

  • Use streamText + toDataStreamResponse() in Next.js route handlers
  • Pass messages from the request body, validate array is non-empty
  • Set appropriate maxTokens to control costs, don't rely on model defaults
  • Use system parameter for system prompts, not as the first message
  • Handle rate limits and API errors with proper HTTP status codes

Read the full file on GitHub · 58 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 58 lines · 654 tokens per session scan A 6b969dee361a

Subscribe to this mod's changes

vercel-ai-sdk is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 654 tokens to every session, about $0.0033 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.