Metadata-Version: 2.5
Name: keyladder
Version: 0.1.2
Summary: One local address for all your AI API keys: when one free key runs out, Keyladder tries the next, and it never spends money you did not approve.
Project-URL: Homepage, https://github.com/sukumarmuthusamy/keyladder
Project-URL: Documentation, https://github.com/sukumarmuthusamy/keyladder/tree/main/docs
Project-URL: Source, https://github.com/sukumarmuthusamy/keyladder
Project-URL: Issues, https://github.com/sukumarmuthusamy/keyladder/issues
Project-URL: Changelog, https://github.com/sukumarmuthusamy/keyladder/blob/main/CHANGELOG.md
Author: Keyladder contributors
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Requires-Python: >=3.12
Requires-Dist: aiosqlite<1,>=0.22
Requires-Dist: alembic<2,>=1.20
Requires-Dist: argon2-cffi>=25.1
Requires-Dist: cryptography>=50
Requires-Dist: fastapi<1,>=0.165
Requires-Dist: httpx<1,>=0.28
Requires-Dist: pydantic-settings<3,>=2.16
Requires-Dist: pydantic<3,>=2.14
Requires-Dist: pyyaml>=6.0.4
Requires-Dist: sqlalchemy[asyncio]<2.2,>=2.1
Requires-Dist: typer<1,>=0.29
Requires-Dist: tzdata>=2024.1
Requires-Dist: uvicorn[standard]<1,>=0.54
Provides-Extra: postgres
Requires-Dist: asyncpg<1,>=0.32; extra == 'postgres'
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/banner-dark.svg">
    <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/banner-light.svg" alt="Keyladder: all your AI API keys, one local address" width="100%">
  </picture>
</p>

<p align="center">
  <b>When one free AI key runs out, Keyladder tries the next, and it never spends money you didn't approve.</b>
</p>

<p align="center">
  <a href="LICENSE"><img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/badges/license.svg" alt="License: Apache 2.0" height="22"></a>
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/badges/python.svg" alt="Python 3.12 or newer" height="22">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/badges/local.svg" alt="Runs on your machine" height="22">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/badges/telemetry.svg" alt="No telemetry" height="22">
</p>

<p align="center">
  <a href="#quick-start">Quick start</a> ·
  <a href="#how-it-works">How it works</a> ·
  <a href="#screenshots">Screenshots</a> ·
  <a href="#works-with">Works with</a> ·
  <a href="#faq">FAQ</a> ·
  <a href="#documentation">Docs</a>
</p>

## Why Keyladder?

You have a Groq key, a Gemini key or two, an OpenRouter key, maybe more. Each free plan has its own limits, so
sooner or later one says "too many requests" and your app stops. So you write retry code in every project, and
still can't tell which key answered or whether anything cost money.

Keyladder runs on your own computer and holds all those keys. Your apps send requests to it as they would to
OpenAI. It tries your keys in your order until one answers, skips anything that would break a limit or cost
money, and writes down why.

**Before:** every project carries its own retry loop.

```python
for key, model in my_keys:
    try:
        reply = call(key, model, messages)
        break
    except RateLimitError:  # "too many requests"
        continue  # which key answered? did it cost money?
```

**After:** every project talks to Keyladder, which handles the keys, the limits and the retries.

```python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8787/v1", api_key="kl-...")  # your Keyladder key
reply = client.chat.completions.create(model="auto", messages=messages)
```

**Try it** with Docker, using built-in fake providers (no account needed):

```bash
git clone https://github.com/sukumarmuthusamy/keyladder.git && cd keyladder
KEYLADDER_DEMO=true docker compose up -d --build && docker compose logs gateway
```

Open the setup link it prints. The [Quick start](#quick-start) covers uv, Windows and adding your real keys.

## See it in action

<p align="center">
  <a href="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/media/keyladder-tour.mp4">
    <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/media/keyladder-tour.gif" alt="Screen recording: the overview, reordering the ladder, a simulator dry run, and the trace of a real request that fell back from Groq to Gemini" width="100%">
  </a>
</p>
<p align="center"><sub>
  A real recording with free-tier keys. In the trace at the end, Keyladder's own per-minute limit on the Groq
  key (set low for this demo) skipped both Groq models without calling them, <code>gemini-2.5-flash</code>
  returned a real 404, and <code>gemini-3.5-flash-lite</code> answered, all within one request.
  <a href="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/media/keyladder-tour.mp4">Watch as video</a>.
</sub></p>

## How it works

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/how-it-works-dark.svg">
    <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/how-it-works-light.svg" alt="Illustration: key 1 has had too many requests, key 2 has used up its daily limit, key 3 answers, and the trace records each step" width="100%">
  </picture>
</p>

You put your keys in order once (several per provider is fine, each with its own limits). Then, per request:

1. **Your app sends a normal request** to Keyladder, using a Keyladder key instead of a provider key.
2. **Keyladder climbs the ladder.** It skips any key that is busy, out of allowance, missing something the
   request needs, or would cost money. The first key that can answer does.
3. **Every step is written down** in a trace: which keys were tried, why each was skipped, how long it took
   and what it cost (on free plans, $0).

<details>
<summary><b>Words used on this page</b></summary>

- **Provider:** a company that runs AI models behind an API, such as Groq or Google Gemini.
- **Free tier:** a provider's free plan, with daily or per-minute limits.
- **Token:** a piece of a word; providers count and limit usage in tokens.
- **Tools:** functions an AI model can ask your program to run (also called function calling).
- **Trace:** Keyladder's record of how one request was handled.
- **Route:** a named ladder your apps can ask for, such as `model="free-ladder"`; `auto` uses all your keys.

</details>

## What you get

<table>
<tr>
<td width="50%" valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/ladder.svg" width="32" height="32" alt=""><br>
<b>Your keys, in your order</b><br>
Drag keys into the order you want them tried, across providers. Route changes can be tested before they go live.
</td>
<td width="50%" valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/shield.svg" width="32" height="32" alt=""><br>
<b>No surprise bills</b><br>
Paid models stay off until you allow them in three places. Free never quietly turns into paid.
</td>
</tr>
<tr>
<td valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/gauge.svg" width="32" height="32" alt=""><br>
<b>Limits you set</b><br>
Requests, tokens, cost and requests at the same time, per key, app or provider account. Keys on one account can share one allowance.
</td>
<td valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/fallback.svg" width="32" height="32" alt=""><br>
<b>Careful retries</b><br>
Moves on when a key is busy or broken, but never resends a rejected request or replays a half-sent answer.
</td>
</tr>
<tr>
<td valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/trace.svg" width="32" height="32" alt=""><br>
<b>See every decision</b><br>
A trace per request, usage and speed per provider, a simulator for dry runs and a playground.
</td>
<td valign="top">
<img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/icons/plug.svg" width="32" height="32" alt=""><br>
<b>Works with your tools</b><br>
Speaks OpenAI's and Anthropic's API, so existing apps and agents only need a new address.
</td>
</tr>
</table>

How it all works in detail: [architecture](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/architecture.md), [routing](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/routing.md),
[limits](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/quotas.md).

## Quick start

You need [uv](https://docs.astral.sh/uv/) (it fetches Python 3.12+ for you) and Node.js 22.12+ to build the
dashboard, **or** just Docker.

### 1. Get the code

```bash
git clone https://github.com/sukumarmuthusamy/keyladder.git
cd keyladder
```

### 2. Start it

**With uv** (macOS, Linux, or Windows with Git Bash/WSL):

```bash
uv sync --locked
cd web && npm ci && npm run build && cd ..
uv run keyladder serve --demo
```

<details>
<summary><b>Windows PowerShell</b></summary>

Windows PowerShell 5.1 has no `&&`, so run one command per line:

```powershell
uv sync --locked
cd web
npm ci
npm run build
cd ..
uv run keyladder serve --demo
```

`scripts\dev.ps1` wraps the same steps (`bootstrap`, `web`, `dev`).

</details>

**With Docker** (any system):

```bash
KEYLADDER_DEMO=true docker compose up -d --build
docker compose logs gateway
```

In PowerShell, run `$env:KEYLADDER_DEMO = "true"` first, then the two `docker compose` commands.

Keyladder now runs at `http://127.0.0.1:8787`, reachable from your computer only. On first start it prints a
one-time **setup link** (in the terminal, or in `docker compose logs gateway`). Open it and create your
owner account. Missed it, or it expired after 24 hours? Run `uv run keyladder reset-owner`
(Docker: `docker compose exec gateway keyladder reset-owner`).

Demo mode (`--demo` or `KEYLADDER_DEMO=true`) adds clearly labelled fake providers to try things with.
Remove them later with `uv run keyladder demo --remove`.

### 3. Add your keys and send a request

Add provider keys in the dashboard (**Providers & Credentials → Add credential**), or, with uv, as environment
variables (or in a `.env` file) before starting:

```bash
export KEYLADDER_CREDENTIAL__GROQ__PERSONAL=gsk_...
export KEYLADDER_CREDENTIAL__GEMINI__WORK=AIza...
```

<details>
<summary><b>The same in Windows PowerShell</b></summary>

```powershell
$env:KEYLADDER_CREDENTIAL__GROQ__PERSONAL = "gsk_..."
$env:KEYLADDER_CREDENTIAL__GEMINI__WORK = "AIza..."
```

</details>

These become `groq/personal` and `gemini/work`, with paid usage off. Then, under **Projects & Keys**, create a
project and a **Keyladder key** (shown once; in demo mode use the `demo` project), and point any OpenAI client
at Keyladder:

```python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8787/v1", api_key="kl-...")

reply = client.chat.completions.create(
    model="auto",  # let Keyladder pick from your ladder
    messages=[{"role": "user", "content": "Hello!"}],
)
print(reply.choices[0].message.content)
```

`model="auto"` uses your whole ladder. You can also pin a model you have a key for, such as
`model="groq/openai/gpt-oss-120b"`, or name a route. Every reply says what served it:

```text
x-keyladder-provider: groq
x-keyladder-model: openai/gpt-oss-120b
x-keyladder-credential: personal
```

The dashboard's **Traces** page shows the full story.

> [!TIP]
> `uv run keyladder live-check` confirms each key works without sending a single chat request
> ([details](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/live-validation.md)).

PostgreSQL, backups and upgrades: [deployment](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/deployment.md) and [operations](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/operations.md).

## Screenshots

Real captures after two days of light free-tier traffic through five providers. They follow your
light or dark setting.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/trace-dark.png">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/trace-light.png" alt="Trace: two Groq models skipped by a per-minute limit, a retired Gemini model failed with 404, the next one answered">
</picture>
<p align="center"><b>A trace.</b> Read the Decision cards in order: two rejected by a limit, one failed, one succeeded.</p>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/ladder-dark.png">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/ladder-light.png" alt="The ladder: six keys from five providers, all healthy">
</picture>
<p align="center"><b>The ladder.</b> Six keys from five providers, tried top to bottom; drag to reorder.</p>

<details>
<summary><b>More: playground, overview, limits</b></summary>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/playground-dark.png">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/playground-light.png" alt="Playground: a free NVIDIA model calls a get_weather tool, then answers from its result">
</picture>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/overview-dark.png">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/overview-light.png" alt="Overview: today's requests, a used-up limit, speed per provider and the next quota resets">
</picture>

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/limits-dark.png">
  <img src="https://raw.githubusercontent.com/sukumarmuthusamy/keyladder/main/docs/images/limits-light.png" alt="Limits: usage against each cap, with a protected reserve">
</picture>

Simulator, traces list and Eval Lab captures are in [docs/images](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/images/).

</details>

## Works with

Built-in support for the providers below, plus [Ollama](https://ollama.com/), any OpenAI-compatible server and
plugins. Names are trademarks of their owners; Keyladder is not affiliated with them.

| Provider | Checked live with a free key on 2026-11-30 |
|---|---|
| Groq | Yes: chat, streaming, tools, JSON output |
| Google Gemini | Yes, on two separate accounts: chat |
| OpenRouter (`:free` models) | Yes: chat, streaming, tools, JSON output; a paid model was refused before sending |
| NVIDIA (hosted API catalog) | Yes: chat, streaming, tools, JSON output |
| Cloudflare Workers AI | Yes: chat, streaming |
| Hugging Face | Checked: free accounts can't use its router (it asks for pre-paid credits) |
| Cerebras | Checked: free access now needs a payment method |
| OpenAI, Anthropic, Mistral, DeepSeek, Together, Cohere, SambaNova | Not yet (no free key); built from their docs |

"Yes" means each feature worked at least once that day through the real API: a record of one day, not a
promise. Full results, including failures: [live results](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/live-validation-results.md).

## How it's tested

Besides the test suite, two tools replay scripted failures against a stand-in provider. They measure
Keyladder's decisions, not real-provider speed or model quality.

- **`uv run keyladder eval run`**: [the recorded run](https://github.com/sukumarmuthusamy/keyladder/blob/main/evals/results/eval-20261201-184913-675d5d44.md)
  (commit `675d5d4`, 2026-12-01) passed 56 scenarios (1 skipped) and 1,084 of 1,084 checks, with 0 budget
  violations and 0 secret leaks.
- **`uv run keyladder bench`**: the same 16 requests and failures through three setups.
  [The recorded run](https://github.com/sukumarmuthusamy/keyladder/blob/main/benchmarks/results/2026-12-01-675d5d44.md) (commit `675d5d4`, 2026-12-01):

| | Keyladder | Naive | Direct |
|---|---|---|---|
| Correct* | **16/16** | 8/16 | 8/16 |
| Answered | 11/16 | 16/16 | 8/16 |
| Unsafe retries | **0** | 3 | 0 |
| Over budget | **0** | 2 | 2 |
| Paid at $0 budget | **0** | 1 | 0 |

\* Graded by Keyladder's own rules: no free-to-paid fallback, no retry after an invalid request, a read timeout
or a half-sent stream, no going over budget. "Naive" (next provider on any error) and "Direct" (one provider)
are minimal clients written for this test, not other products. Naive answered more by breaking those rules;
Keyladder's five refusals were correct. The cost: about 18 ms added per request (median; 28 ms at p95) on SQLite, on a shared 4-CPU cloud machine.
Method and caveats: [docs/evaluation.md](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/evaluation.md), [docs/benchmarks.md](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/benchmarks.md).

## FAQ

<details>
<summary><b>Is it free?</b></summary>

Yes, open source under Apache 2.0. Provider pricing is up to them; Keyladder keeps you inside your free plans.

</details>

<details>
<summary><b>Can it spend my money?</b></summary>

Not unless you say so three times: the global paid switch is on, that key may spend, and the model has a price
you entered (the catalog leaves prices empty on purpose). A free request never falls back to a paid model
unless a route says so, and you can cap spending per key or project.

</details>

<details>
<summary><b>Does it store my prompts?</b></summary>

Not unless you turn that on. Traces keep the facts (keys tried, model, timings, tokens, cost, errors), not the
text, for 14 days by default. The opt-in **content capture** setting, for debugging, also keeps messages and
replies, with known secrets replaced by `[REDACTED]`, for 24 hours by default. All of it stays on your machine.

</details>

<details>
<summary><b>Is it safe to run?</b></summary>

- It listens only on `127.0.0.1` by default: nothing outside your computer can reach it.
- Provider keys are encrypted at rest (AES-256-GCM, rotatable master key) and never shown again; Keyladder
  keys are stored only as hashes.
- Sign-in uses Argon2id, strict cookies, CSRF and Origin checks, and login throttling. Backups are
  tamper-checked, with secrets still encrypted inside.
- No telemetry: the only outside calls go to the providers you set up.

For use from other machines, put TLS in front and read the [threat model](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/security/threat-model.md).
Report vulnerabilities via [SECURITY.md](https://github.com/sukumarmuthusamy/keyladder/blob/main/SECURITY.md).

</details>

<details>
<summary><b>What if a provider changes its limits?</b></summary>

Keyladder's limits are your own numbers: set them a little below the provider's and change them any time. If
a provider refuses requests anyway, Keyladder rests that key for as long as the provider asks and moves on.

</details>

<details>
<summary><b>How is this different from LiteLLM or OpenRouter?</b></summary>

OpenRouter is a hosted service: you reach many models through its key and its billing. Keyladder runs on your
machine with your own keys from each provider (an OpenRouter key can be one of them). LiteLLM is a broad proxy
and SDK for many providers. Keyladder is narrower: a strict ladder of your own keys, shared allowances for keys
on one account, limits reserved before anything is sent, paid usage off by default, and a trace for every
decision.

</details>

<details>
<summary><b>Does it work with my agent or tool?</b></summary>

If it lets you set an OpenAI or Anthropic base URL, very likely: Keyladder speaks OpenAI Chat Completions
(streaming, tools, JSON mode), Anthropic Messages, embeddings and `/v1/models`
([details](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/compatibility.md)).

</details>

<details>
<summary><b>Is it ready?</b></summary>

It is pre-1.0: everything here is built and tested against scripted providers, and five providers were
checked live. Expect rough edges; see the [changelog](https://github.com/sukumarmuthusamy/keyladder/blob/main/CHANGELOG.md).

</details>

## Documentation

| Start here | Go deeper | Testing and results |
|---|---|---|
| [Configuration](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/configuration.md) | [Architecture](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/architecture.md) and [decision records](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/adr/) | [Evaluation](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/evaluation.md) |
| [Deployment](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/deployment.md) | [Routing](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/routing.md) · [Quotas and limits](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/quotas.md) | [Benchmarks](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/benchmarks.md) |
| [Operations](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/operations.md) | [API](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/api.md) · [Data model](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/data-model.md) | [Live validation](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/live-validation.md) |
| [Providers](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/providers.md) · [Compatibility](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/compatibility.md) | [Threat model](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/security/threat-model.md) · [Releases](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/release.md) | [Live results (2026-11-30)](https://github.com/sukumarmuthusamy/keyladder/blob/main/docs/live-validation-results.md) |

## Contributing

Contributions are welcome. Start with [CONTRIBUTING.md](https://github.com/sukumarmuthusamy/keyladder/blob/main/CONTRIBUTING.md); the short version: no real provider
keys in tests, no paid calls in CI, and a failing test first for anything security-related. Please follow the
[Code of Conduct](https://github.com/sukumarmuthusamy/keyladder/blob/main/CODE_OF_CONDUCT.md).

## License

Apache License 2.0. See [LICENSE](https://github.com/sukumarmuthusamy/keyladder/blob/main/LICENSE) and [NOTICE](https://github.com/sukumarmuthusamy/keyladder/blob/main/NOTICE).
