Back to Browse

Make a Chatbot Using Gemini API

4.5K views
Oct 10, 2025
4:06

In this tutorial, I'll guide you through the steps of creating a simple chatbot using the Google Gemini API key, all within your terminal. Whether you're a beginner or just looking to explore chatbot development, this video will walk you through how to set up your environment, integrate the Gemini API, and create a functional chatbot that can respond to your inputs. By the end, you'll have your very own terminal-based chatbot up and running! commands :- npm install @google/generative-ai@latest code :- const { GoogleGenerativeAI } = require("@google/generative-ai"); const readlineSync = require("readline-sync"); // Initialize Gemini model with your API key const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || "your api key here"); const model = genAI.getGenerativeModel({ model: "models/gemini-2.5-flash" }); async function startChat() { console.log("🤖 Gemini Chatbot\nType 'exit' to quit.\n"); // ✅ Fix: Properly formatted chat history const chat = model.startChat({ history: [ { role: "user", parts: [{ text: "You are a helpful assistant chatbot." }], }, ], }); while (true) { const userInput = readlineSync.question("You: "); if (userInput.toLowerCase() === "exit") break; // Send user message const result = await chat.sendMessage(userInput); const response = result.response.text(); console.log(`Gemini: ${response}\n`); } } startChat();

Download

1 formats

Video Formats

360pmp45.1 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Make a Chatbot Using Gemini API | NatokHD