Universal API Key Management Gateway with Provider Presets, Built-in Persistence, and Multi-Provider Vault.
Project description
splashcodex-api-manager v5.0 — Ecosystem Edition (Python)
Universal API Key Management Gateway with Provider Presets, Built-in Persistence, and Multi-Provider Vault.
New in v5.0 (Ecosystem Edition)
- Provider Presets — One-line setup for
GeminiManager,OpenAIManager, andMultiManager. - Automatic Env Parsing — Reads
GOOGLE_GEMINI_API_KEY, etc. (supports JSON arrays and comma-separated strings). - Built-in Persistence —
FileStorage(survives restarts) andMemoryStorageincluded. - Singleton Pattern — Thread-safe singletons with async
get_instance(). - Multi-Provider Vault — Manage multiple providers (
gemini,openai,anthropic) from a single entry point.
Features
- Circuit Breaker — Keys transition through
CLOSED → OPEN → HALF_OPEN → DEAD - Error Classification — Automatic detection of 429 (Quota), 403 (Auth), 5xx (Transient), Timeout
- Pluggable Strategies —
StandardStrategy,WeightedStrategy,LatencyStrategy execute()Wrapper — Single async method: get key → call → latency → retry → fallback
Installation
pip install splashcodex-api-manager
# or using uv
uv add splashcodex-api-manager
Quick Start (v5 Presets)
Auto-Scaffold (New!)
The fastest way to get started is to run the init command in your project directory:
splashcodex-api-manager init
# or
python -m splashcodex_api_manager init
This will automatically create a .env template and a demo.py file showing the Gemini Preset in action.
Gemini Preset
Reads GOOGLE_GEMINI_API_KEY or GEMINI_API_KEY from the environment.
import asyncio
from splashcodex_api_manager.presets.gemini import GeminiManager
from splashcodex_api_manager.core.types import ExecuteOptions
async def call_gemini(key, prompt):
# Your arbitrary LLM call logic here
# Example using google-genai:
# return await client.aio.models.generate_content(...)
pass
async def main():
gemini = await GeminiManager.get_instance()
# The manager automatically handles key rotation on failure (429, 500)
response = await gemini.execute(
lambda key: call_gemini(key, "Hello!"),
ExecuteOptions(maxRetries=3)
)
print(response)
asyncio.run(main())
Multi-Provider Vault
Perfect for gateways or complex AI agents handling multiple models.
import asyncio
from splashcodex_api_manager.presets.multi import MultiManager
async def main():
vault = await MultiManager.get_instance({
"providers": {
"gemini": { "envKeys": ["GOOGLE_GEMINI_API_KEY"] },
"openai": { "envKeys": ["OPENAI_API_KEY"] }
}
})
# Route by provider explicitly
res = await vault.execute(
lambda key: call_gemini(key, "Hi"),
provider="gemini"
)
asyncio.run(main())
v5.0 — Architecture & Persistence
Built-in Persistence
State (cooling down keys, dead keys, usage counts) survives application restarts to prevent spamming exhausted keys.
import asyncio
from splashcodex_api_manager.core.manager import ApiKeyManager
from splashcodex_api_manager.persistence.file import FileStorage
async def main():
manager = ApiKeyManager(["key1", "key2"])
# Load past failure history
storage = FileStorage(file_path='./api_state.json')
await manager.load_state(storage)
# ... use the keys ...
# Save before exiting
await manager.save_state(storage)
Execute Wrapper
Wraps the entire lifecycle into one async method. Automatically trips circuit breakers on persistent failures and seamlessly rotates to the next available key.
from splashcodex_api_manager.core.types import ExecuteOptions
result = await manager.execute(
fn=lambda key: httpx_call(key),
options=ExecuteOptions(maxRetries=5, timeoutMs=10000)
)
API Reference
Presets
| Class | Env Vars | Description |
|---|---|---|
GeminiManager |
GOOGLE_GEMINI_API_KEY, GEMINI_API_KEY |
Gemini-optimized asynchronous singleton |
OpenAIManager |
OPENAI_API_KEY |
OpenAI-optimized asynchronous singleton |
MultiManager |
Custom | Thread-safe Vault for multiple provider pools |
Persistence
| Class | Description |
|---|---|
FileStorage |
Persists to a JSON file (recommended for servers and CLI tools) |
MemoryStorage |
In-memory only (best for serverless/short-lived processes) |
License
ISC
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splashcodex_api_manager-5.0.2.tar.gz.
File metadata
- Download URL: splashcodex_api_manager-5.0.2.tar.gz
- Upload date:
- Size: 37.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b2cd1e058b8e128895e0288d5382b98eaaaddd4e4bf749c1964894ea77065ca
|
|
| MD5 |
d407205d0a658bd37fcdb84d305177ab
|
|
| BLAKE2b-256 |
a22c85fcfb9707aaa010a7b650143992a713ca2d6410ecbe815308ea7d430b14
|
File details
Details for the file splashcodex_api_manager-5.0.2-py3-none-any.whl.
File metadata
- Download URL: splashcodex_api_manager-5.0.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f482e6306c2f88515b422ace6ce4baedbcba1dad85e5e1f535620b01f228efeb
|
|
| MD5 |
c66dc33ec175c0dbe1fefc4b7acae97e
|
|
| BLAKE2b-256 |
f10c830f34d18a3477f3ce5700afa4be7bd80e4d2d7bb1034b04c4bcff0d7610
|