TsgcWSRateLimiter › Methods › IsAllowed
Returns True if a request of the given cost is allowed for the specified key.
function IsAllowed(const aKey: string; aCost: Integer = 1): Boolean;
| Name | Type | Description |
|---|---|---|
aKey | const string | Rate-limit key to evaluate (for example an IP address, apikey:XXX or user:alice@example.com). Matching against PerEndpoint/PerAPIKey/PerUser/PerIP is based on this value. |
aCost | Integer | Number of tokens (or window slots) the request should consume. Defaults to 1. Use a higher cost for expensive operations so a single call counts as several against the budget. |
Returns True if the request would be allowed, False if it would be throttled. (Boolean)
Equivalent to calling Consume(aKey, aCost) and inspecting only the Allowed field of the result — but IsAllowed also updates the counters and fires OnThrottled when the request is rejected. Returns True immediately when Enabled is False. Call this from custom request handlers where you do not need the RetryAfterSec / Remaining / Reason fields that Consume returns.
if not sgcWSRateLimiter1.IsAllowed('apikey:' + ApiKey) then
raise Exception.Create('Too many requests');
// proceed with expensive operation