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.3.tar.gz (80.6 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.3-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: poolswitch-0.1.3.tar.gz
  • Upload date:
  • Size: 80.6 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.3.tar.gz
Algorithm Hash digest
SHA256 016d2beb79d6f79d7f7997dbe85a1cbaac900381ee632506eeb56acfb0bbbed2
MD5 3dab200d3ca71716191f0230dbf5969a
BLAKE2b-256 779a7fbc5169fabc39762af50aca2d6990351c46e41ddcc600e1e899e82e543c

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolswitch-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: poolswitch-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6c4b8a4616b0b394af6e753590461977a48817f2c34ac7001398a2a8e53d43
MD5 0ce338e3bf3945598832e63abd226541
BLAKE2b-256 3988933f6532d4327efe1f2180c9459413f0bc4940b8bd78e8a6647866a3faf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for poolswitch-0.1.3-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