Skip to main content

gemconnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong translates the scary technical error into a simple message the beginner can understand and fix.

Project description

GemConnect

GemConnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong, translates the scary technical error into a simple message the beginner can understand and fix.


The Problem

As an engineer, it felt fascinating to connect upcoming trends like AI into a website and see it work. Getting Gemini to respond in the terminal felt exciting. But when I tried to connect it with the frontend, it once again felt like zero.

Errors kept coming when interconnecting the frontend with Flask. Initially I tried to debug on my own, but it reached a threshold where I shifted from being curious and excited to a mood of just finishing what I had started. I kept copy-pasting the error to an AI bot to debug. Sometimes it worked, sometimes it didn't. But whether it worked or not, I hadn't been able to debug the error myself.

The errors were in technical terms like "404" โ€” like these types of numbers. And in some cases it would show a scary list of errors and say "JSON error" like that, making it difficult to understand what went wrong and where.

What I needed was an error document to understand each error. That problem led to the creation of this library.


What GemConnect Does

GemConnect gets the scary error and converts it into a human-understandable message for easy debugging.

WITHOUT GemConnect:
Flask โ†’ Gemini โ†’ ๐Ÿ˜ต Scary JSON error dump โ†’ Beginner gives up

WITH GemConnect:
Flask โ†’ GemConnect โ†’ Gemini โ†’ โŒ Error?
                                    โ†“
                        "Hey! Your API key looks wrong.
                         Go to aistudio.google.com/apikey and get a fresh one."

Who Is This For

Beginners who are really interested in frontend connectivity with AI services but get scared seeing those errors and not knowing how to solve them.


Requirements

Before using GemConnect, install the Gemini package:

pip install google-genai

GemConnect itself has zero dependencies. You are responsible for creating and passing the Gemini client.


Installation

pip install gemconnect

How To Use

from google import genai
from gemconnect import ask_gemini

# you bring your own client
client = genai.Client(api_key="YOUR_API_KEY")

# one line to call Gemini safely
result = ask_gemini("What is Python?", client, "gemini-2.5-flash")
print(result)

Input Validation

GemConnect checks your inputs before even calling Gemini. If something is wrong it tells you immediately in plain English:

ask_gemini(None, client, model)
# โ†’ "Your prompt is None. Please pass a text string like ask_gemini('hello', client, model)."

ask_gemini("", client, model)
# โ†’ "Your prompt is empty. Please type something before sending."

ask_gemini(["hello"], client, model)
# โ†’ "Your prompt must be plain text. You passed a list instead of a string."

ask_gemini(prompt, None, model)
# โ†’ "Your Gemini client is None. Make sure you created it using genai.Client(api_key=...)."

ask_gemini(prompt, client, None)
# โ†’ "You forgot to pass a model name. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."

ask_gemini(prompt, client, "")
# โ†’ "Your model name is empty. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."

How It Works Inside

User writes ask_gemini()
        โ†“
connector.py runs input checks
        โ†“
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                         โ”‚
  checks pass               checks fail
        โ”‚                         โ”‚
        โ†“                         โ†“
  calls Gemini API        friendly message
        โ”‚                  returned to user
        โ†“
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚             โ”‚
SUCCESS       ERROR
  โ”‚             โ”‚
  โ†“             โ†“
response.text  errors.py
  โ”‚             โ”‚
  โ†“             โ†“ Layer 1 โ€” keyword match
returned      errors.py
to user        โ”‚
               โ†“ Layer 2 โ€” synonym match
               โ”‚
               โ†“
         simple message
         returned to user

Real Project Example โ€” Chatbot

# BEFORE GemConnect โ€” scary errors possible
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=conversation
)
ai_reply = response.text


# AFTER GemConnect โ€” one line, errors handled
from gemconnect import ask_gemini

ai_reply = ask_gemini(conversation, client, "gemini-2.5-flash")

What Errors GemConnect Covers

Every error message inside GemConnect was collected from real beginner projects. Two layers of matching make sure as many errors as possible are caught.

Setup Errors

โŒ jinja2.exceptions.TemplateNotFound
โœ… Flask cannot find your HTML file. Make sure your HTML file is inside 
   a folder named exactly 'templates' (no capital letters, no spaces).

โŒ ERR_CONNECTION_REFUSED
โœ… Your Flask server is not running. Go to your terminal and run your 
   app.py file first, then try again.

โŒ FutureWarning: google.generativeai has ended
โœ… Your Gemini package is old. Open your terminal and run: 
   pip install --upgrade google-generativeai

Install Errors

โŒ ModuleNotFoundError: No module named 'google.generativeai'
โœ… A required package is not installed. Open your terminal and run: 
   pip install google-generativeai

API Key Errors

โŒ 401 Unauthorized
โœ… Gemini does not recognize you. Your API key is either wrong, expired, 
   or missing. Go to aistudio.google.com/apikey and get a fresh one.

โŒ API key not valid. Please pass a valid API key.
โœ… Your API key is wrong. Go to aistudio.google.com/apikey, copy your 
   key again and paste it carefully โ€” even one wrong character breaks it.

Quota Errors

โŒ RESOURCE_EXHAUSTED
โœ… You have used up all your free Gemini quota. Go to 
   aistudio.google.com/apikey, create a brand new project and generate 
   a new API key from there.

โŒ 429 Too Many Requests
โœ… You sent too many requests too fast. Wait 30-60 seconds and try again.

Model Errors

โŒ 404 models/gemini-1.5-flash is not found
โœ… The model name you typed does not exist. Run list_models() to see the 
   exact names and copy-paste one of those.

Gemini Server Errors

โŒ InternalServerError
โœ… Something crashed on Gemini's side โ€” this is not your fault. 
   Wait a minute and try the exact same request again.

โŒ 503 UNAVAILABLE
โœ… Too many people are using Gemini right now. Wait a few minutes and try again.

โŒ 504 Timeout
โœ… Gemini took too long to reply. Wait a moment and try again.

Network Errors

โŒ ConnectionError
โœ… Could not reach Gemini. Check your internet connection and try again.

โŒ SSLError
โœ… A secure connection to Gemini failed. Check your internet or try a 
   different network.

Frontend Errors

โŒ blocked by CORS policy
โœ… Your browser is blocking the request because your frontend and backend 
   are on different ports. Install flask-cors and add CORS(app) to your Flask file.

โŒ SyntaxError: Unexpected token
โœ… Your Flask server crashed and sent back an error page instead of data. 
   Check your terminal โ€” the real error is printed there.

Check Available Models

Not sure which model to use? Run this:

from google import genai
from gemconnect import list_models

client = genai.Client(api_key="YOUR_API_KEY")
list_models(client)

This prints all models your API key can access.


What GemConnect Supports โ€” v1.0

Works with:
โœ… PDF Summarizer      (extract text first, pass as string)
โœ… Chatbot             (conversation as plain string)
โœ… Text Summarizer     (plain text input)
โœ… CSV Analyzer        (convert to string with df.to_string())
โœ… Any project where input to Gemini is plain text

Coming in v2.0:
๐Ÿ”œ Image support
๐Ÿ”œ Audio support
๐Ÿ”œ Video support

Check Version

import gemconnect
print(gemconnect.__version__)

Built From Real Mistakes

This library was not built from assumptions. Every error message inside GemConnect was collected from real beginner projects โ€” PDF summarizer, chatbot, image describer, audio transcriber. Each scary error was faced, documented, and translated into a simple message.

GemConnect v1.0 โ€” Built from real beginner mistakes, for real beginners.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemconnect-1.2.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemconnect-1.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file gemconnect-1.2.0.tar.gz.

File metadata

  • Download URL: gemconnect-1.2.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gemconnect-1.2.0.tar.gz
Algorithm Hash digest
SHA256 192049ffe98ce78122bf087a9718f2f31e94b3852bd48cd58dd372160fbb9d70
MD5 3c86e16c54f4dbe3f13f68ac5dfb8e9b
BLAKE2b-256 4aea7a7d04ee98113d2c30f4c7044fb363410a00b662fb7c25060d4c0e8e23d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemconnect-1.2.0.tar.gz:

Publisher: publish.yml on DIVICODER/gemconnect-lib-

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gemconnect-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: gemconnect-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gemconnect-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2087c47f106cf401c606fe826d131c5b75d97204388f13e55238a452f7f6cecc
MD5 97ba47c74e9ae74b61456f10b816d1ad
BLAKE2b-256 f14efb1bf590a0cc7a35dcb95bbe505afb6f669f7fe384241c9e9997b1437a74

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemconnect-1.2.0-py3-none-any.whl:

Publisher: publish.yml on DIVICODER/gemconnect-lib-

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page