Level 1: AI SDK Basics — Briefing
The AI SDK is your toolkit for AI applications. In this level you’ll learn the fundamentals: generating text, streaming, structured output and system prompts. One API for all providers — Anthropic, OpenAI, Google and 20+ more.
Skill Tree
Section titled “Skill Tree”What You’ll Learn
Section titled “What You’ll Learn”- What the AI SDK is and how it’s structured — three libraries, one unified interface
- How to choose and configure an LLM model — provider system, model instances, switching providers
- Generating text with
generateText— the result object, usage tracking, finish reason - Streaming text with
streamText— real-time output, stream events,textStream - Structured output with
Output.object,Output.arrayandOutput.choice— typed JSON responses instead of free text - System prompts for role behavior — giving the LLM an identity and rules
Why This Matters
Section titled “Why This Matters”Every AI application builds on these fundamentals. Without them, you’re stuck copy-pasting from ChatGPT and can’t programmatically integrate AI into your projects.
The concrete problem: You want to integrate AI into your code, but every provider has a different API, different types, different error handling. The AI SDK solves this — one unified API for all providers. You’ll learn it here from the ground up.
Prerequisites
Section titled “Prerequisites”- Node.js 18+ and npm installed — check with
node -vandnpm -v - TypeScript basics — types, interfaces, async/await
- Experience with ChatGPT or similar — you know what an LLM is and what it can do
- An API key for at least one provider:
- Anthropic Console — create an API key under “API Keys” (recommended for this course)
- OpenAI Platform — create an API key under “API Keys”
- Google AI Studio — create an API key
All providers offer free starter credits or a free tier. For Level 1, a single API key is enough.
Before you start
Section titled “Before you start”Create a project directory for this level. Each challenge is saved as its own TypeScript file, and the Boss Fight combines everything into a final file.
mkdir level-1-ai-sdk && cd level-1-ai-sdknpm init -ynpm install ai @ai-sdk/anthropic zodnpm install -D tsx typescriptCreate a .env file for your API key (automatically loaded by tsx):
echo 'ANTHROPIC_API_KEY=sk-ant-your-key-here' > .envThis is how you run your TypeScript files:
npx tsx challenge-1-1.ts
tsxis a TypeScript runner that executes.tsfiles directly — notsconfig.json, no build step, with automatic.envsupport.
Troubleshooting
Section titled “Troubleshooting”- “API key not found” — Check that your
.envfile exists and the key is correct:cat .env - “Cannot use import statement” — Use
npx tsxinstead ofnodeto run files - “Module not found” — Check that all packages are installed:
npm ls ai @ai-sdk/anthropic zod
Skip hint: You already use the AI SDK daily and know
generateText,streamTextandOutput.object? Jump straight to the Boss Fight and test your knowledge.
Challenges
Section titled “Challenges”Boss Fight
Section titled “Boss Fight”Build a CLI chat: A terminal program that outputs text in real time with streamText and delivers structured JSON output with Output.object on request. You’ll combine all six building blocks of this level into one project.