Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini-model-rotater-1.0.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_model_rotater-1.0.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file gemini-model-rotater-1.0.0.tar.gz.

File metadata

  • Download URL: gemini-model-rotater-1.0.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for gemini-model-rotater-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9f86ca137a5b7cd77f3e9a4cbd4488d73568cd23d8fefa9b794ff2462f027498
MD5 6f3577a11fed3f5a37c28d6e469447e4
BLAKE2b-256 c49987b0eb30abeae10113bfceacbe59e72c9269bd07ea532eb26f4570878d45

See more details on using hashes here.

File details

Details for the file gemini_model_rotater-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_model_rotater-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d1bee226e7b672871b77ff683192a113292192658528e3dd9954a8ae2cdfa6
MD5 d37b59a6b4a10c42a94a8d83fc58f1f3
BLAKE2b-256 fa10b5f2125ac120289c9254b642dee84d01e318bfcdc763d6e03499c5715a27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page