AI Assistant in a Management Panel: Gemini API + Dynamic System Prompt from Firebase A developer integrated an AI chat panel into PanelControl, an internal management tool, using the Google Gemini API with a dynamic system prompt built from live Firebase data. The system answers repetitive business questions about orders, operators, leads, and bonuses by passing real-time context and a hardcoded knowledge base to the model via vanilla JavaScript. The developer encountered model availability issues and recommends verifying model names against the official documentation before integration. I integrated an AI chat panel directly into PanelControl , the internal commercial team management tool I maintain. No external libraries, no framework: a fetch call to the Gemini API with a system prompt built dynamically from live Firebase data — orders, operators, leads, bonuses — plus a static company knowledge base hardcoded in the prompt itself. All in vanilla JavaScript. PanelControl is the internal management panel used by the commercial team to track orders, leads, activations and monthly bonuses. All data lives in Firebase Realtime Database. The team asks the same repetitive questions every day: who sold the most this month? How many activations are missing to reach the bonus threshold? How does procedure X work? The idea was to add a ✦ Ask AI button that opens a conversation panel — same glassmorphism style already present in the panel — responding with full awareness of the business context and the current month's live data. The key technical point: an AI model knows nothing about your management panel. You have to build the context and pass it with every question in the system prompt. This article documents how that was done, including the API selection process and Gemini model versioning issues. The first evaluation was which API to use. The two main options were: Google Gemini API via generativelanguage.googleapis.com and Anthropic API via api.anthropic.com . | Gemini API | Anthropic API | | |---|---|---| | Free tier | Yes generous | No | | Billing required | Yes card on file, not charged | Yes | | REST call | fetch POST | fetch POST | | Response path | candidates 0 .content.parts 0 .text | content 0 .text | The choice fell on Gemini for the more generous free tier for light internal use a few dozen questions per day . An important note: Google Cloud requires a billing account even to use the free plan, but adding a card incurs no charges as long as you stay within the free tier. The Gemini API is called with a simple fetch POST. The request body contains the prompt in the contents field. The response comes back in candidates 0 .content.parts 0 .text . js async function askGemini userMessage, systemPrompt { const GEMINI KEY = ' GEMINI API KEY '; const MODEL = 'gemini-2.5-flash-lite'; const ENDPOINT = https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent?key=${GEMINI KEY} ; const response = await fetch ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify { system instruction: { parts: { text: systemPrompt } }, contents: { parts: { text: userMessage } } } } ; const data = await response.json ; // Handle model unavailability error if response.ok { const msg = data?.error?.message || 'API Error'; throw new Error msg ; } return data.candidates 0 .content.parts 0 .text; } The first obstacle wasn't technical, but one of availability . Gemini deprecates models quickly for new accounts. The error sequence I encountered: gemini-2.0-flash → gemini-2.0-flash-lite → same error gemini-2.5-flash-lite → ✅ working, free tier activeThe lesson: don't trust a hardcoded model name from a tutorial. Before integrating, always verify on ai.google.dev/gemini-api/docs/models https://ai.google.dev/gemini-api/docs/models which models are available for your account and plan. The API key format matters too: Gemini keys always start with AIzaSy , not other prefixes. The ✦ Ask AI button is positioned above the existing chat button in the management panel, with a green/teal gradient to visually distinguish it from the chat's blue. On click it opens a side panel with the same glassmorphism aesthetic as the rest of the interface. php < -- Trigger button --