Overview
GTM Feedback uses the Vercel AI SDK to power intelligent features like feedback analysis, semantic search, and automated workflows. The system supports multiple AI providers through AI Gateway with built-in development tools.AI SDK Integration
The AI package is located inpackages/ai/ and provides:
- Language Models - Pre-configured Claude and GPT models
- Embeddings - OpenAI text embeddings for semantic search
- Agents - Specialized AI agents for different tasks
- Tools - Structured tool calling for AI actions
Package Structure
Model Configuration
Models are configured inpackages/ai/src/models.ts with AI Gateway support:
packages/ai/src/models.ts
Models are wrapped with
wrapLanguageModel to enable middleware like DevTools in development.AI Gateway Setup
AI Gateway provides unified access to multiple AI providers with built-in caching, rate limiting, and observability.Environment Variables
Configure AI Gateway in your.env file:
Gateway Benefits
Multi-Provider
Switch between AI providers without code changes
Caching
Automatic response caching to reduce costs
Rate Limiting
Built-in rate limiting and retry logic
Observability
Track usage, costs, and performance
Model Selection Guide
When to Use Each Model
Claude Sonnet
Claude Sonnet
Best for:
- Complex feedback analysis
- Multi-step reasoning tasks
- Detailed content generation
- High-accuracy requirements
- Highest quality output
- Longer context window
- Higher cost per token
Claude Haiku
Claude Haiku
Best for:
- Real-time interactions
- Simple classification tasks
- Quick responses in Slack
- High-volume operations
- Fast response times
- Lower cost
- Good for straightforward tasks
GPT-4o Mini
GPT-4o Mini
Best for:
- Cost-sensitive operations
- Simple text generation
- Embeddings and search
- Batch processing
- Most cost-effective
- Good general performance
- OpenAI ecosystem integration
Using AI SDK in Your Code
Basic Text Generation
Streaming Responses
Structured Output with Zod
Tool Calling
AI SDK supports structured tool calling for AI-driven actions:Development Tools
In development mode, AI SDK DevTools provide visibility into AI operations:DevTools Features
- Request/Response Logging - See all AI interactions
- Token Usage Tracking - Monitor costs in real-time
- Performance Metrics - Measure latency and throughput
- Prompt Debugging - Iterate on prompts quickly
Cost Optimization
Best Practices
Choose the right model
Use Claude Haiku or GPT-4o Mini for simple tasks, reserve Sonnet for complex analysis.
Token Limits
Error Handling
Handle AI errors gracefully:Performance Tips
Parallel Requests
Process independent AI requests in parallel using
Promise.allTimeout Handling
Set reasonable timeouts for AI operations to prevent hanging requests
Retry Logic
Implement exponential backoff for transient failures
Monitoring
Track AI usage metrics to identify optimization opportunities
Related Resources
Vector Search
Use embeddings for semantic search
Slack Integration
Build AI-powered Slack workflows