Skip to main content

Production-grade PoolSwitch proxy with quota failover and multi-language SDKs.

Project description

PoolSwitch

poolswitch is a production-oriented API key rotation toolkit that can run either:

  • directly inside your app as an embedded client
  • as a local or shared proxy server

It is designed for provider APIs such as OpenAI, Anthropic, Groq, Google, HuggingFace, or any generic HTTP endpoint that authenticates requests with an API key header.

Features

  • Embedded Python client with built-in key rotation, retry, cooldown, and quota failover
  • Embedded Node.js client with built-in key rotation, retry, cooldown, and quota failover
  • Async local HTTP proxy with low overhead
  • Key rotation strategies: round_robin, least_used, random, quota_failover
  • Quota-aware cooldowns and automatic failover
  • Retry system with exponential backoff and network/429 handling
  • Pluggable storage: memory, Redis, SQLite
  • YAML, environment variable, and CLI configuration
  • Prometheus-compatible /metrics endpoint
  • CLI commands for startup, status, metrics, and key management
  • Proxy SDKs for Python, Node.js, and Go

Quick Start

Embedded Client (Recommended)

Node.js / TypeScript:

import { PoolSwitchClient } from "poolswitch-node";

const client = new PoolSwitchClient({
  upstreamBaseUrl: "https://api.openai.com",
  keys: [
    { id: "primary", value: process.env.OPENAI_KEY_1! },
    { id: "backup", value: process.env.OPENAI_KEY_2! }
  ],
  strategy: "quota_failover"
});

const response = await client.post("/v1/chat/completions", {
  json: {
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: "hello" }]
  }
});

Python:

from poolswitch import PoolSwitchClient

client = PoolSwitchClient(
    upstream_base_url="https://api.openai.com",
    keys=[
        {"id": "primary", "value": "sk-123"},
        {"id": "backup", "value": "sk-456"},
    ],
    strategy="quota_failover",
    retry_attempts=3,
    cooldown_seconds=3600,
)

response = client.post(
    "/v1/chat/completions",
    json={
        "model": "gpt-4o-mini",
        "messages": [{"role": "user", "content": "hello"}],
    },
)

For async apps:

from poolswitch import AsyncPoolSwitchClient

async with AsyncPoolSwitchClient(
    upstream_base_url="https://api.openai.com",
    keys=["sk-123", "sk-456"],
) as client:
    response = await client.get("/v1/models")

Proxy Mode

pip install -e .
poolswitch start --config poolswitch.example.yaml

Example request:

curl -X POST http://127.0.0.1:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"hello"}]}'

See docs/architecture.md for the design and the SDK folders for client usage.

Docs Site

This repo now includes a VitePress docs site in docs.

Preview locally with:

npm install
npm run docs:dev

Build static files with:

npm run docs:build

The deployable output is written to docs/.vitepress/dist, which can be uploaded directly to Netlify, Vercel, or any static host.

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

poolswitch-0.1.2.tar.gz (80.5 kB view details)

Uploaded Source

Built Distribution

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

poolswitch-0.1.2-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file poolswitch-0.1.2.tar.gz.

File metadata

  • Download URL: poolswitch-0.1.2.tar.gz
  • Upload date:
  • Size: 80.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for poolswitch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4ec22714ead7559c7b36985c74b1ac0c912560889b6c125c2c925c9e2332284f
MD5 13254e32458d28d2a12522d99e57051a
BLAKE2b-256 f7aeb174d574bf6d3d82964671ea291f1c73b60135c8209f71aac0c0b08a2171

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolswitch-0.1.2.tar.gz:

Publisher: release.yml on SlasshyOverhere/poolswitch

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

File details

Details for the file poolswitch-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: poolswitch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for poolswitch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 260f84b06c4632fcb27209a32905044e1b8dbacdb4909c87f9fd70d3caf7df72
MD5 663747264d05c8d8800a840a248b8f7a
BLAKE2b-256 e8ba5118c4485a7f962395e6366be7bf589b17e44de98f388d0a65ce7fe3db0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolswitch-0.1.2-py3-none-any.whl:

Publisher: release.yml on SlasshyOverhere/poolswitch

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