Configuration
The registry schema, key fields, provider overrides, and how configuration is merged.
llm-rotate is configured with a registry — a plain Python dict of keys
(and optional provider overrides) — plus the list of keys you want active. The
package ships a built-in provider catalog, so most configs only need a keys
block.
The two ways to configure
from llm_rotate import configure
# 1. Registry + use_keys (most common)
configure(registry={"keys": [...]}, use_keys=["openai-1"])
# 2. A pre-built LMRotateConfig (full control)
from llm_rotate import LMRotateConfig
configure(config=LMRotateConfig(...))You can also build a config object without touching the singleton:
from llm_rotate import configure_from_dict, LMRotate
config = configure_from_dict(registry={"keys": [...]}, use_keys=["openai-1"])
rot = LMRotate(config)Key entries
Each entry in registry["keys"] describes one credential. Four fields are
required:
| Field | Description |
|---|---|
key_id | Unique name for this credential — used in logs and in use_keys=[...]. |
provider | One of openai, anthropic, google_ai_studio, google_vertex, openrouter, azure_openai, aws_bedrock. |
secret_ref | A secret URI such as env://OPENAI_API_KEY — resolved at runtime, never stored. |
models | List of model IDs this key may serve. Drives routing and model→provider inference. |
Optional key fields
| Field | Default | Purpose |
|---|---|---|
auth_method | "api_key" | Auth scheme. Vertex uses service-account credentials. |
auth_config | {} | Provider-specific config, e.g. Vertex { "project": ..., "region": ... }. |
priority | 0 | Higher wins under the priority and health_aware strategies. |
weight | 1 | Relative weight for the weighted strategy. |
regions | [] | Free-form region tags. |
tags | [] | Free-form labels for your own bookkeeping. |
rate_limit_rpm / rate_limit_tpm | None | Per-key requests/tokens-per-minute budgets, enforced client-side during selection. See Key selection. |
enabled | true | Set false to keep an entry in the registry but inactive. |
metadata | {} | Arbitrary key→value metadata. |
{
"key_id": "vertex-prod-1",
"provider": "google_vertex",
"secret_ref": "env://VERTEX_SA_JSON",
"auth_method": "service_account",
"auth_config": {"project": "my-proj", "region": "us-central1"},
"models": ["gemini-2.0-flash"],
"priority": 10,
}Overriding provider defaults
Every built-in provider has sensible cooldown/quarantine defaults. To change
them, add a providers block with only the entries you want to override —
everything else keeps its built-in value.
configure(
registry={
"providers": {
"openai": {
"provider_type": "direct",
"display_name": "OpenAI",
"default_cooldown_seconds": 10,
}
},
"keys": [...],
},
use_keys=[...],
)Defaults
These are the global defaults (DefaultsConfig), overridable per provider and,
for max_retries, per call:
| Setting | Default |
|---|---|
selection_strategy | "health_aware" |
max_retries | 3 |
cooldown_seconds | 60 |
quarantine_seconds | 300 |
max_consecutive_failures | 5 |
Merge rules
- The five built-in providers are always the base layer.
- A provider entry in your registry's
providersblock replaces the matching built-in by name; providers you don't mention keep their defaults. keysalways come from your dict — the package ships no keys, credentials, orsecret_refvalues.
State store
By default, key health, cooldowns, and leases live in an in-process store —
zero setup, but not shared across workers. To coordinate rotation across
multiple processes, switch to the Redis backend (pip install "llm-rotate[redis]"):
config = configure_from_dict(
registry={
"state_store": {
"backend": "redis",
"redis_url": "redis://localhost:6379/0",
"redis_namespace": "llmrotate",
},
"keys": [...],
},
use_keys=[...],
)| Field | Default | Purpose |
|---|---|---|
backend | "memory" | "memory" (in-process) or "redis" (shared). |
redis_url | redis://localhost:6379/0 | Connection URL for the Redis backend. |
redis_namespace | "llmrotate" | Key prefix so multiple apps can share one Redis. |
See Advanced for the operational details.
Loading config from a file
configure_from_file() reads the same shape from JSON or YAML (YAML needs
pip install "llm-rotate[yaml]"). use_keys can live in the file or be passed
in:
from llm_rotate import configure_from_file
config = configure_from_file("llm-rotate.yaml")# llm-rotate.yaml
use_keys: [openai-1, anthropic-1]
strategy: health_aware
state_store:
backend: redis
redis_url: redis://localhost:6379/0
keys:
- key_id: openai-1
provider: openai
secret_ref: env://OPENAI_API_KEY
models: [gpt-4o-mini]
- key_id: anthropic-1
provider: anthropic
secret_ref: env://ANTHROPIC_API_KEY
models: [claude-haiku-4-5-20251001]The built-in provider catalog is merged automatically, so only keys (and
use_keys) are strictly required.
Top-level configure() options
| Parameter | Purpose |
|---|---|
registry | Dict with keys (and optional providers). |
use_keys | Which key_ids to activate. |
config | A pre-built LMRotateConfig (overrides the dict args). |
strategy | Selection strategy override. See Key selection. |
priorities | {key_id: int} per-key priority shortcut. |
fallback_chains | {provider: [{provider, upstream?}, ...]}. See Fallback chains. |
Enterprise pattern
For multi-app deployments, keep a central registry (in a cloud secret manager) and let each app pick the keys it needs:
import llm_rotate
llm_rotate.configure(
use_keys=["vertex-prod-1", "anthropic-prod-1"],
priorities={"vertex-prod-1": 10, "anthropic-prod-1": 5},
strategy="health_aware",
fallback_chains={"google_vertex": [{"provider": "anthropic"}]},
)The recommended secret flow is: cloud secret manager → a load_secrets.sh step
that exports env vars → env:// resolution at call time. Secrets never live in
the registry dict.