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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54f49658af1436a5de137b14f34cf8780d2e4cad0129de0eb5ba145ca8ed0b8c
|
|
| MD5 |
ff95daafc45f792efbdbc0369f147c53
|
|
| BLAKE2b-256 |
d89d11d6d5c73311c8bc582e564ed6646f2325261e6381662a6df764ae7365c0
|
Provenance
The following attestation bundles were made for gemconnect-1.2.1.tar.gz:
Publisher:
publish.yml on DIVICODER/gemconnect-lib-
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemconnect-1.2.1.tar.gz -
Subject digest:
54f49658af1436a5de137b14f34cf8780d2e4cad0129de0eb5ba145ca8ed0b8c - Sigstore transparency entry: 1484554089
- Sigstore integration time:
-
Permalink:
DIVICODER/gemconnect-lib-@5ac7e4bd525f591b6cc3986ed0915bbc7478b3b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DIVICODER
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ac7e4bd525f591b6cc3986ed0915bbc7478b3b7 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d968dcec42d9000720a493f49d885e717f5475091773e44f973d525bfbaffc4
|
|
| MD5 |
71d7c2a495c5a175112aad2db05b2809
|
|
| BLAKE2b-256 |
8b4b1b2a8a00c196803b255bba77dc404f10b939e40dad094299a84e6e9afe63
|
Provenance
The following attestation bundles were made for gemconnect-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on DIVICODER/gemconnect-lib-
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gemconnect-1.2.1-py3-none-any.whl -
Subject digest:
9d968dcec42d9000720a493f49d885e717f5475091773e44f973d525bfbaffc4 - Sigstore transparency entry: 1484554115
- Sigstore integration time:
-
Permalink:
DIVICODER/gemconnect-lib-@5ac7e4bd525f591b6cc3986ed0915bbc7478b3b7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DIVICODER
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ac7e4bd525f591b6cc3986ed0915bbc7478b3b7 -
Trigger Event:
push
-
Statement type: