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) = the single source of quota truth shared by every
consumer on a machine: the gemini-mcp gateway,
tldr-digest cron runs, CLI calls, foreign scripts.
- Cascading chain with runtime
listModelsvalidation (defaultgemini-3.8-flash → 3.7 → 3.6 → 3.5 → 3-flash-preview-slot; config-overridable). - 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), 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(rich tables). - 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)
Service-style (no Python): REST /v1/complete + /v1/quota on the gemini-mcp daemon.
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.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gemini_router-0.1.2.tar.gz | 46.5 kB | Without provenance | Details for gemini_router-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gemini_router-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for gemini_router-0.1.2-py3-none-any.whl |
Total release size: 68.6 kB
Release files / gemini_router-0.1.2.tar.gz
| Download URL | gemini_router-0.1.2.tar.gz |
|---|---|
| Size | 46.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e234855e4d07c25c3ace375a6dec5eaf5b904ee39ce6c80c9da2f1869230f3b7
|
|
BLAKE2b-256 checksum How to use checksums |
717419894b8aed3a76d1f0757f8a7aab3567ef6b83928ca9144d8b6209660fc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / gemini_router-0.1.2-py3-none-any.whl
| Download URL | gemini_router-0.1.2-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51c81a9f697537ae7d9fcb20faf1b2baaf598b5c08e4bc455a9cad39a2a88b90
|
|
BLAKE2b-256 checksum How to use checksums |
2991ac69923d60ed3d280ba4978718dcaa81a28056b91229ff35340b7f1a3aa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for gemini-router 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.