AI SDK Integration
Leveraging the Vercel AI SDK with Daydreams.
What is the Vercel AI SDK?
The Vercel AI SDK provides a unified way to connect to different AI providers like OpenAI, Anthropic, Google, and many others. Instead of learning each provider's unique API, you use one consistent interface.
Why This Matters for Your Agent
Daydreams is built on top of the Vercel AI SDK, which means you get:
Easy Provider Switching
Access to All Major Providers
- OpenAI - GPT-4, GPT-4o, GPT-3.5
- Anthropic - Claude 3 Opus, Sonnet, Haiku
- Google - Gemini Pro, Gemini Flash
- Groq - Ultra-fast Llama, Mixtral models
- OpenRouter - Access to 100+ models through one API
- And many more - See the full list
The Problem: Each AI Provider is Different
Without a unified SDK, you'd need different code for each provider:
The Solution: One Interface for All Providers
With the AI SDK, all providers work the same way:
Setting Up Your First Provider
1. Choose Your Provider
For this example, we'll use OpenAI, but the process is similar for all providers.
2. Install the Provider Package
3. Get Your API Key
- Go to OpenAI's API platform
- Create a new API key
- Add it to your environment:
4. Use in Your Agent
All Supported Providers
OpenAI
Get API key: platform.openai.com
Anthropic (Claude)
Get API key: console.anthropic.com
Google (Gemini)
Get API key: aistudio.google.com
Groq (Ultra-Fast)
Get API key: console.groq.com
OpenRouter (100+ Models)
Get API key: openrouter.ai
Switching Providers
The beauty of the AI SDK integration is how easy it is to switch:
Environment Variables
Set up your API keys in your .env
file:
The AI SDK automatically picks up the right environment variable for each provider.
Model Recommendations
For Development/Testing
- Groq Llama3-8B - Ultra-fast responses for quick iteration
- OpenAI GPT-4o-mini - Good balance of speed and capability
For Production
- OpenAI GPT-4o - Best overall capability and reliability
- Anthropic Claude-3-Sonnet - Great reasoning, good for complex tasks
For Cost Optimization
- OpenAI GPT-3.5-turbo - Cheapest OpenAI option
- Anthropic Claude-3-Haiku - Cheapest Anthropic option
- Google Gemini Flash - Very affordable with good performance
For Special Use Cases
- OpenRouter - Access models not available elsewhere
- Local models - Use Ollama for privacy
Advanced Configuration
You can also configure providers with custom settings:
Troubleshooting
Missing API Key
Solution: Make sure your environment variable is set and the process can access it.
Model Not Found
Solution: Check the AI SDK docs for available model names.
Rate Limits
Solution: Switch to a provider with higher limits or implement retry logic.
Next Steps
- Core Concepts - Learn how to build agents
- Your First Agent - Build a working example
- Vercel AI SDK Docs - Complete provider documentation
- Model Comparison - Compare different models' performance and cost
Key Takeaways
- One interface, many providers - Same code works with OpenAI, Anthropic, Google, etc.
- Easy switching - Change providers by changing one line of code
- Automatic key handling - Environment variables work automatically
- Cost flexibility - Use cheap models for development, premium for production
- Future-proof - New providers added to AI SDK work immediately with Daydreams
The AI SDK integration gives you the freedom to choose the best model for your use case without vendor lock-in.