Skip to main content

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.

PyPI version

New in v5.0 (Ecosystem Edition)

  • Provider Presets — One-line setup for GeminiManager, OpenAIManager, and MultiManager.
  • Automatic Env Parsing — Reads GOOGLE_GEMINI_API_KEY, etc. (supports JSON arrays and comma-separated strings).
  • Built-in PersistenceFileStorage (survives restarts) and MemoryStorage included.
  • 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 StrategiesStandardStrategy, 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)

The fastest way to get started in any Python application.

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


Download files

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

Source Distribution

splashcodex_api_manager-5.0.1.tar.gz (37.1 MB view details)

Uploaded Source

Built Distribution

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

splashcodex_api_manager-5.0.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file splashcodex_api_manager-5.0.1.tar.gz.

File metadata

  • Download URL: splashcodex_api_manager-5.0.1.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

Hashes for splashcodex_api_manager-5.0.1.tar.gz
Algorithm Hash digest
SHA256 bfbe31b63fc1efb8de7e24b5aebecf457c9896e7a79d7cd212fc56ada548b1f6
MD5 f7e801dae255e9ec8c84883a8e871fe0
BLAKE2b-256 4df50368a873917b5dbc5132149d547d78e798b0e949dfb0be3642ab1aa1a0ee

See more details on using hashes here.

File details

Details for the file splashcodex_api_manager-5.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for splashcodex_api_manager-5.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb2a8b498dbe049f1db89d3a2e9e4802a3ec3c5ed6b1e2d61a664abdec0be68f
MD5 260ac5b7437ce77451e57ba1d8a66b0e
BLAKE2b-256 2afb8ccd2aaca9900a1f0118ddf65b2345f949faf1a5fb979f501cfafb31e089

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