<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Quota Tracking on KnightLi Blog</title>
        <link>https://www.knightli.com/en/tags/quota-tracking/</link>
        <description>Recent content in Quota Tracking on KnightLi Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en</language>
        <lastBuildDate>Thu, 16 Apr 2026 18:13:04 +0800</lastBuildDate><atom:link href="https://www.knightli.com/en/tags/quota-tracking/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>codex-quota Practical Guide: Local, Web, and Docker Usage with Original CLI Commands</title>
        <link>https://www.knightli.com/en/2026/04/16/codex-quota-cli-web-docker-guide/</link>
        <pubDate>Thu, 16 Apr 2026 18:13:04 +0800</pubDate>
        
        <guid>https://www.knightli.com/en/2026/04/16/codex-quota-cli-web-docker-guide/</guid>
        <description>&lt;h2 id=&#34;what-this-project-does&#34;&gt;What This Project Does
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;codex-quota&lt;/code&gt; is a lightweight tool for checking ChatGPT Codex quota usage, with data fetched from &lt;code&gt;https://chatgpt.com/backend-api/wham/usage&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Main features:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Supports both single-account and multi-account queries (&lt;code&gt;account/*.auth.json&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Outputs &lt;code&gt;five_hour%&lt;/code&gt;, &lt;code&gt;weekly%&lt;/code&gt;, &lt;code&gt;weekly_reset&lt;/code&gt;, and marks the source (&lt;code&gt;network&lt;/code&gt; or &lt;code&gt;cache&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Uses exponential backoff retries for temporary failures (&lt;code&gt;408&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt;, &lt;code&gt;5xx&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Includes local caching to reduce repeated requests when quota is already exhausted.&lt;/li&gt;
&lt;li&gt;Provides a Web Dashboard, JSON API, and auth file management pages.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Advantages:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Lightweight: runs with simple scripts and minimal dependencies.&lt;/li&gt;
&lt;li&gt;Practical: supports both CLI and Web entry points.&lt;/li&gt;
&lt;li&gt;Deployable: works with Docker and Docker Compose.&lt;/li&gt;
&lt;li&gt;Easy to operate: includes retry, cache, and scheduled refresh support.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;prepare-account-credentials-first&#34;&gt;Prepare Account Credentials First
&lt;/h2&gt;&lt;p&gt;Create credential files in &lt;code&gt;account/&amp;lt;name&amp;gt;.auth.json&lt;/code&gt;, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;3
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;4
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;5
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;6
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-json&#34; data-lang=&#34;json&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nt&#34;&gt;&amp;#34;tokens&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;#34;access_token&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;eyJ...&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nt&#34;&gt;&amp;#34;account_id&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;user-xxxxxxxx&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;access_token&lt;/code&gt; and &lt;code&gt;account_id&lt;/code&gt; are required by the usage API.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt; in the filename is used as the account name in output.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;local-cli-usage-keep-original-commands&#34;&gt;Local CLI Usage (Keep Original Commands)
&lt;/h2&gt;&lt;p&gt;Install dependencies:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pip install -r requirements.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: installs project dependencies.&lt;/p&gt;
&lt;p&gt;Query all accounts:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python codex_quota.py
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: reads &lt;code&gt;account/*.auth.json&lt;/code&gt; and outputs quota summary for all accounts.&lt;/p&gt;
&lt;p&gt;Query one account:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python codex_quota.py your_account_name
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: only queries &lt;code&gt;account/your_account_name.auth.json&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Force refresh (skip cache):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python codex_quota.py --refresh
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: ignores local cache and fetches fresh data directly.&lt;/p&gt;
&lt;h2 id=&#34;cli-options-aligned-with-readme&#34;&gt;CLI Options (Aligned with README)
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;account_name&lt;/code&gt;: optional account name (without &lt;code&gt;.auth.json&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--account-dir&lt;/code&gt;: auth directory, default &lt;code&gt;account&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--chatgpt-url&lt;/code&gt;: quota API endpoint.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--raw-json&lt;/code&gt;: print full JSON response body.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--raw-headers&lt;/code&gt;: print response headers.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--refresh&lt;/code&gt;: ignore cache.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--retries&lt;/code&gt;: retry count, default &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--retry-delay&lt;/code&gt;: base retry delay in seconds, default &lt;code&gt;2.0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;web-dashboard-usage-keep-original-command&#34;&gt;Web Dashboard Usage (Keep Original Command)
&lt;/h2&gt;&lt;p&gt;Start the service:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;python codex_quota_service.py --host 0.0.0.0 --port &lt;span class=&#34;m&#34;&gt;8081&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: starts HTTP service listening on port &lt;code&gt;8081&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Access URL: &lt;code&gt;http://localhost:8081&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Service options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--host&lt;/code&gt;: bind address, default &lt;code&gt;0.0.0.0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--port&lt;/code&gt;: service port, default &lt;code&gt;8081&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--interval-seconds&lt;/code&gt;: scheduled refresh interval, default &lt;code&gt;3600&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--account-dir&lt;/code&gt;: auth directory, default &lt;code&gt;account&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--state-file&lt;/code&gt;: state file path, default &lt;code&gt;&amp;lt;account-dir&amp;gt;/codex_quota_web_results.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--account-name&lt;/code&gt;: optional single-account mode.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--chatgpt-url&lt;/code&gt;: quota API endpoint.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--retries&lt;/code&gt;: retry count.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--retry-delay&lt;/code&gt;: base retry delay.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--refresh&lt;/code&gt;: ignore CLI cache during scheduled runs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;http-endpoints-for-automation&#34;&gt;HTTP Endpoints (For Automation)
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET /&lt;/code&gt;: dashboard page.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /api/results&lt;/code&gt;: latest results in JSON.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /refresh&lt;/code&gt;: trigger immediate refresh and redirect to &lt;code&gt;/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /auth&lt;/code&gt;: list auth files.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /auth/new&lt;/code&gt;: form to create auth file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /auth/edit?name=&amp;lt;account&amp;gt;&lt;/code&gt;: form to edit auth file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;POST /auth/save&lt;/code&gt;: create/update auth file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;POST /auth/delete&lt;/code&gt;: delete auth file.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;docker-usage-keep-original-commands&#34;&gt;Docker Usage (Keep Original Commands)
&lt;/h2&gt;&lt;p&gt;Build image:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker build -t codex-quota .
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: builds the current project as image &lt;code&gt;codex-quota&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Run container (map 8081):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker run --rm -p 8081:8081 -v ./account:/app/account codex-quota
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--rm&lt;/code&gt;: remove container automatically after exit.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-p 8081:8081&lt;/code&gt;: map host port to container port.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-v ./account:/app/account&lt;/code&gt;: mount local credentials into container.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Access URL: &lt;code&gt;http://localhost:8081&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;docker-compose-usage-keep-original-command&#34;&gt;Docker Compose Usage (Keep Original Command)
&lt;/h2&gt;&lt;p&gt;Start:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;docker compose up --build
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Explanation: build and start services based on &lt;code&gt;docker-compose.yml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Access URL: &lt;code&gt;http://localhost:8081&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;usage-tips&#34;&gt;Usage Tips
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;For multi-account scenarios, use Dashboard first for unified view and auth management.&lt;/li&gt;
&lt;li&gt;For alerting or automation, prefer &lt;code&gt;GET /api/results&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Do not commit real &lt;code&gt;access_token&lt;/code&gt; values to public repositories.&lt;/li&gt;
&lt;li&gt;If you see many temporary failures, increase &lt;code&gt;--retries&lt;/code&gt; and &lt;code&gt;--retry-delay&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
</description>
        </item>
        
    </channel>
</rss>
