Skip to content
Development
Skill

/ai-orchestration-vercel-ai-sdk

Vercel AI SDK patterns - providers, text generation, streaming, structured output, tool calling, chat UI hooks, embeddings, and RAG

From plugin
skills
26200 skills

Claude Code

$ npx -y skills add agents-inc/skills --skill ai-orchestration-vercel-ai-sdk --agent claude-code

SKILL.md

ai-orchestration-vercel-ai-sdk.SKILL.md
name: ai-orchestration-vercel-ai-sdk
description: Vercel AI SDK patterns - providers, text generation, streaming, structured output, tool calling, chat UI hooks, embeddings, and RAG

Vercel AI SDK Patterns

> **Quick Guide:** Use Vercel AI SDK (v6) to build AI-powered applications with a unified provider API. Use `generateText`/`streamText` for text generation and streaming, `Output.object()`/`Output.array()` for structured data with Zod, `tool()` for function calling, and `useChat`/`useCompletion` hooks for React chat UIs. Supports OpenAI, Anthropic, Google, and 20+ providers through a single API.

---

<critical_requirements>

CRITICAL: Before Using This Skill

**(You MUST use the `ai` package (v6) with `Output.object()` / `Output.array()` for structured output -- NOT the deprecated `generateObject` / `streamObject` functions)**

**(You MUST define tool input schemas with `z.object()` and use `.describe()` on each property to help the model understand expected inputs)**

**(You MUST use `streamText` for user-facing responses to enable progressive rendering -- use `generateText` only for background/non-interactive tasks)**

**(You MUST handle streaming errors via `onError` callback -- streamText errors become part of the stream and are NOT thrown)**

**(You MUST use `inputSchema` (not `parameters`) when defining tools -- `parameters` was renamed in SDK v5+)**

</critical_requirements>

---

**Auto-detection:** AI SDK, Vercel AI, generateText, streamText, generateObject, streamObject, Output.object, Output.array, useChat, useCompletion, @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google, tool(), toolChoice, embedMany, embed, cosineSimilarity, ToolLoopAgent, smoothStream

**When to use:**

  • Building AI chat interfaces with streaming responses
  • Generating structured data (JSON objects, arrays) from LLMs with Zod schema validation
  • Implementing tool calling / function calling with LLMs
  • Creating multi-provider AI applications (OpenAI, Anthropic, Google, etc.)
  • Building RAG pipelines with embeddings and vector similarity
  • Adding AI text completion or generation to any TypeScript app

**Key patterns covered:**

  • Provider setup and model configuration (OpenAI, Anthropic, Google, custom)
  • Text generation (`generateText`) and streaming (`streamText`)
  • Structured output with Zod schemas (`Output.object`, `Output.array`, `Output.choice`)
  • Tool calling with `tool()`, multi-step execution, and approval flows
  • React hooks: `useChat` for chat UIs, `useCompletion` for text completion
  • Embeddings (`embed`, `embedMany`) and RAG patterns with `cosineSimilarity`

**When NOT to use:**

  • Simple static content that doesn't need AI generation
  • Server-side-only batch jobs where a direct provider SDK (e.g., `openai` npm package) is simpler
  • Image generation only (AI SDK supports it, but dedicated image SDKs may be more feature-rich)

**Detailed Resources:**

  • For provider setup, text generation, and error handling, see [examples/core.md](examples/core.md)
  • For chat UI patterns with useChat, see [examples/chat.md](examples/chat.md)
  • For tool definitions and multi-step calling, see [examples/tools.md](examples/tools.md)
  • For Zod-based structured output, see [examples/structured-output.md](examples/structured-output.md)
  • For embeddings and RAG, see [examples/rag.md](examples/rag.md)
  • For quick reference tables, see [reference.md](reference.md)

---

<philosophy>

Philosophy

The Vercel AI SDK provides a **unified TypeScript API** for building AI-powered applications across providers. Instead of learning each provider's unique SDK, you write one set of code that works with OpenAI, Anthropic, Google, and 20+ other providers.

**Core principles:**

1. **Provider agnostic** -- Switch models by changing a string, not rewriting code. The provider abstraction means `generateText({ model: 'openai/gpt-4o' })` and `generateText({ model: 'anthropic/claude-sonnet-4.5' })` use the same API. 2. **Streaming first** -- `streamText` starts delivering tokens immediately. Use it for all user-facing responses. `generateText` blocks until completion and is better for background tasks and agent loops. 3. **Type-safe structured output** -- Define Zod schemas and get validated, typed objects back from the model. Use `.describe()` on schema properties to guide the model. 4. **Tools as first-class citizens** -- Define tools with Zod input schemas and execute functions. The SDK handles the tool call loop, including multi-step execution and human approval. 5. **Framework-agnostic UI hooks** -- `useChat` and `useCompletion` work with React, Svelte, Vue, and Angular. They manage streaming state, message history, and input handling.

**When to use Vercel AI SDK:**

  • Multi-provider applications where you want to switch models easily
  • Streaming chat interfaces with React (or Svelte, Vue, Angular)
  • Structured data extraction from natural language
  • Agent-style applications with tool calling loops
  • RAG systems with embedding and retrieval

**When NOT to use:**

  • Single-provider scripts where the native SDK is simpler and has fewer dependencies
  • Extremely high-throughput batch processing (direct API calls avoid SDK overhead)
  • Non-TypeScript environments (the SDK is TypeScript-first)

</philosophy>

---

<patterns>

Core Patterns

Pattern 1: Provider Setup

Configure providers via direct imports (auto-reads env vars), custom instances, or AI Gateway. See [examples/core.md](examples/core.md) for full examples.

import { gateway } from "ai";
import { openai } from "@ai-sdk/openai";

// Gateway: provider/model string routing
const model = gateway("anthropic/claude-sonnet-4.5");

// Direct: auto-reads OPENAI_API_KEY from env
const openaiModel = openai("gpt-4o");

Use `customProvider` for semantic model aliases (`models('fast')`, `models('smart')`). Never hardcode API keys.

---

Pattern 2: Text Generation with generateText

Use `generateText` for non-interactive tasks. Returns a promi

Read more
@agents-inc
Ships withskills

The official skills marketplace for Agents Inc. 230+ skills covering everything from React and Prisma to Redis, ElevenLabs, and infrastructure tooling. Pick the skills that match your stack and install them via Claude Code. Need more control?

Stars on GitHub

Momentum

stars in total
26
Star history of agents-inc/skills on GitHub, a chart by star-history.com

Other skills on skills.

ai-infrastructure-litellm

ai-infrastructure-lite…

LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking,…

@agents-inc@agents-incInstall Skill
ai-infrastructure-modal

ai-infrastructure-moda…

Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client…

@agents-inc@agents-incInstall Skill
ai-infrastructure-ollama

ai-infrastructure-olla…

Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output,…

@agents-inc@agents-incInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react1d252k
@facebook@facebookInstall Skill

Questions about ai-orchestration-vercel-ai-sdk.

Which coding agents can use ai-orchestration-vercel-ai-sdk?
ai-orchestration-vercel-ai-sdk installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.