# ai-sdk

This Claude Code rule covers structured data generation with the Vercel AI SDK. It applies to TypeScript and TSX files.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 1120 repo stars
- Author: rerun-build
- License: AGPL-3.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/rerun-build/rerun/tree/HEAD/apps/ui/.cursor/rules/ai-sdk.mdc
- Updated: 2026-11-16
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/ai-sdk

## What it does

The rule steers Vercel AI SDK code toward `generateText` with an `Output` format, replacing the deprecated `generateObject` pattern. Zod schemas shape objects and arrays; `Output.choice()` selects from a fixed set, while `Output.json()` returns JSON without schema validation. Plain text uses `Output.text()`.

For streamed arrays, the rule demonstrates `elementStream`. Field descriptions with `.describe()` add context to schema properties, and the error example checks for `NoObjectGeneratedError`. It also covers structured output alongside tools. The file patterns are `**/*.ts` and `**/*.tsx`.

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/ai-sdk.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/ai-sdk.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/ai-sdk.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/ai-sdk.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/ai-sdk.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/rerun-build/rerun/tree/HEAD/apps/ui/.cursor/rules/ai-sdk.mdc

## When to use it
- replace `generateObject` with the current generation pattern
- define object or array output with a Zod schema
- consume array items as streaming completes
- classify text using a fixed set of labels

## Example prompts
- Rewrite this `generateObject` call using `generateText`, `Output.object()`, and a Zod schema.
- Show how to stream array items with `elementStream`.
- Classify this text with `Output.choice()` and the options positive, negative, and neutral.

## Similar
- [ai-sdk-6-skills](https://affpapa.org/en/nevibecode/skills/ai-sdk-6-skills.md) — skill · 484 installs
- [ai-sdk-expert](https://affpapa.org/en/nevibecode/agents/ai-sdk-expert.md) — subagent · ★ 763 repo stars
- [workflow](https://affpapa.org/en/nevibecode/skills/vercel-inc-workflow.md) — skill · 5500 installs
- [vercel-development](https://affpapa.org/en/nevibecode/skills/vercel-development.md) — skill · 756 installs
- [ai-sdk-6](https://affpapa.org/en/nevibecode/skills/ai-sdk-6.md) — skill · 218 installs
- [json-render](https://affpapa.org/en/nevibecode/skills/json-render.md) — skill · 4 installs

From the same set: [rerun-build/rerun](https://affpapa.org/en/nevibecode/by/rerun-build/rerun.md) — 25 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
