Skip to main content
The gateway now ships in the praisonai-bot package. praisonai serve gateway still works exactly as documented here; for a standalone install see praisonai-bot Migration.
Rate limiting caps how many requests a given identity can make within a time window, returning a retry_after_seconds hint when they exceed it.
The user or bot sends high-volume traffic; gateway rate limiting protects agents and downstream APIs.

How It Works

Quick Start

1

Create a sliding-window policy

2

Inject into the gateway


Wire Response

A limited decision maps to ConnectErrorCode.RATE_LIMITED on the handshake wire:
Clients read retry_after_seconds and back off before reconnecting. This keeps retry storms from amplifying the load that triggered limiting in the first place.

SlidingWindowRateLimitPolicy Reference


RateLimitDecision Fields

RateLimitDecision is a frozen dataclass — immutable by design so it can be safely returned across threads.
RateLimitDecision is frozen (@dataclass(frozen=True)). Never try to mutate it — create a new instance instead.

Bring Your Own Limiter

Implement RateLimitPolicyProtocol for per-tenant, distributed, or cost-based limiting:
RateLimitPolicy is a backward-compatible alias for RateLimitPolicyProtocol. Both names import from praisonaiagents.gateway.

The Gateway Policy Family

Rate limiting completes the gateway’s symmetric policy-protocol family: All five follow the same shape: pure, stateless decision over typed facts, with a frozen decision dataclass returned.

Best Practices

SlidingWindowRateLimitPolicy is dependency-free and covers the common case. Only inject a custom policy when you need per-tenant fairness, shared state (Redis), or cost-based limits.
A 5-minute lockout after 5 exceeded requests in a minute prevents a script from hammering the gateway every 60 s. The retry_after_seconds hint in the response lets well-behaved clients back off cleanly.
Clients respect retry_after_seconds. A hint of 0 invites immediate retry; a hint matching your actual window (window_seconds) gives the client a correct backoff. Use lockout_seconds when you want a longer penalty than the window naturally provides.

Gateway

WebSocket control plane — full YAML and Python reference

Reliability Preset

One-switch production posture (includes admission control)

Admission Control

Bound concurrent turns with a fair queue and overflow policy

Gateway Security

Operator authentication and scope-based access control