gemini-usage-limits 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gemini_usage_limits-0.1.0/LICENSE +21 -0
- gemini_usage_limits-0.1.0/MANIFEST.in +1 -0
- gemini_usage_limits-0.1.0/PKG-INFO +231 -0
- gemini_usage_limits-0.1.0/README.md +211 -0
- gemini_usage_limits-0.1.0/pyproject.toml +33 -0
- gemini_usage_limits-0.1.0/setup.cfg +4 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/__init__.py +3 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/__main__.py +8 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/api.py +194 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/auth.py +56 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/cli.py +62 -0
- gemini_usage_limits-0.1.0/src/gemini_usage/report.py +179 -0
- gemini_usage_limits-0.1.0/src/gemini_usage_limits.egg-info/PKG-INFO +231 -0
- gemini_usage_limits-0.1.0/src/gemini_usage_limits.egg-info/SOURCES.txt +22 -0
- gemini_usage_limits-0.1.0/src/gemini_usage_limits.egg-info/dependency_links.txt +1 -0
- gemini_usage_limits-0.1.0/src/gemini_usage_limits.egg-info/entry_points.txt +2 -0
- gemini_usage_limits-0.1.0/src/gemini_usage_limits.egg-info/top_level.txt +1 -0
- gemini_usage_limits-0.1.0/tests/conftest.py +49 -0
- gemini_usage_limits-0.1.0/tests/fixtures/agy_usage.tsv +4 -0
- gemini_usage_limits-0.1.0/tests/fixtures/load_code_assist.json +10 -0
- gemini_usage_limits-0.1.0/tests/fixtures/quota_summary.json +45 -0
- gemini_usage_limits-0.1.0/tests/test_auth.py +91 -0
- gemini_usage_limits-0.1.0/tests/test_report.py +170 -0
- gemini_usage_limits-0.1.0/tests/test_sources.py +327 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gemini-usage contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include tests *.py *.json *.tsv
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gemini-usage-limits
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI for Antigravity plan usage and rate limits, with Antigravity CLI fallback and warning thresholds.
|
|
5
|
+
Author: gemini-usage contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/javaisbetterthanpython/gemini-usage
|
|
8
|
+
Project-URL: Issues, https://github.com/javaisbetterthanpython/gemini-usage/issues
|
|
9
|
+
Keywords: gemini,google,antigravity,usage,rate-limit,weekly-usage,subscription,cli
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
<h1 align="center">๐ gemini-usage</h1>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<b>Your Antigravity plan limits โ right from your terminal.</b>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<a href="https://pypi.org/project/gemini-usage-limits/"><img alt="PyPI" src="https://img.shields.io/pypi/v/gemini-usage-limits?color=blue&label=PyPI"></a>
|
|
29
|
+
<img alt="Python" src="https://img.shields.io/badge/python-3.9%2B-blue">
|
|
30
|
+
<img alt="Platforms" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey">
|
|
31
|
+
<img alt="Dependencies" src="https://img.shields.io/badge/dependencies-zero-brightgreen">
|
|
32
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<img src="https://raw.githubusercontent.com/javaisbetterthanpython/gemini-usage/main/docs/demo.gif" alt="gemini-usage demo" width="760">
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
Antigravity shows your plan limits with its `/usage` command.
|
|
42
|
+
**`gemini-usage` gives you plan usage from the shell**, for scripts, hooks, and
|
|
43
|
+
AI agents deciding when to back off. It uses the Antigravity login already on
|
|
44
|
+
your machine.
|
|
45
|
+
|
|
46
|
+
The 5-hour and weekly windows cover Gemini models and Claude/GPT models in
|
|
47
|
+
separate groups.
|
|
48
|
+
|
|
49
|
+
**Install `gemini-usage-limits` from PyPI for the `gemini-usage` command.**
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
$ gemini-usage
|
|
53
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
54
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
55
|
+
Claude/GPT 5-hour: 0% used
|
|
56
|
+
Claude/GPT 7-day: 0% used
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## โจ Features
|
|
60
|
+
|
|
61
|
+
- **โฑ๏ธ Usage windows** with 5-hour and weekly percentages and local reset times for each group.
|
|
62
|
+
- **๐ฆ Thresholds for scripts** with `--warn [N]` for any window and `--warn-7d [N]` for the Gemini weekly window. Both exit 1 at or above N%.
|
|
63
|
+
- **๐ Extra detail** with model group descriptions and the plan when available through `--all`.
|
|
64
|
+
- **๐ Antigravity CLI fallback** through `agy -p /usage` when the direct endpoint path fails.
|
|
65
|
+
- **๐งพ Plain, JSON, or short** output for terminals and scripts.
|
|
66
|
+
- **๐ Cross-platform** with keyring access on macOS and Linux and CLI fallback on Windows.
|
|
67
|
+
- **๐ Zero dependencies** beyond the Python 3.9+ standard library.
|
|
68
|
+
- **๐ Local & private** with existing login credentials sent only to Google's Antigravity endpoint.
|
|
69
|
+
|
|
70
|
+
## ๐ Quickstart
|
|
71
|
+
|
|
72
|
+
Install Antigravity and run `agy` once to sign in with Google.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
curl -fsSL https://antigravity.google/cli/install.sh | bash
|
|
76
|
+
agy
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
After signing in, install and run the usage CLI.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install gemini-usage-limits
|
|
83
|
+
gemini-usage
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## ๐งโ๐ป Usage
|
|
87
|
+
|
|
88
|
+
| Command | What it does |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `gemini-usage` | Available usage windows and their reset times |
|
|
91
|
+
| `gemini-usage --json` | Raw quota-only JSON (alias for `--format json`) |
|
|
92
|
+
| `gemini-usage --warn [N]` | Exit 1 when any usage window reaches N% (default 70) |
|
|
93
|
+
| `gemini-usage --warn-7d [N]` | Exit 1 at or above N% of the Gemini 7-day window (default 70) |
|
|
94
|
+
| `gemini-usage --all` | Add group descriptions and the plan in plain format |
|
|
95
|
+
| `gemini-usage --format {plain,json,short}` | Choose output format (default plain) |
|
|
96
|
+
| `gemini-usage -v`, `--verbose` | Print credential and usage sources and the plan, when available, to stderr |
|
|
97
|
+
| `gemini-usage -V`, `--version` | Print the version |
|
|
98
|
+
| `gemini-usage -h`, `--help` | Show help |
|
|
99
|
+
|
|
100
|
+
Flags combine as in `gemini-usage --format short --warn 70 --warn-7d 90`.
|
|
101
|
+
The last of `--json` and `--format` wins. `--all` adds detail in plain format.
|
|
102
|
+
Group descriptions come from the quota endpoint and the plan comes from a
|
|
103
|
+
separate lookup.
|
|
104
|
+
|
|
105
|
+
<details>
|
|
106
|
+
<summary><b>๐ Example ยท <code>--all</code></b></summary>
|
|
107
|
+
|
|
108
|
+
```text
|
|
109
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
110
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
111
|
+
Claude/GPT 5-hour: 0% used
|
|
112
|
+
Claude/GPT 7-day: 0% used
|
|
113
|
+
Gemini: Models within this group: Gemini 4 Neon, Gemini 4 Carbon, Gemini 4 Argon, Gemini 4 Hydrogen, Gemini 3.8 Flash
|
|
114
|
+
Claude/GPT: Models within this group: Claude Opus 5.5, Claude Sonnet 5.5, GPT-OSS 120B
|
|
115
|
+
plan Google AI Pro
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
</details>
|
|
119
|
+
|
|
120
|
+
## ๐ค Using it from scripts and agents
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
gemini-usage --warn 70 || echo "back off"
|
|
124
|
+
gemini-usage --warn 70 --warn-7d 90 --format short
|
|
125
|
+
gemini-usage --json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The usual output is printed even when a threshold trips. Exit code **0** means
|
|
129
|
+
success, **1** means a threshold tripped or no source answered, and **2** means
|
|
130
|
+
an argument error. Both warning thresholds are inclusive and compare the
|
|
131
|
+
source percentage before rounding for display. `--warn` includes all reported
|
|
132
|
+
windows, and `--warn-7d` checks the Gemini weekly window when present.
|
|
133
|
+
|
|
134
|
+
## ๐ Antigravity CLI fallback
|
|
135
|
+
|
|
136
|
+
The direct request needs a current access token. When it is expired or the
|
|
137
|
+
endpoint path fails, the CLI runs `agy -p /usage --print-timeout 60s` once in a
|
|
138
|
+
temporary directory. Antigravity refreshes its own credential as needed. The
|
|
139
|
+
fallback uses whole percentages from its tab-separated output.
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
$ gemini-usage
|
|
143
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
144
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
145
|
+
Claude/GPT 5-hour: 0% used
|
|
146
|
+
Claude/GPT 7-day: 0% used
|
|
147
|
+
(from the agy CLI)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
With `--format short`, each group and window fits on one line.
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
Gemini 5h 1% ยท Gemini 7d 18% ยท Claude/GPT 5h 0% ยท Claude/GPT 7d 0%
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## ๐ค How it works
|
|
157
|
+
|
|
158
|
+
Sources are tried in this order.
|
|
159
|
+
|
|
160
|
+
1. `last-usage.json` if less than **5 minutes** old.
|
|
161
|
+
2. One live `POST https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary`, saved on success.
|
|
162
|
+
3. One Antigravity `/usage` run.
|
|
163
|
+
4. `last-usage.json` if less than **60 minutes** old.
|
|
164
|
+
|
|
165
|
+
The quota cache lives in `~/.gemini-usage`, or `GEMINI_USAGE_HOME` when set.
|
|
166
|
+
Cache writes are atomic. Cached answers at least a minute old show their source
|
|
167
|
+
and age, for example `(from the endpoint, 3 min ago)`. If all sources fail, the
|
|
168
|
+
distinct reasons appear on stderr with a sign-in hint.
|
|
169
|
+
|
|
170
|
+
The direct quota request has a 15-second timeout. `-v` and plain `--all` can
|
|
171
|
+
make one additional request for the plan using the available Antigravity login.
|
|
172
|
+
|
|
173
|
+
<details>
|
|
174
|
+
<summary><b>๐ Where credentials live (per OS)</b></summary>
|
|
175
|
+
|
|
176
|
+
| OS | Credential source |
|
|
177
|
+
|---|---|
|
|
178
|
+
| macOS | Antigravity's system Keychain entry |
|
|
179
|
+
| Linux | Antigravity's Secret Service entry through `secret-tool`, when available |
|
|
180
|
+
| Windows | The signed-in Antigravity CLI via the fallback |
|
|
181
|
+
|
|
182
|
+
For the protocol and a recipe to rebuild the tool, see
|
|
183
|
+
**[docs/HOW_THIS_WAS_BUILT.md](docs/HOW_THIS_WAS_BUILT.md)**.
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
## ๐ Privacy & security
|
|
187
|
+
|
|
188
|
+
- Reads the existing Antigravity login. Antigravity handles token refresh.
|
|
189
|
+
- Sends the access token only to **`daily-cloudcode-pa.googleapis.com`** in direct requests.
|
|
190
|
+
- Keeps only quota fields in the cache and JSON output. The plan lookup extracts the tier name for display.
|
|
191
|
+
- Keeps tokens, request headers, and email addresses out of errors and verbose output.
|
|
192
|
+
- **No telemetry or third-party calls from this CLI.**
|
|
193
|
+
|
|
194
|
+
## โ ๏ธ Good to know
|
|
195
|
+
|
|
196
|
+
- The quota endpoint is **undocumented** and its format may change.
|
|
197
|
+
- Both sources need a signed-in Antigravity CLI and an eligible account.
|
|
198
|
+
- The direct request uses Antigravity's versioned User-Agent to receive the Gemini group.
|
|
199
|
+
- An unused window can have no reset time. The CLI omits the reset clause for it.
|
|
200
|
+
|
|
201
|
+
## ๐ ๏ธ Install options
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
pip install gemini-usage-limits # from PyPI
|
|
205
|
+
pipx install gemini-usage-limits # isolated command installation
|
|
206
|
+
pip install . # from a local clone
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Requires Python 3.9+. **The PyPI distribution is `gemini-usage-limits`. The command
|
|
210
|
+
and GitHub repo are `gemini-usage`, and the import package is `gemini_usage`.**
|
|
211
|
+
|
|
212
|
+
## ๐ค Contributing
|
|
213
|
+
|
|
214
|
+
Issues and PRs are welcome. After installing the local project with `pip install -e .`,
|
|
215
|
+
run the tests with the following command.
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
pip install pytest && pytest -q
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Tests use temporary directories and mocked HTTP and subprocesses. They never
|
|
222
|
+
contact the endpoint or read real credentials.
|
|
223
|
+
|
|
224
|
+
Regenerate the demo with `python3 docs/record_demo.py` after installing
|
|
225
|
+
[agg](https://github.com/asciinema/agg/releases) and the DejaVu Sans Mono font.
|
|
226
|
+
The recorder uses illustrative quota data with HTTP and credential access
|
|
227
|
+
disabled. The README embeds the resulting `docs/demo.gif`.
|
|
228
|
+
|
|
229
|
+
## ๐ License
|
|
230
|
+
|
|
231
|
+
[MIT](LICENSE) โ do whatever you like.
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
<h1 align="center">๐ gemini-usage</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>Your Antigravity plan limits โ right from your terminal.</b>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/gemini-usage-limits/"><img alt="PyPI" src="https://img.shields.io/pypi/v/gemini-usage-limits?color=blue&label=PyPI"></a>
|
|
9
|
+
<img alt="Python" src="https://img.shields.io/badge/python-3.9%2B-blue">
|
|
10
|
+
<img alt="Platforms" src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-lightgrey">
|
|
11
|
+
<img alt="Dependencies" src="https://img.shields.io/badge/dependencies-zero-brightgreen">
|
|
12
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="https://raw.githubusercontent.com/javaisbetterthanpython/gemini-usage/main/docs/demo.gif" alt="gemini-usage demo" width="760">
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
Antigravity shows your plan limits with its `/usage` command.
|
|
22
|
+
**`gemini-usage` gives you plan usage from the shell**, for scripts, hooks, and
|
|
23
|
+
AI agents deciding when to back off. It uses the Antigravity login already on
|
|
24
|
+
your machine.
|
|
25
|
+
|
|
26
|
+
The 5-hour and weekly windows cover Gemini models and Claude/GPT models in
|
|
27
|
+
separate groups.
|
|
28
|
+
|
|
29
|
+
**Install `gemini-usage-limits` from PyPI for the `gemini-usage` command.**
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
$ gemini-usage
|
|
33
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
34
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
35
|
+
Claude/GPT 5-hour: 0% used
|
|
36
|
+
Claude/GPT 7-day: 0% used
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## โจ Features
|
|
40
|
+
|
|
41
|
+
- **โฑ๏ธ Usage windows** with 5-hour and weekly percentages and local reset times for each group.
|
|
42
|
+
- **๐ฆ Thresholds for scripts** with `--warn [N]` for any window and `--warn-7d [N]` for the Gemini weekly window. Both exit 1 at or above N%.
|
|
43
|
+
- **๐ Extra detail** with model group descriptions and the plan when available through `--all`.
|
|
44
|
+
- **๐ Antigravity CLI fallback** through `agy -p /usage` when the direct endpoint path fails.
|
|
45
|
+
- **๐งพ Plain, JSON, or short** output for terminals and scripts.
|
|
46
|
+
- **๐ Cross-platform** with keyring access on macOS and Linux and CLI fallback on Windows.
|
|
47
|
+
- **๐ Zero dependencies** beyond the Python 3.9+ standard library.
|
|
48
|
+
- **๐ Local & private** with existing login credentials sent only to Google's Antigravity endpoint.
|
|
49
|
+
|
|
50
|
+
## ๐ Quickstart
|
|
51
|
+
|
|
52
|
+
Install Antigravity and run `agy` once to sign in with Google.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
curl -fsSL https://antigravity.google/cli/install.sh | bash
|
|
56
|
+
agy
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
After signing in, install and run the usage CLI.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install gemini-usage-limits
|
|
63
|
+
gemini-usage
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## ๐งโ๐ป Usage
|
|
67
|
+
|
|
68
|
+
| Command | What it does |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `gemini-usage` | Available usage windows and their reset times |
|
|
71
|
+
| `gemini-usage --json` | Raw quota-only JSON (alias for `--format json`) |
|
|
72
|
+
| `gemini-usage --warn [N]` | Exit 1 when any usage window reaches N% (default 70) |
|
|
73
|
+
| `gemini-usage --warn-7d [N]` | Exit 1 at or above N% of the Gemini 7-day window (default 70) |
|
|
74
|
+
| `gemini-usage --all` | Add group descriptions and the plan in plain format |
|
|
75
|
+
| `gemini-usage --format {plain,json,short}` | Choose output format (default plain) |
|
|
76
|
+
| `gemini-usage -v`, `--verbose` | Print credential and usage sources and the plan, when available, to stderr |
|
|
77
|
+
| `gemini-usage -V`, `--version` | Print the version |
|
|
78
|
+
| `gemini-usage -h`, `--help` | Show help |
|
|
79
|
+
|
|
80
|
+
Flags combine as in `gemini-usage --format short --warn 70 --warn-7d 90`.
|
|
81
|
+
The last of `--json` and `--format` wins. `--all` adds detail in plain format.
|
|
82
|
+
Group descriptions come from the quota endpoint and the plan comes from a
|
|
83
|
+
separate lookup.
|
|
84
|
+
|
|
85
|
+
<details>
|
|
86
|
+
<summary><b>๐ Example ยท <code>--all</code></b></summary>
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
90
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
91
|
+
Claude/GPT 5-hour: 0% used
|
|
92
|
+
Claude/GPT 7-day: 0% used
|
|
93
|
+
Gemini: Models within this group: Gemini 4 Neon, Gemini 4 Carbon, Gemini 4 Argon, Gemini 4 Hydrogen, Gemini 3.8 Flash
|
|
94
|
+
Claude/GPT: Models within this group: Claude Opus 5.5, Claude Sonnet 5.5, GPT-OSS 120B
|
|
95
|
+
plan Google AI Pro
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
</details>
|
|
99
|
+
|
|
100
|
+
## ๐ค Using it from scripts and agents
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
gemini-usage --warn 70 || echo "back off"
|
|
104
|
+
gemini-usage --warn 70 --warn-7d 90 --format short
|
|
105
|
+
gemini-usage --json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The usual output is printed even when a threshold trips. Exit code **0** means
|
|
109
|
+
success, **1** means a threshold tripped or no source answered, and **2** means
|
|
110
|
+
an argument error. Both warning thresholds are inclusive and compare the
|
|
111
|
+
source percentage before rounding for display. `--warn` includes all reported
|
|
112
|
+
windows, and `--warn-7d` checks the Gemini weekly window when present.
|
|
113
|
+
|
|
114
|
+
## ๐ Antigravity CLI fallback
|
|
115
|
+
|
|
116
|
+
The direct request needs a current access token. When it is expired or the
|
|
117
|
+
endpoint path fails, the CLI runs `agy -p /usage --print-timeout 60s` once in a
|
|
118
|
+
temporary directory. Antigravity refreshes its own credential as needed. The
|
|
119
|
+
fallback uses whole percentages from its tab-separated output.
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
$ gemini-usage
|
|
123
|
+
Gemini 5-hour: 1% used, resets 21:18 (in 4h44m)
|
|
124
|
+
Gemini 7-day: 18% used, resets Tue 19:33 (in 146h58m)
|
|
125
|
+
Claude/GPT 5-hour: 0% used
|
|
126
|
+
Claude/GPT 7-day: 0% used
|
|
127
|
+
(from the agy CLI)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
With `--format short`, each group and window fits on one line.
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Gemini 5h 1% ยท Gemini 7d 18% ยท Claude/GPT 5h 0% ยท Claude/GPT 7d 0%
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## ๐ค How it works
|
|
137
|
+
|
|
138
|
+
Sources are tried in this order.
|
|
139
|
+
|
|
140
|
+
1. `last-usage.json` if less than **5 minutes** old.
|
|
141
|
+
2. One live `POST https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary`, saved on success.
|
|
142
|
+
3. One Antigravity `/usage` run.
|
|
143
|
+
4. `last-usage.json` if less than **60 minutes** old.
|
|
144
|
+
|
|
145
|
+
The quota cache lives in `~/.gemini-usage`, or `GEMINI_USAGE_HOME` when set.
|
|
146
|
+
Cache writes are atomic. Cached answers at least a minute old show their source
|
|
147
|
+
and age, for example `(from the endpoint, 3 min ago)`. If all sources fail, the
|
|
148
|
+
distinct reasons appear on stderr with a sign-in hint.
|
|
149
|
+
|
|
150
|
+
The direct quota request has a 15-second timeout. `-v` and plain `--all` can
|
|
151
|
+
make one additional request for the plan using the available Antigravity login.
|
|
152
|
+
|
|
153
|
+
<details>
|
|
154
|
+
<summary><b>๐ Where credentials live (per OS)</b></summary>
|
|
155
|
+
|
|
156
|
+
| OS | Credential source |
|
|
157
|
+
|---|---|
|
|
158
|
+
| macOS | Antigravity's system Keychain entry |
|
|
159
|
+
| Linux | Antigravity's Secret Service entry through `secret-tool`, when available |
|
|
160
|
+
| Windows | The signed-in Antigravity CLI via the fallback |
|
|
161
|
+
|
|
162
|
+
For the protocol and a recipe to rebuild the tool, see
|
|
163
|
+
**[docs/HOW_THIS_WAS_BUILT.md](docs/HOW_THIS_WAS_BUILT.md)**.
|
|
164
|
+
</details>
|
|
165
|
+
|
|
166
|
+
## ๐ Privacy & security
|
|
167
|
+
|
|
168
|
+
- Reads the existing Antigravity login. Antigravity handles token refresh.
|
|
169
|
+
- Sends the access token only to **`daily-cloudcode-pa.googleapis.com`** in direct requests.
|
|
170
|
+
- Keeps only quota fields in the cache and JSON output. The plan lookup extracts the tier name for display.
|
|
171
|
+
- Keeps tokens, request headers, and email addresses out of errors and verbose output.
|
|
172
|
+
- **No telemetry or third-party calls from this CLI.**
|
|
173
|
+
|
|
174
|
+
## โ ๏ธ Good to know
|
|
175
|
+
|
|
176
|
+
- The quota endpoint is **undocumented** and its format may change.
|
|
177
|
+
- Both sources need a signed-in Antigravity CLI and an eligible account.
|
|
178
|
+
- The direct request uses Antigravity's versioned User-Agent to receive the Gemini group.
|
|
179
|
+
- An unused window can have no reset time. The CLI omits the reset clause for it.
|
|
180
|
+
|
|
181
|
+
## ๐ ๏ธ Install options
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install gemini-usage-limits # from PyPI
|
|
185
|
+
pipx install gemini-usage-limits # isolated command installation
|
|
186
|
+
pip install . # from a local clone
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Requires Python 3.9+. **The PyPI distribution is `gemini-usage-limits`. The command
|
|
190
|
+
and GitHub repo are `gemini-usage`, and the import package is `gemini_usage`.**
|
|
191
|
+
|
|
192
|
+
## ๐ค Contributing
|
|
193
|
+
|
|
194
|
+
Issues and PRs are welcome. After installing the local project with `pip install -e .`,
|
|
195
|
+
run the tests with the following command.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
pip install pytest && pytest -q
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Tests use temporary directories and mocked HTTP and subprocesses. They never
|
|
202
|
+
contact the endpoint or read real credentials.
|
|
203
|
+
|
|
204
|
+
Regenerate the demo with `python3 docs/record_demo.py` after installing
|
|
205
|
+
[agg](https://github.com/asciinema/agg/releases) and the DejaVu Sans Mono font.
|
|
206
|
+
The recorder uses illustrative quota data with HTTP and credential access
|
|
207
|
+
disabled. The README embeds the resulting `docs/demo.gif`.
|
|
208
|
+
|
|
209
|
+
## ๐ License
|
|
210
|
+
|
|
211
|
+
[MIT](LICENSE) โ do whatever you like.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gemini-usage-limits"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "CLI for Antigravity plan usage and rate limits, with Antigravity CLI fallback and warning thresholds."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "gemini-usage contributors" }]
|
|
14
|
+
keywords = ["gemini", "google", "antigravity", "usage", "rate-limit", "weekly-usage", "subscription", "cli"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Utilities",
|
|
22
|
+
]
|
|
23
|
+
dependencies = []
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
gemini-usage = "gemini_usage.cli:main"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/javaisbetterthanpython/gemini-usage"
|
|
30
|
+
Issues = "https://github.com/javaisbetterthanpython/gemini-usage/issues"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|