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.1.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.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gemconnect-1.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 54f49658af1436a5de137b14f34cf8780d2e4cad0129de0eb5ba145ca8ed0b8c
MD5 ff95daafc45f792efbdbc0369f147c53
BLAKE2b-256 d89d11d6d5c73311c8bc582e564ed6646f2325261e6381662a6df764ae7365c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemconnect-1.2.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: gemconnect-1.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d968dcec42d9000720a493f49d885e717f5475091773e44f973d525bfbaffc4
MD5 71d7c2a495c5a175112aad2db05b2809
BLAKE2b-256 8b4b1b2a8a00c196803b255bba77dc404f10b939e40dad094299a84e6e9afe63

See more details on using hashes here.

Provenance

The following attestation bundles were made for gemconnect-1.2.1-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