Gemini AI Chatbot Wrapper
A lightweight, secure, and production-ready AI chatbot system featuring a FastAPI backend deployable as a serverless function on Vercel and an interactive Python terminal client.
Terminal Client
↓ HTTPS
Vercel Backend API (FastAPI)
↓
Gemini API (Google AI)
↓
Vercel Backend API
↓
Terminal Client
🌟 Key Features
- Secure Backend Architecture: The Gemini API key remains safely stored in the backend environment variables and is never exposed to the client.
- Vercel Serverless Ready: Pre-configured with
vercel.jsonfor one-command deployment to Vercel. - FastAPI Backend: Fast, robust, asynchronous request handling with strict Pydantic validation.
- Interactive Terminal Client: Clean CLI interface with session banners, continuous input, network error handling, and graceful exit (
exit/quit). - Free-Tier Compatible: Defaults to Google Gemini free-tier friendly models (e.g.,
gemini-2.5-flashorgemini-1.5-flash).
📁 Project Structure
gemini-chat-wrapper/
│
├── api/
│ └── chat.py # FastAPI serverless backend endpoint
│
├── client/
│ └── main.py # Interactive Python terminal client
│
├── requirements.txt # Python package dependencies
├── vercel.json # Vercel serverless deployment configuration
├── .env.example # Example environment variables template
├── .gitignore # Git ignore file (secures .env and artifacts)
└── README.md # Complete documentation and setup guide
🚀 Quick Start Guide
Step 1: Get a Gemini API Key
- Visit Google AI Studio.
- Sign in with your Google account.
- Click Get API Key and then Create API Key.
- Copy the generated API key.
Step 2: Local Installation & Setup
-
Clone or navigate to the project directory:
cd gemini-chat-wrapper
-
Create and activate a virtual environment (optional but recommended):
# On macOS/Linux python3 -m venv venv source venv/bin/activate # On Windows (PowerShell) python -m venv venv .\venv\Scripts\Activate.ps1
-
Install dependencies:
pip install -r requirements.txt
-
Create your
.envfile:cp .env.example .env
Edit
.envto include your Gemini API key:GEMINI_API_KEY=your_actual_gemini_api_key_here GEMINI_MODEL=gemini-2.5-flash BACKEND_URL=http://127.0.0.1:8000
Step 3: Run and Test Locally
-
Start the local FastAPI backend server:
uvicorn api.chat:app --reload --port 8000
- The API health check will be live at:
http://127.0.0.1:8000/api/chat - Interactive OpenAPI Docs at:
http://127.0.0.1:8000/docs
- The API health check will be live at:
-
In a new terminal window, start the terminal client:
python client/main.py
☁️ Deploying to Vercel
You can deploy the backend to Vercel in two ways: via the Vercel CLI or through the Vercel Web Dashboard (GitHub).
Option A: Deploy via Vercel CLI (Fastest)
-
Install Vercel CLI:
npm i -g vercel
-
Deploy the project:
vercel
Follow the interactive prompts (select default settings).
-
Add your Environment Variables on Vercel:
vercel env add GEMINI_API_KEY
- Enter your Gemini API key when prompted.
- Select
Production,Preview, andDevelopment.
(Optional) Configure the model name:
vercel env add GEMINI_MODEL
- Set value to
gemini-2.5-flash.
-
Deploy to Production:
vercel --prod
Option B: Deploy via Vercel Dashboard (GitHub)
- Push this repository to GitHub.
- Go to Vercel Dashboard and click Add New Project.
- Import your GitHub repository.
- Under Environment Variables, add:
GEMINI_API_KEY: Your Gemini API Key from Google AI Studio.GEMINI_MODEL(Optional):gemini-2.5-flash(orgemini-1.5-flash).
- Click Deploy.
🔗 Connecting the Terminal Client to Vercel
-
Copy your deployed Vercel URL: Once deployment completes, Vercel gives you a URL such as:
https://your-project.vercel.app -
Configure your Terminal Client: Set the
BACKEND_URLenvironment variable:- Via
.envfile:BACKEND_URL=https://your-project.vercel.app
- Or directly in your shell:
# Linux / macOS export BACKEND_URL="https://your-project.vercel.app" # Windows (PowerShell) $env:BACKEND_URL="https://your-project.vercel.app" # Windows (CMD) set BACKEND_URL=https://your-project.vercel.app
- Via
-
Launch the interactive terminal client:
python client/main.py
💬 Terminal Client Interface Example
╔════════════════════════════╗
║ GEMINI AI CLIENT ║
╚════════════════════════════╝
Connected to AI Server: https://your-project.vercel.app
Type 'exit' or 'quit' to leave the chat.
You > Hello
AI > Hello! How can I help you today?
You > Explain recursion in simple terms.
AI > Recursion is a programming technique where a function solves a problem by calling a smaller instance of itself until it reaches a base condition.
You > exit
Goodbye!
📡 API Specification
POST /api/chat
Request Body
{
"message": "What is artificial intelligence?"
}
Success Response (200 OK)
{
"response": "Artificial intelligence (AI) refers to computer systems capable of performing tasks that typically require human intelligence..."
}
Error Response (400 Bad Request / 500 Internal Server Error / 502 Bad Gateway)
{
"error": "Message cannot be empty."
}
🛡️ Security Best Practices
- Zero Client Secrets: The terminal client never touches or stores the Gemini API key.
- Environment Protection: Secrets are kept in
.envlocally (ignored in Git) and configured in Vercel's encrypted environment variable store. - Error Sanitization: Backend error handlers redact sensitive API tokens from error outputs.
📄 License
MIT License. Open source and free to use.
Release files for gemini-ai-terminal 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gemini_ai_terminal-1.0.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gemini_ai_terminal-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / gemini_ai_terminal-1.0.0.tar.gz
| Download URL | gemini_ai_terminal-1.0.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c018032022b898293927375b9ccfa70d316c79706c57e1c3f3605004865600e8
|
|
BLAKE2b-256 checksum How to use checksums |
2a99a79fd3a4cb366ab9de4223077bed27bb8c3ea1a0888a63744c4231baefeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / gemini_ai_terminal-1.0.0-py3-none-any.whl
| Download URL | gemini_ai_terminal-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5015531eaa34306aef350513424886ce719ba744b3aefad535d1db3ae9c2eefa
|
|
BLAKE2b-256 checksum How to use checksums |
4b9eafc6c255ebab6ac64c74d3ef9c7d0d0b2a42e4a23fe10c5804e8278cea0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|