A demonstration project for the Vercel AI SDK, showcasing how to build AI-powered applications with TypeScript and Node.js.
The Vercel AI SDK is a powerful library for building AI-powered applications. It provides a set of functions for:
- Generating text from language models (LLMs)
- Streaming responses for better UX
- Creating structured data from LLM outputs
- Tool calling and function execution
- Multi-modal capabilities
- Support for multiple AI providers (OpenAI, Anthropic, Google, etc.)
- Node.js (v22 or higher)
Install dependencies:
npm installCreate a .env file with your API keys:
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
GOOGLE_GENERATIVE_AI_API_KEY=your_google_key_here
This repo contains examples demonstrating Vercel AI SDK capabilities:
# Basic examples
npm run lesson_1 # Basic text generation (generateText)
npm run lesson_2 # Streaming text responses (streamText)
npm run lesson_3 # Usage tracking and token counting
# Advanced features
npm run lesson_4 # System prompts for controlling AI behavior
npm run lesson_5 # Structured output with Zod schemas (JSON output)
npm run lesson_6 # Tool calling with weather API integration
npm run lesson_7 # Working with multiple model providersHere's a simple example of using the Vercel AI SDK:
import { generateText } from 'ai';
import { google } from '@ai-sdk/google';
// Initialize the model
const model = google('gemini-1.5-flash');
// Generate text
const result = await generateText({
model,
prompt: 'Explain the Vercel AI SDK in one sentence',
});
console.log(result.text);- Language Models: Generate text using state-of-the-art LLMs
- Streaming: Real-time text generation with streaming responses
- Structured Data: Generate JSON and other structured outputs
- Tool Calling: Enable LLMs to call functions and use tools
- Provider Management: Use models from multiple AI providers
MIT