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
/metricsendpoint - 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
016d2beb79d6f79d7f7997dbe85a1cbaac900381ee632506eeb56acfb0bbbed2
|
|
| MD5 |
3dab200d3ca71716191f0230dbf5969a
|
|
| BLAKE2b-256 |
779a7fbc5169fabc39762af50aca2d6990351c46e41ddcc600e1e899e82e543c
|
Provenance
The following attestation bundles were made for poolswitch-0.1.3.tar.gz:
Publisher:
release.yml on SlasshyOverhere/poolswitch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poolswitch-0.1.3.tar.gz -
Subject digest:
016d2beb79d6f79d7f7997dbe85a1cbaac900381ee632506eeb56acfb0bbbed2 - Sigstore transparency entry: 1084882285
- Sigstore integration time:
-
Permalink:
SlasshyOverhere/poolswitch@167c86ef46c833f832848030995c1b1bc510a9b2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/SlasshyOverhere
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@167c86ef46c833f832848030995c1b1bc510a9b2 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d6c4b8a4616b0b394af6e753590461977a48817f2c34ac7001398a2a8e53d43
|
|
| MD5 |
0ce338e3bf3945598832e63abd226541
|
|
| BLAKE2b-256 |
3988933f6532d4327efe1f2180c9459413f0bc4940b8bd78e8a6647866a3faf3
|
Provenance
The following attestation bundles were made for poolswitch-0.1.3-py3-none-any.whl:
Publisher:
release.yml on SlasshyOverhere/poolswitch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
poolswitch-0.1.3-py3-none-any.whl -
Subject digest:
5d6c4b8a4616b0b394af6e753590461977a48817f2c34ac7001398a2a8e53d43 - Sigstore transparency entry: 1084882382
- Sigstore integration time:
-
Permalink:
SlasshyOverhere/poolswitch@167c86ef46c833f832848030995c1b1bc510a9b2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/SlasshyOverhere
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@167c86ef46c833f832848030995c1b1bc510a9b2 -
Trigger Event:
push
-
Statement type: