The Vercel AI SDK handles the messy parts — streaming, structured output parsing, tool calling.
Key Patterns
Streaming Structured Output: generateObject with Zod schemas gives type-safe structured data streaming token by token.
Multi-Model Routing: Simple classification to Haiku, conversation to Sonnet, complex reasoning to Opus.
Tool Calling: Functions the model can invoke mid-conversation — check calendars, book appointments, query databases.
Production Tips
- Always set maxTokens to prevent runaway generation
- Use onFinish callbacks for logging
- Implement retry with exponential backoff
- Cache repeated prompts at application layer