Skip to main content

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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatrelay 0.1.3
File Size Uploaded
chatrelay-0.1.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chatrelay 0.1.3
File Interpreter ABI Platform
chatrelay-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / chatrelay-0.1.3.tar.gz

Download URL chatrelay-0.1.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
400063f301a1499062dbb83e9a77d31e635776f08ce304058d8d20fec7d23471
BLAKE2b-256 checksum
How to use checksums
91e4c21e599f88c44ded6f19159f978a3fb8fdaab48a34e824f62125b00356a5
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.3-py3-none-any.whl

Download URL chatrelay-0.1.3-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcc91177b54252c8ae59b0381eb8137abc5b6a5ee7a085377e41b116077d0015
BLAKE2b-256 checksum
How to use checksums
ba1187be86943ebd02e8a0ac0e27a61da81a6826538a1ae11696f6b07678eb3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.10

Release history Release notifications | RSS feed

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page