Turn per-user token quota off by default; keep code for later

This commit is contained in:
2026-08-21 12:51:29 -07:00
parent f1200b7d79
commit fac6e7f356
4 changed files with 54 additions and 39 deletions

View File

@@ -128,15 +128,14 @@ The `.gitignore` file excludes `node_modules` and common system files from commi
## Deploy for the whole company
Use this when the tool needs to be reachable by anyone on the internal network or VPN, not just on one person's machine. This uses a company-owned Anthropic API key shared by everyone who reaches the tool, so it adds a per-person login, a per-person daily token quota, and a request cap that a solo local setup does not need.
Use this when the tool needs to be reachable by anyone on the internal network or VPN, not just on one person's machine. This uses a company-owned Anthropic API key shared by everyone who reaches the tool, so it adds a per-person login and a request cap that a solo local setup does not need.
1. Get an Anthropic API key billed to a company account, not a personal one. IT or finance should provision this, since it is billed like any other company vendor cost.
2. Decide who needs their own login. Each name gets its own password and its own daily token quota, tracked separately.
2. Decide who needs their own login. Each name gets its own password.
3. On the host or container platform, set these values as environment variables, or in a `.env` file next to `docker-compose.yml`:
```
ANTHROPIC_API_KEY=<company key>
APP_USERS=alice:pass1,bob:pass2,carol:pass3
TOKEN_LIMIT_PER_USER=50000
```
4. Build and run the container:
```
@@ -152,13 +151,13 @@ Use this when the tool needs to be reachable by anyone on the internal network o
- It is a shared-credential list, not a real identity system. Anyone who has a name's password can use that name's quota. If real single-sign-on attribution matters later, that needs a larger integration than this tool currently supports.
- Old single-shared-login setups still work: set `APP_USERNAME` and `APP_PASSWORD` instead of `APP_USERS` if you want everyone to share one login and one quota, unchanged from before this feature existed.
### Per-user token quota
### Per-user token quota (built, currently off)
`TOKEN_LIMIT_PER_USER` caps combined input and output tokens per named user, per UTC calendar day. Default: 50000 tokens/day, which is roughly 100 to 200 AI drafts with this tool's prompt size. A user who hits the cap gets a clear error naming their usage and the time until reset, instead of a silent failure or an unexplained cost.
This tool can cap combined input and output tokens per named user, per UTC calendar day, but it ships disabled. A rough cost analysis against this tool's own baseline usage (a workshop session drafts around 6 to 10 breadcrumbs, using roughly 15 to 25 percent of a 50000-token daily allowance) showed the spend at stake is small enough, and the number of people and sessions low enough, that the quota was not worth the added complexity for now. The code stays in place in case usage grows.
Usage is written to `TOKEN_USAGE_FILE` (default `./data/token-usage.json`) after every AI call. In Docker, `docker-compose.yml` mounts `./data` as a volume so this file survives a restart or redeploy. If you remove that volume mount, usage resets to zero every time the container restarts, which defeats the point of a daily cap.
To turn it on: set `TOKEN_LIMIT_PER_USER` to a positive number of tokens (for example 50000) in `.env`. Leave it unset or `0` for unlimited, which is the default, and which also skips writing a usage file at all.
To reset one person's quota early, stop the container, edit their entry out of the usage file (or set its `date` to any past date), and restart. To raise or lower the cap for everyone, change `TOKEN_LIMIT_PER_USER` and restart; the change applies from that point on, not retroactively.
Once enabled, usage is written to `TOKEN_USAGE_FILE` (default `./data/token-usage.json`) after every AI call. In Docker, `docker-compose.yml` already mounts `./data` as a volume, so usage survives a restart or redeploy once you turn this on. A user who hits the cap gets a clear error naming their usage and the time until reset, instead of a silent failure or an unexplained cost. To reset one person's quota early, stop the container, edit their entry out of the usage file (or set its `date` to any past date), and restart. To raise or lower the cap for everyone, change `TOKEN_LIMIT_PER_USER` and restart; the change applies from that point on, not retroactively.
### Rate limit