Skip to main content

Always uses the most lazy key when calling an online LLM.

Project description

(definitely not ai generated generic project description that will be updated in the future)

Lazy Key is a Python-based utility designed to efficiently manage multiple API keys while ensuring optimal usage and load balancing. Built with asyncio, the system dynamically selects the best available key based on predefined rate-limiting metrics such as tokens per minute (TPM) and requests per second (RPS).

Key Features
✅ Asynchronous API Requests – Uses asyncio to handle API calls concurrently, improving performance.
✅ Smart Key Selection – Dynamically picks the API key with the lowest usage based on live metrics.
✅ Rate Limit Awareness – Supports selection methods like TPM and RPS to maximize key efficiency.
✅ Parallel Metric Evaluation – Uses asyncio.gather() to fetch usage data from all keys simultaneously.
✅ Flexible and Scalable – Easily extendable to support additional rate-limiting strategies and APIs such as OpenAI, Groq, or any custom online LLM API.\

Quickstart

Sync version

from lazykey import KeyHandler
from groq import Groq

api_keys = ["API_KEY_1", "API_KEY_2"]
client = Groq

api = KeyHandler(api_keys, client)

completion = api.request(
    messages=[
        {
            "role": "user",
            "content": "Cats or dogs?",
        }
    ],
    model="llama-3.3-70b-versatile",
)

Async version:

from lazykey import AsyncKeyHandler
from groq import AsyncGroq

api_keys = ["API_KEY_1", "API_KEY_2"]
client = AsyncGroq

api = AsyncKeyHandler(api_keys, client)

completion = await api.request(
    messages=[
        {
            "role": "user",
            "content": "Cats or dogs?",
        }
    ],
    model="llama-3.3-70b-versatile",
)

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

lazykey-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

lazykey-0.0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file lazykey-0.0.2.tar.gz.

File metadata

  • Download URL: lazykey-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for lazykey-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fd3716ba38920ac17511e7b7c4399561f48e0668dab56341fcd5245b0760c25c
MD5 3fc0ce576ff9fd86fb83434ada4dd1f3
BLAKE2b-256 36d77a1b52d659b1c3737f9027bbb3b1f11a94f5de6a306e727151517a8b4169

See more details on using hashes here.

File details

Details for the file lazykey-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: lazykey-0.0.2-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.10.16

File hashes

Hashes for lazykey-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 25697278c3ce16095a013d89ee4c195e3f2a8d6deff14a439549a733071b94db
MD5 5cccf630aad402068a521c6cb6c6bbf8
BLAKE2b-256 fb3f0fc8977f51f3eb7bb0cb6911fb9d5f50efac2a90991caf5d7064baaa19c0

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