Skip to main content
ClaudeWave
Skill169 repo starsupdated 29d ago

ai-sdk-core

Vercel AI SDK v5 for backend AI (text generation, structured output, tools, agents). Multi-provider. Use for server-side AI or encountering AI_APICallError, AI_NoObjectGeneratedError, streaming failures.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/secondsky/claude-skills /tmp/ai-sdk-core && cp -r /tmp/ai-sdk-core/plugins/ai-sdk-core/skills/ai-sdk-core ~/.claude/skills/ai-sdk-core
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# AI SDK Core

Production-ready backend AI with Vercel AI SDK v5.

**Last Updated**: 2025-11-21

## Table of Contents
1. [Quick Start](#quick-start-5-minutes)
2. [Core Functions](#core-functions)
3. [Provider Setup & Configuration](#provider-setup--configuration)
4. [Tool Calling & Agents](#tool-calling--agents)
5. [Critical v4→v5 Migration](#critical-v4v5-migration)
6. [Top 12 Errors & Solutions](#top-12-errors--solutions)
7. [Production Best Practices](#production-best-practices)
8. [When to Load References](#when-to-load-references)
9. [When to Use This Skill](#when-to-use-this-skill)
10. [Dependencies & Versions](#dependencies--versions)
11. [Links to Official Documentation](#links-to-official-documentation)
12. [Templates & References](#templates--references)

---

## Quick Start (5 Minutes)

### Installation

```bash
bun add ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google workers-ai-provider zod  # preferred
# or: npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google workers-ai-provider zod
```

### Environment Variables

```bash
# .env
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_GENERATIVE_AI_API_KEY=...
```

### First Example: Generate Text

```typescript
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const result = await generateText({
  model: openai('gpt-4-turbo'),
  prompt: 'What is TypeScript?',
});

console.log(result.text);
```

### First Example: Streaming Chat

```typescript
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';

const stream = streamText({
  model: anthropic('claude-sonnet-4-5-20250929'),
  messages: [
    { role: 'user', content: 'Tell me a story' },
  ],
});

for await (const chunk of stream.textStream) {
  process.stdout.write(chunk);
}
```

### First Example: Structured Output

```typescript
import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const result = await generateObject({
  model: openai('gpt-4'),
  schema: z.object({
    name: z.string(),
    age: z.number(),
    skills: z.array(z.string()),
  }),
  prompt: 'Generate a person profile for a software engineer',
});

console.log(result.object);
// { name: "Alice", age: 28, skills: ["TypeScript", "React"] }
```

## Secure Installation

This installs 6+ AI provider packages simultaneously — a large dependency surface to audit. Before installing, follow supply chain security best practices:

- **Block post-install scripts** — `npm config set ignore-scripts true` (or Bun: disabled by default)
- **Cooldown period** — Wait 7 days for new package versions to be vetted by the community
- **Audit before installing** — Run `socket package score npm <pkg>` or use `socket npm install <pkg>` to check packages

Load the `dependency-upgrade` skill for full security configuration including Socket CLI integration, cooldown setup, lockfile validation, and CI enforcement.

---

## Core Functions

**Load `references/core-functions.md` for complete API reference** of all 4 core functions.

### Quick Overview

AI SDK v5 provides 4 core functions:

| Function | Output | Streaming | Use Case |
|----------|--------|-----------|----------|
| `generateText()` | Text | No | Batch processing, simple completions |
| `streamText()` | Text | Yes | Chat UIs, long responses |
| `generateObject()` | Structured | No | Data extraction, JSON generation |
| `streamObject()` | Structured | Yes | Real-time forms, progressive UIs |

### Basic Example

```typescript
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const result = await generateText({
  model: openai('gpt-4-turbo'),
  prompt: 'Explain quantum computing',
});

console.log(result.text);
```

**→ Load `references/core-functions.md` for:** Complete signatures, tool usage patterns, error handling, streaming examples, comparison table

---

## Provider Setup & Configuration

**Load `references/provider-setup.md` for complete setup instructions** for all providers.

### Quick Overview

AI SDK v5 supports 4 major providers:

| Provider | Environment Variable | Latest Models |
|----------|---------------------|---------------|
| OpenAI | `OPENAI_API_KEY` | GPT-5, GPT-4 Turbo |
| Anthropic | `ANTHROPIC_API_KEY` | Claude Sonnet 4.5, Opus 4 |
| Google | `GOOGLE_GENERATIVE_AI_API_KEY` | Gemini 2.5 Pro/Flash |
| Cloudflare | Workers AI binding | Llama 3.1, Qwen 2.5 |

### Basic Setup

```typescript
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';

// API key from environment
const result = await generateText({
  model: openai('gpt-4-turbo'),
  prompt: 'Hello',
});
```

**→ Load `references/provider-setup.md` for:** Complete API configuration, rate limiting, error handling, Cloudflare Workers optimization, model selection guides

---

## Tool Calling & Agents

**Load `references/tools-and-agents.md` for complete tool and agent documentation**.

### Quick Overview

Tools allow models to call external functions. Agents manage multi-step workflows.

**v5 Tool Changes:**
- `parameters` → `inputSchema` (Zod schema)
- Tool properties: `args` → `input`, `result` → `output`
- `maxSteps` → `stopWhen(stepCountIs(n))`

### Basic Tool Example

```typescript
import { generateText, tool } from 'ai';
import { z } from 'zod';

const result = await generateText({
  model: openai('gpt-4'),
  tools: {
    weather: tool({
      description: 'Get weather for a location',
      inputSchema: z.object({ location: z.string() }),
      execute: async ({ location }) => {
        return { temperature: 72, condition: 'sunny' };
      },
    }),
  },
  prompt: 'What is the weather in Tokyo?',
});
```

**→ Load `references/tools-and-agents.md` for:** Agent class usage, multi-step execution, dynamic tools, stop conditions

---

## Critical v4→v5 Migration

**Load `references/v4-to-v5-migration.md` for complete migration guide**.

### Key Breaking Changes

AI SDK v5 has 9 major breaking changes:
- `maxTokens` → `maxOutputTokens`
- `p
access-control-rbacSkill

Role-based access control (RBAC) with permissions and policies. Use for admin dashboards, enterprise access, multi-tenant apps, fine-grained authorization, or encountering permission hierarchies, role inheritance, policy conflicts.

aceternity-uiSkill

100+ animated React components (Aceternity UI) for Next.js with Tailwind. Use for hero sections, parallax, 3D effects, or encountering animation, shadcn CLI integration errors.

ai-elements-chatbotSkill

shadcn/ui AI chat components for conversational interfaces. Use for streaming chat, tool/function displays, reasoning visualization, or encountering Next.js App Router setup, Tailwind v4 integration, AI SDK v5 migration errors.

ai-sdk-uiSkill

Vercel AI SDK v5 React hooks (useChat, useCompletion, useObject) for AI chat interfaces. Use for React/Next.js AI apps or encountering parse stream errors, no response, streaming issues.

api-authenticationSkill

Secure API authentication with JWT, OAuth 2.0, API keys. Use for authentication systems, third-party integrations, service-to-service communication, or encountering token management, security headers, auth flow errors.

api-changelog-versioningSkill

Creates comprehensive API changelogs documenting breaking changes, deprecations, and migration strategies for API consumers. Use when managing API versions, communicating breaking changes, or creating upgrade guides.

api-contract-testingSkill

Verifies API contracts between services using consumer-driven contracts, schema validation, and tools like Pact. Use when testing microservices communication, preventing breaking changes, or validating OpenAPI specifications.

api-design-principlesSkill

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.