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), 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.3.5
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.3.5.tar.gz | 101.1 kB | With provenance | Details for gemini_router-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gemini_router-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for gemini_router-0.3.5-py3-none-any.whl |
Total release size: 142.0 kB
Release files / gemini_router-0.3.5.tar.gz
| Download URL | gemini_router-0.3.5.tar.gz |
|---|---|
| Size | 101.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15321390e312457f0684fce0e3d2dc07bfdba46e9042c9db4a075281154b6f94
|
|
BLAKE2b-256 checksum How to use checksums |
eba936a75c1e9a9468862fa026329910cd0d6c417d92cf49e59ec68415d99324
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logRelease files / gemini_router-0.3.5-py3-none-any.whl
| Download URL | gemini_router-0.3.5-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67c9bdddae891ef4c4210d129b958f2851968c6ba158f43a22da189f6bbcc3bc
|
|
BLAKE2b-256 checksum How to use checksums |
99c92927595048dc8630da529e57adcb1801e15385949a47c1d81e7fefdc4895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logSecurity for gemini-router 0.3.5
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for gemini_router-0.3.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logA 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.