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.
Status
v0.1.1 implemented (milestone M1 of the
gemini-mcp plan):
library + CLI, 45 tests green, CI on push. Contract: docs/SPEC.md.
Planned usage
from gemini_router import Router, RouterRequest
router = Router.from_env()
res = await router.complete(RouterRequest(prompt=..., thinking_level="high"),
on_event=print)
uv add "gemini-router @ git+https://github.com/vernikr/gemini-router.git@v1.0.0"
gemini-router quota # RPD left / RPM & TPM windows / cooldowns / next recommendation
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gemini_router-0.1.1.tar.gz | 45.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gemini_router-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.6 kB
Release files / gemini_router-0.1.1.tar.gz
| Download URL | gemini_router-0.1.1.tar.gz |
|---|---|
| Size | 45.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfe2468ce1e8aebec51c1f2aefcd8f6b9f8a35ebd8747ed4c73b583bd82006c9
|
|
BLAKE2b-256 checksum How to use checksums |
634b2e58815d251bcd7f6ec7ac0504e21a375dd55452e7f958fdd0ce124d1d37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"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.1-py3-none-any.whl
| Download URL | gemini_router-0.1.1-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07312776ad576622dff9758f95983f2b9a51b609acff0eeaa30f2a055280ed6d
|
|
BLAKE2b-256 checksum How to use checksums |
fdfc5f72c22726fc517f800928050dc7562faa07c98b847f026e4fb14211b179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|