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.2
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.2.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chatrelay-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / chatrelay-0.1.2.tar.gz
| Download URL | chatrelay-0.1.2.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0c7d83c68acebe462dcd81290b8d57c1d23592427ee58bdfe63ff4c4205e43b
|
|
BLAKE2b-256 checksum How to use checksums |
3fe3a4afaff370bd904ec86f73e59f547c687c9954d4f2750ac2ed52026c4752
|
| 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.2-py3-none-any.whl
| Download URL | chatrelay-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21cba6363f507e1a435cdf3a344ffd89e92c946a9345ab671f773f60aa0b2d0c
|
|
BLAKE2b-256 checksum How to use checksums |
de80b5cfb3bd657e7a41a89d19b57a012b25ab2f60f9af5d9fd5e079e105a080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.10
|