@@ -11,6 +11,161 @@ target.
1111
1212## [ Unreleased]
1313
14+ ## [ 3.5.0] — 2026-10-11
15+
16+ Limits hold where they used to leak: route caps are enforced, a limits
17+ store that cannot be read follows ` security.rate_limit_fail_closed ` , a
18+ refused model or tool no longer spends a request, a team-scoped role no
19+ longer limits the gateway it does not open, and cached answers count their
20+ tokens. A client can ask the gateway what room its API key has left
21+ (` GET /v1/usage ` ), and an API key's own limits are edited in the console.
22+ The legacy monthly token quota is gone, and the thinkwatch-core crates move
23+ from v0.69.0 to v0.70.0.
24+
25+ ### Read before upgrading
26+
27+ - ** Route caps are enforced.** A route's RPM cap and TPM cap
28+ (` model_routes.rpm_cap ` / ` tpm_cap ` , set in the route editor) were saved
29+ but never applied. They now are, per route over a sliding minute, the TPM
30+ cap in weighted tokens like every other token limit (counted after the
31+ response). A route at either cap is skipped and the model's next route
32+ serves the request; when every route left is at its cap, the request gets
33+ 429 with ` Retry-After ` , labelled ` route:requests/1m ` or
34+ ` route:tokens/1m ` . Such a request has passed the caller's own limits and
35+ counts on them, as a request every upstream fails does. Review the caps
36+ already set on your routes: a cap that did nothing until now takes effect
37+ on upgrade. Routes with a cap write new Redis keys,
38+ ` ratelimit:{route:<route_id>}:ai_gateway:route:… ` .
39+ - ** A limits store that cannot be read follows
40+ ` security.rate_limit_fail_closed ` .** When the database failed while a
41+ request's rate limits and budgets were being loaded, the request ran with
42+ no limits at all; when Redis failed while a budget was being read, the
43+ budget read as unspent. Both now follow the setting, as a Redis failure
44+ in the rate limiter always has, and so do the route caps: off (the
45+ default), the request goes on and a warning with the error is logged
46+ (` gateway_limits_load_fail_open_total ` ,
47+ ` lifecycle_budget_fail_open_total ` ); on, the request is refused, labelled
48+ ` limits_unavailable ` , ` budget_unavailable ` or ` rate_limiter_unavailable `
49+ (on the AI gateway, 429 with ` Retry-After: 30 ` ). With the setting off, a
50+ Redis error used to fail every AI-gateway request anyway, with 502
51+ ` Quota exceeded ` , at the legacy quota check (see Changed); such a request
52+ now goes on, as the setting says. Turn the setting on to keep refusing
53+ requests while Redis is down.
54+ - ** A role granted at team scope no longer limits gateway requests.** Such
55+ a grant administers that team and has never opened a model or an MCP tool
56+ at the gateways, but its rate limits and budgets were applied to every
57+ gateway request of the user who held it. A role's limits now apply
58+ exactly where its gateway grant does: roles assigned globally, and roles
59+ attached to a team the user is a member of. A user who held a limiting
60+ role only at team scope is no longer held to its limits; assign the role
61+ globally, attach it to the team, or set a user limit if they were meant.
62+ - ** Answers from the response cache count their tokens.** A cache hit
63+ counted toward request limits but added no tokens to token limits and
64+ budgets, so repeating a cached request got round them. It now adds the
65+ tokens the cached answer records, weighted like any answer (all of its
66+ input as plain input). The cost a cache hit reports stays 0. Callers that
67+ lean on the cache reach their token limits and budgets sooner.
68+ - ** Each API key and each user get day and month usage counters in Redis.**
69+ An AI-gateway request made with a key now also counts on the key's
70+ ` usage:{user:<owner id>}:api_key_lineage:<lineage id>:daily:<date> ` and
71+ ` …:monthly:<month> ` and on its owner's
72+ ` usage:{user:<owner id>}:user:<owner id>:daily:<date> ` and
73+ ` …:monthly:<month> ` , hashes that expire two periods after their last write.
74+ That is one more Redis script per request once it passes the rate limits,
75+ and one when its tokens are counted, after the call or when it is answered
76+ from the response cache. The counters start empty, so the ` usage ` that
77+ ` GET /v1/usage ` reports counts from the upgrade on. No setting, database
78+ schema or Helm value changes.
79+
80+ ### Added
81+
82+ - ** ` GET /v1/usage ` tells a client what room its API key has left.** Called
83+ on the gateway port with a gateway API key, as a model request is, it
84+ answers about one of two subjects, named in ` scope ` :
85+
86+ - ` "key" ` when the key has limits of its own on the AI gateway: ` limits `
87+ lists only the key's limits, each with ` used ` counted for the key, and
88+ ` usage ` is the key's own (across its rotations).
89+ - ` "user" ` when it has none: ` limits ` lists its owner's effective limits
90+ (roles, including those a team grants, merged most-restrictive, then
91+ the user's overrides), each with ` used ` counted for everything the
92+ owner does, and ` usage ` is the owner's total over all of their keys.
93+ With no limits on the owner either, ` limits ` is empty.
94+
95+ ``` json
96+ {
97+ "scope" : " key" ,
98+ "usage" : {"requests_today" : 12 , "tokens_today" : 48210 ,
99+ "requests_month" : 340 , "tokens_month" : 1290455 ,
100+ "cost_usd_month" : 3.82 },
101+ "limits" : [
102+ {"scope" : " key" , "kind" : " tokens" , "window" : " daily" , "window_secs" : null ,
103+ "limit" : 100000 , "used" : 48210 , "resets_at" : " 2026-10-12T00:00:00Z" },
104+ {"scope" : " key" , "kind" : " requests" , "window" : " 1m" , "window_secs" : 60 ,
105+ "limit" : 60 , "used" : 4 , "resets_at" : null }
106+ ],
107+ "expires_at" : " 2026-12-31T00:00:00Z"
108+ }
109+ ```
110+
111+ ` usage ` holds the requests the rate limits let through and the weighted
112+ tokens limits count, answers from the response cache included, for the
113+ UTC day and month, and the cost this month from the request log (` null `
114+ without ClickHouse). Every limit's ` used ` is read from the counter that
115+ refuses requests, and the one with the least left comes first. ` window `
116+ is a rate limit's sliding window (` 1m ` , ` 5m ` , ` 1h ` , ` 5h ` , ` 1d ` , ` 1w ` , with
117+ its length in ` window_secs ` ) or a budget's calendar period (` daily ` ,
118+ ` weekly ` , ` monthly ` , with its end in ` resets_at ` , UTC). Limits on the MCP
119+ gateway are not listed. ` expires_at ` is the key's expiry or the end of
120+ its rotation grace period, whichever comes first. A key a model request
121+ would refuse gets the same ` 401 ` or ` 403 ` , and ` 503 ` means the key's
122+ limits or their counters could not be read, whichever way
123+ ` security.rate_limit_fail_closed ` is set. Calling it charges no limit, writes no request log row
124+ and is not a use of the key: ` last_used_at ` stays as it was, so polling
125+ does not keep an idle key from its inactivity timeout. Whoever holds a key
126+ without limits of its own sees its owner's totals and limits; a key handed
127+ to someone else should carry limits of its own. The console's
128+ Configuration Guide lists the endpoint with the other gateway endpoints.
129+ - ** An API key's own limits are edited in the console.** The key's edit
130+ dialog has a Limits tab: rate limits (requests or weighted tokens over
131+ 1m, 5m, 1h, 5h, 1d or 1w) and budgets (daily, weekly or monthly weighted
132+ tokens), each with what it has used, added, changed and removed through
133+ the existing limits endpoints. They follow the key across rotations.
134+ Reading needs ` rate_limits:read ` and changing ` rate_limits:write ` , in a
135+ scope that covers the key, as before; without write access the tab is
136+ read-only, and without read access the dialog is unchanged.
137+
138+ ### Fixed
139+
140+ - ** A request the key may not make no longer spends a request limit.** The
141+ rate-limit check, which counts the request, ran before the model check on
142+ the AI gateway and before the tool check on the MCP gateway, so a refused
143+ model or tool used up the caller's ` requests ` limits. Access is now
144+ checked first (after the budget check, which counts nothing).
145+ - ** Route caps are applied** , ** limits and budgets that cannot be read
146+ follow the fail-closed setting** , ** team-scoped roles no longer limit**
147+ and ** cached answers count their tokens** : see Read before upgrading.
148+ - Comments that described a limits cache, a ` limits:changed ` subscriber and
149+ team-level budget caps, none of which exist, now say what happens: limits
150+ are read from the database on every request, nothing subscribes to
151+ ` limits:changed ` , and teams carry no limits of their own.
152+
153+ ### Changed
154+
155+ - ** The legacy monthly token quota is removed.** Every request counted its
156+ tokens into ` quota:{<user or key>:<model>}:used:<YYYY-MM> ` in Redis
157+ against a limit nothing could set, so it never refused anything. The
158+ gateway no longer reads or writes these keys; existing ` quota:* ` keys can
159+ be deleted. Monthly limits are budgets. Its metric,
160+ ` gateway_quota_overflow_total ` , is gone too: the Grafana overview panel
161+ that plotted it shows routes at their cap (` gateway_route_capped_total ` )
162+ instead.
163+ - The ` security.rate_limit_fail_closed ` hint in Settings names everything
164+ the setting now covers.
165+ - thinkwatch-core crates (tw-bedrock, tw-breaker, tw-dialect, tw-guard)
166+ v0.69.0 → v0.70.0. The four crates do not change beyond their version.
167+
168+
14169## [ 3.4.0] — 2026-10-11
15170
16171Conversations with reasoning models behind Chat-format upstreams keep their
@@ -1768,7 +1923,8 @@ unreleased builds should: stop the gateway, run `db/schema.sql`
17681923against PostgreSQL, restart against this tag. The schema is
17691924idempotent end-to-end, so the apply is safe to repeat.
17701925
1771- [ Unreleased ] : https://github.com/ThinkWatchProject/ThinkWatch/compare/v3.4.0...HEAD
1926+ [ Unreleased ] : https://github.com/ThinkWatchProject/ThinkWatch/compare/v3.5.0...HEAD
1927+ [ 3.5.0 ] : https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v3.5.0
17721928[ 3.4.0 ] : https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v3.4.0
17731929[ 3.3.1 ] : https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v3.3.1
17741930[ 3.3.0 ] : https://github.com/ThinkWatchProject/ThinkWatch/releases/tag/v3.3.0
0 commit comments