
I'm sharing the AI integration strategy I use on my portfolio site. The system automatically switches between different AI providers like Google Gemini and Groq, intelligently manages quota limits, and rotates between 20+ different models.
1export async function sendMessageWithFailover(message: string, history: any[]) {
2 for (const model of GEMINI_MODELS) {
3 try {
4 const res = await tryGemini(model, message, history);
5 if (res) return { reply: res, provider: 'Google Gemini' };
6 } catch (err) { if (err.status === 429) continue; }
7 }
8 for (const model of GROQ_MODELS) {
9 try {
10 const res = await tryGroq(model, message, history);
11 if (res) return { reply: res, provider: 'Groq' };
12 } catch (err) {}
13 }
14}