Skip to main content

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.json for 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-flash or gemini-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

  1. Visit Google AI Studio.
  2. Sign in with your Google account.
  3. Click Get API Key and then Create API Key.
  4. Copy the generated API key.

Step 2: Local Installation & Setup

  1. Clone or navigate to the project directory:

    cd gemini-chat-wrapper
    
  2. 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
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Create your .env file:

    cp .env.example .env
    

    Edit .env to 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

  1. 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
  2. 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)

  1. Install Vercel CLI:

    npm i -g vercel
    
  2. Deploy the project:

    vercel
    

    Follow the interactive prompts (select default settings).

  3. Add your Environment Variables on Vercel:

    vercel env add GEMINI_API_KEY
    
    • Enter your Gemini API key when prompted.
    • Select Production, Preview, and Development.

    (Optional) Configure the model name:

    vercel env add GEMINI_MODEL
    
    • Set value to gemini-2.5-flash.
  4. Deploy to Production:

    vercel --prod
    

Option B: Deploy via Vercel Dashboard (GitHub)

  1. Push this repository to GitHub.
  2. Go to Vercel Dashboard and click Add New Project.
  3. Import your GitHub repository.
  4. Under Environment Variables, add:
    • GEMINI_API_KEY: Your Gemini API Key from Google AI Studio.
    • GEMINI_MODEL (Optional): gemini-2.5-flash (or gemini-1.5-flash).
  5. Click Deploy.

🔗 Connecting the Terminal Client to Vercel

  1. Copy your deployed Vercel URL: Once deployment completes, Vercel gives you a URL such as: https://your-project.vercel.app

  2. Configure your Terminal Client: Set the BACKEND_URL environment variable:

    • Via .env file:
      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
      
  3. 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 .env locally (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)

Source distribution for gemini-ai-terminal 1.0.0
File Size Uploaded
gemini_ai_terminal-1.0.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-ai-terminal 1.0.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page