Skip to main content

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.

Metadata

Release files for gemini-model-rotater 1.0.1

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

Source distribution (sdist)

Source distribution for gemini-model-rotater 1.0.1
File Size Uploaded
gemini-model-rotater-1.0.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-model-rotater 1.0.1
File Interpreter ABI Platform
gemini_model_rotater-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / gemini-model-rotater-1.0.1.tar.gz

Download URL gemini-model-rotater-1.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
42da97397bccae2e94350749a834b4e7aae3907ee6e6b8c145fdc4f0d7536d2c
BLAKE2b-256 checksum
How to use checksums
3cb7914f002f63fa851acca34e5fc517226611638d5a03a9d2f3705b42cf1a47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / gemini_model_rotater-1.0.1-py3-none-any.whl

Download URL gemini_model_rotater-1.0.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2289a0f689943ded13f0933561076996c2a33b93f441b03f79fad1c628b6735a
BLAKE2b-256 checksum
How to use checksums
140d3ddcd8189349e56f30b0f76468f44cbdae36f3d453630bb77055efce7936
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

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