Palimpsest Gateway

Self-hosted · OpenAI-compatible

One endpoint in front of all your LLM keys.

Pool OpenAI, Anthropic, Gemini, OpenRouter, Mistral, Groq, Z.ai, xAI, GitHub Models and any OpenAI-compatible key. Let it pick the best model. Fail over automatically. Keep every conversation going across the switch.

  • MIT licensed
  • Python 3.11 | 3.12
  • FastAPI + Redis
  • Docker Compose
POST /v1/chat/completions  model=gpt-4o-mini  session=my-chat
  key openai-free-1   429 rate limited   rest 60s
  key openai-free-2   quota spent       wait for reset
  key openai-paid     200 ok           history carried over
reply returned · 1 request counted · 0 changes in your app

See what your keys are doing

The operator dashboard ships in the same container. Live traffic, key health, cost and latency, with no message content ever shown.

Dashboard overview in the dark theme: requests, success rate, latency, tokens, estimated cost, active users and pool state, with a requests-per-day chart
Overview. Headline numbers against the previous period, in a light or dark theme.
Live Flow: clients on the left, the gateway in the middle, providers and models on the right, with requests as moving dots
Live Flow. One dot per request, from client through the gateway to a provider and back.
Supermode ranking: every model the pool can serve with score, context window, capabilities, keys ready and a start score you can set
Supermode. The live ranking of every model the pool can serve. Set a start score from here.
Pool Keys: provider keys grouped by provider with their models, state and Test, Limits, Edit and Suspend actions
Pool Keys. Add, test, suspend and edit keys from every provider.
Utilization and Failover: per-key use of its cap, paused models and the failover record
Utilization and failover. How much of each key's cap is used, and why anything is paused.
Costs: spend per day, month to date, projection and budget, by model
Costs. Spend against the prices and monthly budget you enter.
Performance: latency percentiles and distribution, error rate, throttled requests and requests served after failover
Performance. Latency percentiles, error causes and requests saved by a failover.

Screenshots use demo data: invented keys, users and traffic.

Your apps see one URL. Behind it, a pool.

Apps talk to the gateway exactly as they would talk to OpenAI. Provider keys never leave it.

Your app

Any OpenAI client, with a gateway key pgw_live_…

Palimpsest Gateway

Admit, load history, pick a key, fail over, meter usage.

Providers

OpenAI, Anthropic, Google Gemini, OpenRouter, Mistral, Groq, Z.ai, xAI, GitHub Models and custom endpoints.

  1. Authenticate. The app sends its own gateway key, never a provider key.
  2. Admit. Daily cap and remaining pool capacity are checked.
  3. Load context. With X-Session-ID, stored history is added for you.
  4. Choose a model and a key. Ask for palimpsest/supermode and the gateway picks the best model that can serve; then only active keys that serve it and aren't resting.
  5. Fail over. Rate limit, outage or bad key: retry on the next key, same call. A provider in a real outage is skipped for a moment instead of hammered.
  6. Answer and record. Reply in OpenAI format, turn saved, usage counted once.

Features

Everything needed to run a shared key pool without every app re-implementing it.

Drop-in OpenAI API
/v1/chat/completions with streaming and tool calls, plus /v1/models.
Multi-provider pool
Keys with optional request cap, token budget, reset schedule and label.
Supermode
Ask for palimpsest/supermode and the gateway picks the best model your pool can serve right now, across every provider and key, and moves to the next best if it fails. Pin a model's starting score from the dashboard.
Learns from traffic
Context sizes, vision and tool support, model reliability and per-key rate limits are learned from what succeeds and what is refused, so the next request avoids what blocked this one.
Live Flow
Watch each request travel from a client through the gateway to a provider and model and back, with a history of every call and which key served which model.
Provider protection
A per-provider circuit breaker skips a provider in a real outage, and a concurrency gate caps requests in flight per provider. Neither spends a retry.
Key tests
Send one tiny real request through a key, or test every model of a key to find the ones the account can really use. A pass lifts a stale pause.
Automatic failover
Rate limits, outages and exhausted quotas are retried within a fixed budget. 503 with a retry hint when nothing is left.
Conversation memory
Per-user session history, so clients send only the new message and context survives a switch.
Fairness controls
Per-user daily caps and a pool low-water mark that throttles before the pool runs dry.
Keys stay private
Encrypted at rest, never returned after creation. Users only see generic errors and stable codes.
Operator dashboard
Key health and tests, usage, failovers, users, sessions, latency, costs, alerts and audit trail.
Costs from your prices
You enter per-model prices and a monthly budget. Nothing bundled, so nothing goes stale.
Alerts and exports
Low capacity, key problems, error rate, optional webhook. CSV export for usage, requests and audit.
Observable
One structured JSON log line per request, Prometheus metrics, and an ops view with provider and breaker state.

Quick start

Docker with Compose v2 is the only prerequisite. No .env, no manual key generation.

01Clone and run

shell
git clone https://github.com/hammrouni/palimpsest-gateway.git
cd palimpsest-gateway
docker compose up -d --wait

API at localhost:8000, dashboard at /dashboard/, docs at /docs. First boot generates and persists a master key and an operator key.

02Add a provider key

shell
echo 'PALIMPSEST_PROVIDER_API_KEY=sk-your-key' >> .env
docker compose up -d

Or add pool keys in the dashboard. Read the operator key with docker compose exec app cat /app/.secrets/operator_key.

03Create a user and call it

app.py
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="pgw_live_...")
reply = client.chat.completions.create(
    model="gpt-4o-mini",  # a model one of your pool keys serves
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)

Create the user under Users → + New user; the key is shown once. Send the same X-Session-ID header to keep a conversation going server-side.

Security. The gateway binds 127.0.0.1:8000 by default and has no TLS or IP rate limiting. Before exposing it, set PALIMPSEST_BIND=0.0.0.0 behind a TLS reverse proxy, with PALIMPSEST_ALLOW_SIGNUP=false and a user daily cap.

Paid keys, free keys, or both

The gateway tries keys that still have requests left first, most room first. Uncapped keys come last. Give limited keys a cap and they are used before the fallback.

Paid keysAdd without a cap, or with a safety cap. Enter prices and a monthly budget under Costs, and turn on Alerts.
Free-tier keysSet daily_cap at or below the published allowance with the matching reset period. Spent keys are skipped until reset.
Not a model hostIt forwards to providers and runs no models.
Not a loopholeIt uses only the keys you give it, within each key's limits. It does not lift provider limits.
CapacityIf every key is out of quota, clients get a 503 with Retry-After.
LicenseMIT

Stop handling 429s in every app.