Перейти к содержимому

Limits and rate limits

Every Gateway connection has limits on what it sends, how long its session lasts and how much Squad replays to it. Going over a limit closes the connection, drops the payload or clamps the value.

These limits don’t apply to the media connection a client opens to LiveKit or to a peer, and voice joins have their own admission limits. A connection that closes for a limit gets a close code. A client message can be at most 16,384 bytes.

LimitValueWhat happens
Heartbeat interval41,250 msSent in Hello
Heartbeat checkEvery 13,750 msThe Gateway checks the heartbeat
Heartbeat request37,125 ms since the last acknowledgementThe Gateway sends opcode 1, and you send a heartbeat right away
Heartbeat timeout45,000 ms with no acknowledgementThe connection closes with 4009 at the next heartbeat check, within 13,750 ms of that point
Identify deadlineOne heartbeat interval after HelloA socket with no Identify or Resume closes with 4003 at the next heartbeat check
Resume window60,000 ms after a disconnectA Resume restores the status the session had before
Offline presence5,000 ms after a disconnectThe presence shows as offline
Live sessions per user100A further Identify closes with 4008
Shard count1 to 16,384A shard that is not a valid [shard_id, shard_count] pair closes with 4010
Guilds per bot shard2,500A bot shard with more guilds closes with 4011

User accounts have no guild limit per session.

When the Gateway is busy, it keeps an Identify waiting and starts the session once it can. Keep heartbeating until Ready arrives. More than 300 Identify and Resume commands from one IP address in a 60-second window close the connection with 4008. Wait for the next window before you reconnect. The session start limit that GET /v1/gateway/bot returns has fixed values for client compatibility, and the Gateway does not enforce it.

Every client payload counts towards the first three budgets.

ScopeBudgetOver the budget
WebSocket600 payloads per rolling 60 secondsThe connection closes with 4008
Session600 payloads per fixed 60-second bucket, after authenticationThe connection closes with 4008
IP address6,000 payloads per fixed 60-second bucketThe connection closes with 4008
Open connections per IP256 WebSocketsThe new connection closes with 4008 before Hello
Identify and Resume per IP300 attempts per fixed 60-second windowThe connection closes with 4008, reason Identify rate limited or Resume rate limited
Commands between Identify and Ready, or between Resume and Resumed64 queued commandsThe connection closes with 4008
Presence Update5 per WebSocket per rolling 20 secondsThe command is dropped
Request Forum Unreads5 per WebSocket per rolling 5 secondsThe command is dropped
Voice Signal240 per WebSocket per rolling 10 secondsThe command is dropped
Request Guild Members12 per account and 40 per guild per rolling 10 secondsThe command is dropped

Squad applies the first two Voice State Updates per WebSocket in a rolling second. Later ones wait in a queue of up to 64 and are applied one every 500 ms. A newer update for the same guild_id and connection_id replaces one that is still waiting, and a full queue drops its oldest update.

A bot can request a guild’s complete member list (Request Guild Members with an empty query, limit 0 and no user_ids) once every 30 seconds per guild. An earlier request gets Rate Limited, and reconnecting does not reset the timer.

Request Guild Counts and Request Channel Member Counts leave out a guild that does not respond within 2,000 ms.

The replay buffer keeps at most 4,096 Dispatch events and about 16 MiB of event data, and drops the oldest events past either limit. A single Dispatch over about 2 MiB is sent but never kept, and a Resume with a seq below that event gets opcode 9 with d: false. Some events are never replayed, and a replay skips their sequence numbers.

The Gateway drops kept events up to the sequence in a heartbeat. Send a sequence only after you finish processing that event. When seq is below an event that was dropped from the buffer or never kept, you get opcode 9 with d: false and need to Identify again.

CommandLimit
IdentifyAt most 256 ignored_events
Request Guild MembersAt most 100 user_ids, a limit from 0 through 100 and a nonce up to 32 bytes
Lazy RequestAt most 10 ranges per channel of up to 100 members each, and 1,000 member IDs per guild
Request Guild CountsAt most 100 guild IDs and a nonce from 1 through 64 bytes
Request Channel Member CountsAt most 25 channel IDs and a nonce from 1 through 64 bytes
Request Forum UnreadsAt most 40 posts

Going over an Identify limit closes the connection with 4002. Other out-of-range values in client commands are clamped or dropped, depending on the field.

A refused voice join does not close the connection. It sends a Gateway Error with the refusal code.

A guild voice channel admits at most user_limit users, where 0 means no limit. Once anyone has a camera on, it admits at most 25 users, and a 26th camera is refused with VOICE_CAMERA_USER_LIMIT. A peer-to-peer call has at most max_participants participants, 2 by default and never more than 4, and refuses more with VOICE_CHANNEL_FULL. One user has at most voice_connection_limit connections in one guild voice channel (default 5, range 1-100).