groq-rotator
A drop-in async Groq client that automatically rotates API keys when you hit rate limits. Useful when you have multiple free-tier Groq keys and don't want your pipeline to crash.
Install
pip install groq-rotator
Usage
Use it exactly like the normal AsyncGroq client:
import asyncio
from groq_rotator import AsyncRotatingGroq
client = AsyncRotatingGroq(api_keys=["key1", "key2", "key3"])
async def main():
response = await client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content)
asyncio.run(main())
That's it. No extra setup. If key1 hits a rate limit, it silently switches to key2 and retries.
Parallel requests (main use case)
import asyncio
from groq_rotator import AsyncRotatingGroq
client = AsyncRotatingGroq(api_keys=["key1", "key2", "key3"])
async def process(prompt: str):
response = await client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
async def main():
prompts = ["Summarize X", "Classify Y", "Extract Z"]
results = await asyncio.gather(*[process(p) for p in prompts])
print(results)
asyncio.run(main())
FastAPI
from fastapi import FastAPI
from groq_rotator import AsyncRotatingGroq
app = FastAPI()
client = AsyncRotatingGroq(api_keys=["key1", "key2", "key3"])
@app.post("/chat")
async def chat(prompt: str):
response = await client.chat.completions.create(
model="llama3-70b-8192",
messages=[{"role": "user", "content": prompt}]
)
return {"response": response.choices[0].message.content}
Optional: know when a key rotates
def on_rotate(index: int):
print(f"Switched to key index {index}")
client = AsyncRotatingGroq(api_keys=["key1", "key2"], on_rotate=on_rotate)
When is this useful?
- You have multiple free-tier Groq keys and want to maximize throughput
- You're running batch jobs or multi-agent pipelines with heavy Groq usage
- You're in a FastAPI or async backend and can't afford a crash on rate limit
- You want rotation to be invisible — no changes to how you write Groq code
When you don't need this
- You have a paid Groq key with high rate limits
- You're making one-off requests in a script
- You're not using async
Error handling
If all keys are rate limited, it raises groq.RateLimitError so you can handle it yourself:
from groq import RateLimitError
try:
response = await client.chat.completions.create(...)
except RateLimitError:
print("All keys exhausted")
Metadata
Release files for GroqAuto 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| groqauto-0.1.0.tar.gz | 2.6 kB | Without provenance | Details for groqauto-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| groqauto-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for groqauto-0.1.0-py3-none-any.whl |
Total release size: 5.4 kB
Release files / groqauto-0.1.0.tar.gz
| Download URL | groqauto-0.1.0.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f0c96c90125134f9b2487dd53c2db3c6fc41a9c9f46b1f6bb41265fb49dba61
|
|
BLAKE2b-256 checksum How to use checksums |
e300d715e06bde87238fc2803c70caadb3c2c9df3bcfaf52fbe30749e01dc6f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / groqauto-0.1.0-py3-none-any.whl
| Download URL | groqauto-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2bda3592352ca9d312ace8b36b05ecfc62751f8847be5cf1c1e511cdf26fde0
|
|
BLAKE2b-256 checksum How to use checksums |
a1d36f75be2a9156867568368b92776eb93aec2b75712f1381afce6006e6d0e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for GroqAuto 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.