chatrelay
Chatbot library for Groq and Gemini. Give it multiple API keys; when one hits its rate limit it automatically switches to the next.
Install
pip install chatrelay
Setup
Set environment variables (comma-separated keys):
export GROQ_API_KEYS="groq_key_1,groq_key_2"
export GEMINI_API_KEYS="gemini_key_1,gemini_key_2"
Use in code
from chatrelay import Chatbot, build_providers
bot = Chatbot(build_providers(), system_prompt="You are a helpful assistant.")
result = bot.ask("What is Python?")
print(result["provider"], result["reply"]) # e.g. groq-1 ...
bot.ask("Explain more") # remembers the conversation
bot.ask("Hi", provider="gemini") # prefer a provider ("gemini") or one key ("groq-2")
bot.reset() # clear history
Terminal chat
pip install "chatrelay[cli]"
chatrelay "What is Python?" # one-shot: prints the answer and exits
chatrelay # interactive mode: /groq /gemini /auto /reset /quit
How failover works
Order: groq-1 -> groq-2 -> gemini-1 -> gemini-2. A key that returns HTTP 429 is skipped
for 60s (or the Retry-After time). If all keys fail, LLMError is raised.
REST API example
See examples/fastapi_app.py (pip install "chatrelay[api]").
Metadata
Release files for chatrelay 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chatrelay-0.1.1.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chatrelay-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / chatrelay-0.1.1.tar.gz
| Download URL | chatrelay-0.1.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f443615980c08fb5764b81d3e0bfa392592e9c5e9b44e6ccb2c86687fb5c41d8
|
|
BLAKE2b-256 checksum How to use checksums |
f4051f7cdcff7e00082ca17db51120943d7582e468a565452ea7af7f45d0cf18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.10
|
Release files / chatrelay-0.1.1-py3-none-any.whl
| Download URL | chatrelay-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9c9161e6761d7cea264b50c96f9a797c433be7737d3c07bd45ce6265a95fd7d
|
|
BLAKE2b-256 checksum How to use checksums |
34882c3bb8a71c2df11edc6534941acc4aff797c1d824dde8d7152f2118d2d7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.10
|