assembly-rate-limit

This command specifies a rate limit assembly scheme to apply to a rate limit assembly action.

Syntax

assembly-rate-limit schemeName rate [interval] [unit] [hard-limit] [cache-first] [is-client] [use-api-name] [use-app-id] [use-client-id] [dynamic-value] [weight]

Parameters

schemeName
Specifies the name for the rate limit scheme. This parameter is a string.

Assembly limits defined in different configurations, including an API gateway, API collection, or API plan, need unique names. If two limits with the same name are used in an assembly and both limits are applied, then information about only one limit is included in the response headers.

rate
Specifies the maximum number of requests to handle within a unit of time. The value of 0 indicates no limit.
interval
Specifies the time interval for the rate limit. Specify a value that is greater than or equal to 1. The default value is 1.
unit
Specifies the unit of time for the rate limit. For example, when the unit is second, the requests that are received in a second cannot exceed the specified rate. The following values are supported. The default value is second.
  • second
  • minute
  • hour
  • day
  • week
hard-limit
Controls whether to reject requests when the specified rate limit is reached. The default value is off.
on
Rejects the request when the limit is exceeded.
off
Accepts and processes the request when the limit is reached but produces a warning message.
cache-first
Specifies whether to use the local cache first to enforce the rate limit. In peer group mode, the local cache first can prevent transaction delays if communication problems arise across the peer group. However, the transaction count is less precise when this setting is enabled. The default setting is on.
is-client
Specifies whether to apply the rate limit to the client or to an internal component. Client burst limits return a 429 error when exceeded. Nonclient burst limits return a 503 error when exceeded. The default setting is on. When set to off, rate limit information is not included in the response header.
use-api-name
Specifies whether to use the API name as part of the rate limit key. The default setting is off.
use-app-id
Specifies whether to use the application ID as part of the rate limit key. The default setting is off.
use-client-id
Specifies whether to use the client ID as part of the rate limit key. The default setting is off.
dynamic-value
Specifies the dynamic value string for the rate limit, which contains one or more context variables. The dynamic value makes it possible to use a context variable to enforce the limit based on parameters that are not defined in the scheme. The context variable can be set in a GatewayScript action and then included in the dynamic value. The default value is an empty string.
The following example uses the context object in a GatewayScript action to add the my.server variable to the API context. You can then provide the $(my.server) variable that resolves to the server34 server.
context.set("my.server", "server34")
weight
Specifies a JSONata expression that assigns a weight value to the transaction. You use a subset of JSONata notation to define the expression. For more information, see JSONata and assembly actions.

For each API call, the applied limit is the value that the weight expression computes. The default value is 1. If the weight expression evaluates to a value that is less than or equal to 0, it is set to 1. An empty string results in an error.

Guidelines

The assembly-rate-limit command specifies a rate limit assembly scheme to apply to a rate limit assembly action. When added to an assembly, the assembly rate limit scheme overrides the default rate limit.

Attention: Because the synchronization interval is 1 second, do not use the local cache first to enforce the rate limit with a 1-second interval. With this configuration, each peer can use all available tokens during the interval. For example, a configuration of 10 tokens per second with 3 peers results in a condition where each peer can use 10 tokens.