Skip to main content

Unified LLM client with key rotation, health-aware failover, and multi-provider orchestration.

Project description

llm-rotate

llm-rotate is a Python library for resilient LLM calls across providers. It provides API key rotation, health-aware selection, retry/failover, and a unified chat interface.

What it does

  • Unified API for OpenAI, Anthropic, Google AI Studio, Vertex AI, and OpenRouter
  • Automatic key rotation on rate-limit/auth/transient failures
  • Provider fallback chains
  • Streaming and sync/async chat support
  • Structured per-call usage logging

Quickstart

llm-rotate ships a built-in provider catalog covering all five supported backends. Configure it programmatically with a plain Python dict before your first lm call — no env var registry blob required.

from llm_rotate import configure, lm

configure(
    registry={
        "keys": [
            {
                "key_id": "openai-1",
                "provider": "openai",
                "secret_ref": "env://OPENAI_API_KEY",
                "models": ["gpt-4o-mini"],
            },
            {
                "key_id": "gemini-1",
                "provider": "google_ai_studio",
                "secret_ref": "env://GOOGLE_API_KEY",
                "models": ["gemini-2.0-flash"],
            },
        ]
    },
    use_keys=["openai-1", "gemini-1"],
)

response = await lm.chat("gpt-4o-mini", [{"role": "user", "content": "Hello"}])
print(response.content)

configure() must be called before the first use of lm. Using lm without prior configure() raises ConfigurationError.

Required fields per key entry

Field Description
key_id Unique name for this credential (used in logs and use_keys=[...])
provider One of: openai, anthropic, google_ai_studio, google_vertex, openrouter
secret_ref env://VAR_NAME — resolved at runtime, never stored
models List of model IDs this key may serve (used for routing and inference)

Overriding built-in provider settings (optional)

If you need custom cooldown/quarantine values for a specific provider, add a providers key containing only the entries you want to override — the rest keep their built-in defaults:

configure(
    registry={
        "providers": {
            "openai": {
                "provider_type": "direct",
                "display_name": "OpenAI",
                "default_cooldown_seconds": 10,
            }
        },
        "keys": [...],
    },
    use_keys=[...],
)

Merge rules

  1. Built-in providers (openai, anthropic, google_ai_studio, google_vertex, openrouter) are always the base layer.
  2. Any provider entry in the registry dict's "providers" block replaces the corresponding built-in entry by name; providers not mentioned keep their built-in values.
  3. "keys" always come from the caller-supplied dict — the package ships no keys, credentials, or secret_ref values.

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

llm_rotate-0.3.1.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

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

llm_rotate-0.3.1-py3-none-any.whl (46.0 kB view details)

Uploaded Python 3

File details

Details for the file llm_rotate-0.3.1.tar.gz.

File metadata

  • Download URL: llm_rotate-0.3.1.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for llm_rotate-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ac12a73ca6eecedc5d67f4047242bac78afae28cd7cd459884b99cf95b10ca3c
MD5 e2b18e0413a14834d3a23771d03da5e6
BLAKE2b-256 44d6c7de84ea41830d203af3adbb41ae681477808ffce9780a6c8b72f4bc1635

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_rotate-0.3.1.tar.gz:

Publisher: publish.yml on Research-Commons/llm-rotate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_rotate-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: llm_rotate-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 46.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for llm_rotate-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d03a85ea668b7c192eee0f5524c1a118f7652a2b7b0596e032229d346ce6ac
MD5 db2c0d08c54e8a8f840731a564e0cb50
BLAKE2b-256 2ddc6c3aa6cc9fe29025dd23eb7882aef379c21f86c3bdb4af8d0ab092230210

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_rotate-0.3.1-py3-none-any.whl:

Publisher: publish.yml on Research-Commons/llm-rotate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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