A package to rotate Gemini API models based on rate limits.
Project description
Gemini Model Rotater
gemini-model-rotater is a Python package that rotates Gemini API models based on their rate limits. It loads model configurations from a JSON file and selects the best available model based on remaining quota. It also includes methods to increment usage after a request and swap models when rate limits are exceeded. The ranking of models determines the order in which they are selected. The package is useful for managing multiple models with different rate limits and selecting the best model for each request.
Installation
You can install the package via pip with the following command:
pip install gemini-model-rotater==1.0.0
Usage
from gemini_model_rotater import ModelManager
# Initialize with the JSON file containing your model configurations.
manager = ModelManager("models.json")
# Get the best available model.
model = manager.get_available_model()
if model:
print("Using model:", model.name)
# Perform your API call here.
manager.increment_request(model.name)
else:
print("No models available. Please wait for limits to reset.")
# If a 429 error occurs, swap to an alternative model.
alternative_model = manager.swap_model(model.name)
if alternative_model:
print("Swapped to model:", alternative_model.name)
else:
print("No alternative models available.")
Json File Format
[
{
"name": "model_A",
"requests_per_minute": 10,
"requests_per_day": 100,
"ranking": 1
},
{
"name": "model_B",
"requests_per_minute": 5,
"requests_per_day": 50,
"ranking": 2
}
]
3. LICENSE
MIT License
Copyright (c) 2025 Santosh Kanumuri
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 gemini-model-rotater-1.0.1.tar.gz.
File metadata
- Download URL: gemini-model-rotater-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42da97397bccae2e94350749a834b4e7aae3907ee6e6b8c145fdc4f0d7536d2c
|
|
| MD5 |
3a26dcead1a429ab89e8715db09678dc
|
|
| BLAKE2b-256 |
3cb7914f002f63fa851acca34e5fc517226611638d5a03a9d2f3705b42cf1a47
|
File details
Details for the file gemini_model_rotater-1.0.1-py3-none-any.whl.
File metadata
- Download URL: gemini_model_rotater-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2289a0f689943ded13f0933561076996c2a33b93f441b03f79fad1c628b6735a
|
|
| MD5 |
f4d43bdb324d8c094660e932f6841963
|
|
| BLAKE2b-256 |
140d3ddcd8189349e56f30b0f76468f44cbdae36f3d453630bb77055efce7936
|