Skip to content

A REST API backend built with Node.js and Express to interact with the Google Gemini large language model (LLM). Features include real-time data handling and API rate limiting.

Notifications You must be signed in to change notification settings

SuvojitDev/gemini-api-backend

Repository files navigation

Gemini AI REST API Backend

A REST API backend built with Node.js and Express to interact with the Google Gemini large language model (LLM).

Node.js Version License

🛠️ Built With

Node.js
Node.js
Express.js
Express.js
Gemini AI
Gemini AI

✨ Features

  • Direct Google Gemini Integration – Leverages Gemini's generative capabilities via official API.
  • Real-Time UTC Context – Injects live time/date data into prompts when needed.
  • API Rate Limiting – Uses express-rate-limit to prevent abuse.
  • Modular Structure – Clean separation of concerns (routes, controllers, services, middleware).

🧠 AI Model Used

This backend uses Google's gemini-1.5-flash – a fast, multimodal model ideal for low-latency, cost-effective tasks.

🚀 Getting Started

Follow these instructions to run the project locally.

✅ Prerequisites

  • Node.js (v18.x or newer)
  • NPM (comes with Node.js)
  • Google Gemini API Key from Google AI Studio

📦 Installation

  1. Clone the repository
git clone https://github.com/your-username/gemini-api-backend.git
cd gemini-api-backend
  1. Install dependencies
npm install
  1. Create environment file
Create a .env file in the root directory:
GEMINI_API_KEY=your_google_api_key_here
  1. Run the development server
npm run dev

📖 API Endpoint

POST /ask

Send a question to Gemini and receive a response.


🧾 Request Body

Send a JSON object containing a question field:

{
  "question": "What are the main benefits of using Node.js for a backend?"
}

✅ Response (200 OK)

A successful response returns a JSON object with the AI-generated answer:

{
  "answer": "Node.js is great for backends because it's non-blocking and event-driven, making it highly efficient for handling many simultaneous connections. Its large npm ecosystem provides free packages for almost any functionality you can imagine, and using JavaScript on both the front-end and back-end simplifies development."
}

📁 Project Structure

├── config/         # Environment variables & configuration
├── controllers/    # Request handling logic
├── middleware/     # Custom Express middlewares (rate limiting, etc.)
├── prompts/        # Base prompt templates
├── routes/         # API route definitions
├── services/       # External API integrations (Gemini)
└── server.js       # App entry point

👨‍💻 Author

Suvojit Modak

Connect with me

Twitter LinkedIn

About

A REST API backend built with Node.js and Express to interact with the Google Gemini large language model (LLM). Features include real-time data handling and API rate limiting.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published