ai-sdk

Explain AI SDK functions like generateText, streamText, and embed.

Updated Jan 7, 2026
One-click install
npx skills add https://github.com/oneqmethod/next-payload-shadcn-starter-kit --skill ai-sdk-oneqmethod
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-sdk
Source: https://github.com/oneqmethod/next-payload-shadcn-starter-kit/tree/main/.claude/skills/ai-sdk
Command: npx skills add https://github.com/oneqmethod/next-payload-shadcn-starter-kit --skill ai-sdk-oneqmethod

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill provides focused guidance on using the AI SDK to build AI-powered features, reducing guesswork and onboarding time for developers.

Core Features & Use Cases

  • SDK guidance: explains functions like generateText, streamText, ToolLoopAgent, embed, and tools, with practical usage scenarios.
  • Agent and UI design: supports building chatbots, RAG systems, and AI-powered features using React hooks like useChat and useCompletion.
  • Best practices: covers provider selection (via the AI Gateway), streaming outputs, structured results, and safe tool invocation patterns.

Quick Start

Ask a concrete question about implementing a feature with the AI SDK, such as "How do I create a ToolLoopAgent that streams text with a weather tool using useChat?" or "What are the recommended steps to integrate generateText in a React app?"

Frequently Asked Questions about ai-sdk

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use generateText and streamText with the AI SDK in a React app?

To use generateText and streamText with the AI SDK, you call these functions on the server and connect them to the useChat React hook for streaming outputs. This pattern enables real-time text generation and structured results in your React app.

What is the best way to build a ToolLoopAgent that streams text using useChat?

Building a ToolLoopAgent with useChat involves defining tools and passing them to the agent function for safe tool invocation. The AI SDK handles the tool loop logic while streaming the intermediate and final text outputs directly to your chat interface.

How do I implement a RAG system using the embed function and AI Gateway?

Implementing a RAG system uses the embed function to generate vector representations of your documents via the AI Gateway. You then query these embeddings to retrieve relevant context and pass it to generateText for grounded AI responses.

Does the AI SDK support multiple providers through the AI Gateway?

Yes, the AI SDK supports multiple providers through the AI Gateway for provider selection. This allows you to switch between different language models seamlessly while maintaining consistent streaming outputs and structured results across your AI features.

Can I use useCompletion for structured results and streaming outputs?

You can use the useCompletion hook to handle streaming outputs and structured results from your model. It works alongside the AI SDK to manage completion states, ensuring safe tool invocation patterns and structured data handling in your UI.