Overview
Studley AI leverages Groq’s fast AI inference API to power all AI-driven features including:- Quiz generation
- Flashcard creation
- Study guide generation
- AI tutor chat
- Note-taking assistance
- Audio transcription
Groq API Setup
Create Groq Account
- Visit console.groq.com
- Sign up with email or GitHub
- Verify your email address
Generate API Key
- Navigate to API Keys in the dashboard
- Click Create API Key
- Name your key (e.g., “Studley AI Production”)
- Copy the key immediately (it won’t be shown again)
Add to Environment Variables
Add your Groq API key to For production (Vercel), add to environment variables in dashboard.
.env.local:Available AI Models
Studley AI uses different Groq models optimized for specific tasks:Primary Models
Main model for most AI features.Best for:
- Quiz generation
- Study guide creation
- General chat
- Context: 128k tokens
- Speed: ~300 tokens/sec
- Quality: High
Alternative versatile model for complex reasoning.Best for:
- Complex explanations
- Multi-step problems
- Detailed analysis
- Context: 128k tokens
- Speed: ~300 tokens/sec
Fast model for simpler tasks.Best for:
- Quick responses
- Simple Q&A
- Flashcard generation
- Context: 32k tokens
- Speed: ~500 tokens/sec
Audio transcription model.Best for:
- Lecture transcription
- Audio note processing
- Voice input
- Languages: 100+
- Quality: High accuracy
AI SDK Integration
Studley AI uses Vercel AI SDK for streamlined AI operations:Feature-Specific Configuration
Quiz Generation
app/api/generators/quiz/route.ts
Flashcard Generation
app/api/generators/flashcards/route.ts
AI Tutor Chat
app/api/ai-tutor/chat/route.ts
Audio Transcription
app/api/transcribe-audio/route.ts
Rate Limiting
Studley AI implements rate limiting to prevent abuse and manage API costs.Database-Based Rate Limiting
lib/rateLimit.ts
Apply Rate Limits
Recommended Rate Limits
Free Tier Users
Free Tier Users
Premium Users
Premium Users
Credit System
Studley AI uses a credit system to manage AI usage:Credit Costs
Check and Deduct Credits
app/actions.ts
Error Handling
Implement robust error handling for AI operations:Content Safety
Implement content moderation to ensure safe AI outputs:lib/policyCheck.ts
Performance Optimization
Response Streaming
Response Streaming
Use streaming for better UX:Users see responses as they’re generated, reducing perceived latency.
Prompt Caching
Prompt Caching
Cache common system prompts:
Token Optimization
Token Optimization
Limit tokens to reduce costs and latency:
Monitoring and Logging
Track AI usage for optimization:Troubleshooting
API key not found
API key not found
Error:
GROQ_API_KEY is undefinedSolutions:- Verify
GROQ_API_KEYis in.env.local - Check environment variable is set in Vercel dashboard
- Restart dev server after adding variable
- Ensure no typos in variable name
Rate limit errors
Rate limit errors
Error:
Rate limit exceededSolutions:- Check Groq dashboard for rate limits
- Implement request queuing
- Add user-facing rate limiting
- Consider upgrading Groq plan
Slow response times
Slow response times
Solutions:
- Use streaming responses
- Reduce
maxTokens - Switch to faster model (Mixtral)
- Optimize prompts for conciseness
Poor output quality
Poor output quality
Solutions:
- Adjust
temperature(0.7-0.9 for creativity) - Improve prompt engineering
- Use examples in prompts (few-shot)
- Switch to larger model (70B)
Groq Pricing
As of 2024, Groq offers competitive pricing:- Free Tier
- Pay-as-you-go
Limits:
- 14,400 requests/day
- 7,200,000 tokens/day
- Rate: 30 requests/minute
Next Steps
File Storage
Set up file uploads for documents
API Reference
View AI generation endpoints
Quiz Features
Learn about quiz generation
Credit System
Manage credits and usage