Musashi API Deployment Guide
API_DEPLOYMENT_GUIDE.md
Musashi API Deployment Guide
Prerequisites
- Vercel Account: Sign up at vercel.com
- Vercel CLI: Install globally
bash npm install -g vercel
Local Development
1. Install Dependencies
cd "C:\Users\rotciv\Desktop\Musashi ai"
npm install2. Run API Locally
vercel devThis starts the API at http://localhost:3000
3. Test the API
curl -X POST http://localhost:3000/api/analyze-text \
-H "Content-Type: application/json" \
-d "{\"text\": \"Bitcoin just hit $100k!\"}"Or use the test script:
node test-api.jsDeploy to Vercel
Option 1: Vercel CLI (Recommended)
- Login to Vercel
bash vercel login
- Deploy
bash vercel --prod
- Note Your URL
Vercel will give you a URL like: https://musashi-api-[random].vercel.app
Option 2: GitHub Integration
- Push to GitHub
bash git init git add . git commit -m "Initial API deployment" git remote add origin https://github.com/rotciv/musashi.git git push -u origin main
- Connect to Vercel
- Go to vercel.com/new
- Import your GitHub repository
- Click "Deploy"
- Auto-Deploy on Push
- Every push to
mainwill auto-deploy - Preview deployments for branches
Configuration
Environment Variables
Create .env.local for local development:
MUSASHI_API_URL=http://localhost:3000For production, set in Vercel dashboard:
- Go to your project → Settings → Environment Variables
- Add:
MUSASHI_API_URL=https://your-deployed-url.vercel.app
Custom Domain (Optional)
- Go to Vercel project → Settings → Domains
- Add your custom domain (e.g.,
api.musashi.ai) - Update DNS records as instructed
Update Extension to Use Deployed API
1. Update API Client
Edit src/api/musashi-api-client.ts:
export const musashiApi = new MusashiApiClient(
'https://your-deployed-url.vercel.app' // Replace with your Vercel URL
);2. Rebuild Extension
npm run build3. Reload Extension
- Go to
chrome://extensions - Click reload icon on Musashi
- Refresh Twitter/X tab
Testing
Test API Endpoint
// test-api.js
const fetch = require('node-fetch');
async function testAPI() {
const response = await fetch('https://your-url.vercel.app/api/analyze-text', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: 'The Fed is cutting interest rates',
maxResults: 3
})
});
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
}
testAPI();Test Extension Integration
- Open Twitter/X
- Find a tweet about markets (e.g., "Bitcoin", "Fed rates", "Trump election")
- Check browser console for
[Musashi API]logs - Verify card appears under tweet
Monitoring
Vercel Analytics
- Go to your project → Analytics
- View:
- Request count
- Response times
- Error rates
- Geographic distribution
Logs
# Stream real-time logs
vercel logs --follow
# View recent errors
vercel logs --since 1hTroubleshooting
API Not Responding
- Check Vercel deployment status
- Verify endpoint URL is correct
- Check CORS headers in browser console
Extension Still Using Local Matcher
- Check console for
[Musashi API]vs[Musashi LOCAL] - Verify API URL in
musashi-api-client.ts - Rebuild extension:
npm run build - Reload extension in Chrome
High Latency
- Check Vercel region (should be close to users)
- Consider upgrading Vercel plan for better performance
- Implement caching in extension
CORS Errors
API already includes CORS headers. If errors persist:
- Check
api/analyze-text.tshas:
typescript res.setHeader('Access-Control-Allow-Origin', '*');
- Redeploy:
vercel --prod
Performance Optimization
1. Enable Caching
Add cache headers to API responses (future enhancement)
2. Rate Limiting
Implement Redis-based rate limiting (future)
3. CDN
Vercel automatically uses CDN for all endpoints
Cost Estimates
Vercel Free Tier:
- 100GB bandwidth/month
- ~100k requests/month
- Enough for MVP testing
Hobby Plan ($20/month):
- 1TB bandwidth
- ~1M requests/month
- Custom domains
Pro Plan ($50/month):
- 10TB bandwidth
- ~10M requests/month
- Team collaboration
Next Steps
- ✅ Deploy API to Vercel
- ✅ Update extension to use deployed URL
- [ ] Test with real Twitter usage
- [ ] Monitor performance and errors
- [ ] Add API key auth (Phase 2)
- [ ] Implement webhook subscriptions (Phase 2)
- [ ] Add real-time WebSocket stream (Phase 2)
Support
- Vercel Docs: https://vercel.com/docs
- Musashi GitHub: https://github.com/rotciv/musashi
- Vercel Discord: https://vercel.com/discord