diff --git a/types/defines/ratelimit.d.ts b/types/defines/ratelimit.d.ts index a37ec6013fb..388c45bfad3 100644 --- a/types/defines/ratelimit.d.ts +++ b/types/defines/ratelimit.d.ts @@ -1,5 +1,11 @@ interface RateLimitOptions { key: string + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number } interface RateLimitOutcome { diff --git a/types/generated-snapshot/experimental/index.d.ts b/types/generated-snapshot/experimental/index.d.ts index c319c9c8ea3..d264090f22a 100755 --- a/types/generated-snapshot/experimental/index.d.ts +++ b/types/generated-snapshot/experimental/index.d.ts @@ -16552,6 +16552,12 @@ interface JsonWebKeyWithKid extends JsonWebKey { } interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/experimental/index.ts b/types/generated-snapshot/experimental/index.ts index 27f7240092a..1788008fde9 100755 --- a/types/generated-snapshot/experimental/index.ts +++ b/types/generated-snapshot/experimental/index.ts @@ -16462,6 +16462,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey { } export interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } export interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/index.d.ts b/types/generated-snapshot/index.d.ts index fcd35c5d71e..a206da5399e 100755 --- a/types/generated-snapshot/index.d.ts +++ b/types/generated-snapshot/index.d.ts @@ -16191,6 +16191,12 @@ interface JsonWebKeyWithKid extends JsonWebKey { } interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } interface RateLimitOutcome { success: boolean; diff --git a/types/generated-snapshot/index.ts b/types/generated-snapshot/index.ts index 471fddf0030..98088e9bcd1 100755 --- a/types/generated-snapshot/index.ts +++ b/types/generated-snapshot/index.ts @@ -16104,6 +16104,12 @@ export interface JsonWebKeyWithKid extends JsonWebKey { } export interface RateLimitOptions { key: string; + /** + * Amount to add to the counter for this call. Must be a positive integer; + * defaults to `1`. The call is allowed while the counter is below the limit, + * even if `delta` takes it past the limit. + */ + delta?: number; } export interface RateLimitOutcome { success: boolean; diff --git a/types/test/types/ratelimit.ts b/types/test/types/ratelimit.ts new file mode 100644 index 00000000000..a72d89dbd1e --- /dev/null +++ b/types/test/types/ratelimit.ts @@ -0,0 +1,17 @@ +// Copyright (c) 2026 Cloudflare, Inc. +// Licensed under the Apache 2.0 license found in the LICENSE file or at: +// https://opensource.org/licenses/Apache-2.0 + +function expectType(_value: T) {} + +declare const limiter: RateLimit; + +expectType>(limiter.limit({ key: 'user-123' })); +expectType>( + limiter.limit({ key: 'user-123', delta: 5 }) +); + +// @ts-expect-error `delta` must be a number. +limiter.limit({ key: 'user-123', delta: '5' }); +// @ts-expect-error `key` is required. +limiter.limit({ delta: 5 });