---
id: w7/m3/t004
title: "Env knobs for limits, documented + mirrored in .env.example / .env.template"
worker: worker7
status: done
estimate: 30m
depends_on: [w7/m3/t002]
---

## Objective

Make the budgets operable: env vars (e.g. `BEX_API_RATE_RPS`, `BEX_API_RATE_BURST`, `BEX_API_MAX_BODY`, `BEX_API_MAX_SSE`) with the code defaults from t001, parsed in bex-api's main, documented in the CLAUDE.md env table, and mirrored name-only into `.env.example` and `.env.template` per the repo sync rule.

## Context

- Env parsing lives in `lego/backend/cmd/api/main.go` (`envOr` pattern).
- Repo rule (CLAUDE.md): `.env.example`/`.env.template` mirror `.env`'s variable *names* — never values; keep all three aligned when adding vars.
- Unset ⇒ the documented defaults apply (limits on by default — an unset var must not mean "unlimited", unlike the opt-in integrations).

## Steps

1. Add the knobs in `main.go`, thread them into the t002 limiter + t003 caps.
2. Add rows to CLAUDE.md's env table; mirror names+comments into `.env.example` and `.env.template`.
3. Set one override on the mock cluster deployment and verify it takes effect.

## Files

- `lego/backend/cmd/api/main.go`
- `CLAUDE.md` (env table), `.env.example`, `.env.template`

## Acceptance criteria

- [ ] Overriding a knob observably changes the enforced limit
- [ ] Unset vars ⇒ documented defaults (not unlimited)
- [ ] CLAUDE.md table + both env mirrors updated in the same change

## Out of scope

- Per-plan budgets; prod value tuning (ops follow-up once real traffic exists)
