A previous release had provenance metadata, but this release does not. View details.
gemini-router
Quota-aware Gemini Flash router as a standalone, reusable module — extracted and
generalized from tldr-digest/src/llm.py.
One persistent ledger (SQLite WAL) lets the gemini-mcp
gateway and CLI calls share quota truth on a machine. Other programs can join the same
ledger; tldr-digest has not been migrated yet.
- Cascading chain with runtime
listModelsvalidation (configurable; the current default lives only insrc/gemini_router/config.py:DEFAULT_CHAIN). - Per key×model budgets: RPD (Pacific-time day + rolling 24 h), RPM, TPM (sliding
60 s) — pre-flight enforced, accounted from
usageMetadata; conservative 429 handling with cooldowns andRetry-After. - Key pool (
GEMINI_API_KEYS/GEMINI_API_KEY_1..10), budget-maximizing selection. thinking_levelper request (Gemini 3.x rules), request cache (0-RPD hits), opt-in overflow tiers (flash-lite → gemma-auto) behind oneoverflow_defaultconfig key that every entry point (library and proxy) walks identically, event stream for progress frontends.- Per-request wait policy for minute-scale gates (RPM/TPM/short cooldowns): default
wait with countdown events (
waiting, remaining seconds);wait=Falseskips to the next candidate or returns wait ETAs in the structured error. Daily resets are never waited on. - CLI:
gemini-router quota | models | calls | prune | doctor | proxy(rich tables). - Native Gemini API pass-through (
gemini-router proxy, loopback): pointGOOGLE_GEMINI_BASE_URLat it to run a Google Gen AI SDK client — e.g. themikesmitty/file-searchMCP — on this key pool. Model and key of a model call come from the same selection walk the library uses (chain, overflow, budgets — SPEC §11.6); File Search resources stay pinned to the Google project that owns them (SPEC §11, wiring: docs/file-search-wiring.md). - Deps:
httpx,pydantic,rich, stdlibsqlite3— no MCP/web-framework coupling.
Contract: docs/SPEC.md.
Install
uv add gemini-router # PyPI
gemini-router quota # RPD left / RPM & TPM windows / cooldowns / recommendation
Usage
from gemini_router import Router, RouterRequest
router = Router.from_env()
res = await router.complete(RouterRequest(prompt=..., thinking_level="high"),
on_event=print)
Streaming
Pass stream=True to Router.complete. on_event receives stream_start before
each provider attempt (discard the previous provisional text), then text events
with detail["text"] deltas. The returned RouterResult.text is authoritative;
cache hits return it without deltas. Text events are not retained in result.events.
Truncated, blocked and interrupted responses are never cached. Existing calls stay
non-streaming. Both paths share keys, model selection, auth fallback and the ledger.
Service-style (no Python): REST /v1/complete + /v1/quota on the gemini-mcp daemon.
Native Gemini API pass-through
GEMINI_ROUTER_PROXY_TOKEN=$(openssl rand -hex 32) gemini-router proxy # 127.0.0.1:8787
Then, on the client machine, GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:8787 (through an
SSH tunnel) plus GEMINI_API_KEY=<the token> — no change to the client's code. The base
URL must be a bare origin with no path prefix; see SPEC §11.
Conventions: English in files, Conventional Commits, SemVer tags v* (gemini-mcp pins
a tag), CI = ruff + pytest with mocked HTTP (see AGENTS.md).
Metadata
Release files for gemini-router 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Loss of provenance
These files do not have provenance metadata, despite files in a prior release including this data.
We recommend further investigation before installing these files. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gemini_router-0.8.1.tar.gz | 147.1 kB | Without provenance | Details for gemini_router-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gemini_router-0.8.1-py3-none-any.whl | Python 3 | none | any | Details for gemini_router-0.8.1-py3-none-any.whl |
Total release size: 207.9 kB
Release files / gemini_router-0.8.1.tar.gz
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | gemini_router-0.8.1.tar.gz |
|---|---|
| Size | 147.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ea5329181f555c7d39e39abf86da1fa2d4630dd0f24f7189fb4a68269a2c96a
|
|
BLAKE2b-256 checksum How to use checksums |
6275f2659a012a292400aa7e3ee472b9c6c33cef2811dae5bf521abeb3849442
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / gemini_router-0.8.1-py3-none-any.whl
Loss of provenance
This file belongs to a release without provenance metadata, despite a prior release including this data.
We recommend further investigation before installing this file. View details.
| Download URL | gemini_router-0.8.1-py3-none-any.whl |
|---|---|
| Size | 60.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f84d7a23f45ae6e458de34a52f3d9e8769ad5c862ada6cfa502509e92944452e
|
|
BLAKE2b-256 checksum How to use checksums |
32b08fc695058b0e24350ad9d7a1b3d814689fc759d4ef4cb644304e1c9a34a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for gemini-router 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Loss of provenance
A previous release of these files had provenance metadata, but this release does not.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Release comparison
- Removed 0.5.2 2 files With provenance
- Added 0.8.1 2 files Without provenance
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.