Key Features
Real-time Events
Receive instant updates for messages, guild changes, and user presence
Compression Support
Optional zstd-stream compression for reduced bandwidth usage
Session Management
Resume interrupted sessions without missing events
Rate Limiting
Built-in rate limiting to prevent abuse (120 events/60s)
Gateway URL
Connect to the Gateway using the WebSocket URL obtained from the/gateway/bot endpoint:
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
v | integer | Yes | Gateway API version (currently 1) |
encoding | string | No | Message encoding format (json, default) |
compress | string | No | Compression algorithm (zstd-stream or none) |
The Gateway currently supports version 1 only. Connecting without
v=1 will result in close code 4012 (Invalid API Version).Connection Flow
Message Format
All Gateway messages follow this JSON structure:Message Fields
| Field | Type | Description |
|---|---|---|
op | integer | Opcode identifying the message type |
d | mixed | Event data (type varies by opcode) |
s | integer | Sequence number (for dispatch events only) |
t | string | Event name (for dispatch events only) |
Configuration Constants
The Gateway enforces several limits and intervals defined in the source code:These values are extracted from
fluxer_gateway/src/utils/constants.erl.| Constant | Value | Description |
|---|---|---|
| Heartbeat Interval | 41,250 ms | Time between heartbeat requests |
| Heartbeat Timeout | 45,000 ms | Maximum time to wait for heartbeat ACK |
| Max Payload Size | 4,096 bytes | Maximum size of incoming messages |
| Rate Limit Window | 60,000 ms | Time window for rate limiting |
| Rate Limit Max Events | 120 | Maximum events per window |
| Guild Members Rate Limit | 3 requests/10s | Rate limit for REQUEST_GUILD_MEMBERS |
Connection Requirements
Rate Limiting
The Gateway implements two types of rate limiting:General Rate Limit
Rate-limited operations:- Heartbeat (opcode 1)
- Identify (opcode 2)
- Presence Update (opcode 3)
- Voice State Update (opcode 4)
- Resume (opcode 6)
- Lazy Request (opcode 14)
Opcode-Specific Limits
REQUEST_GUILD_MEMBERS (opcode 8):- Maximum 3 requests per 10 seconds
- Exceeding this limit results in close code 4008
- Maximum 10 updates per second
- Exceeding this limit queues updates (max queue: 64)
- Queue is processed at 100ms intervals
Client IP Detection
The Gateway extracts the client’s real IP address from theX-Forwarded-For header when present, with support for:
- IPv4 addresses (with or without port)
- IPv6 addresses (bracketed or unbracketed)
- Multiple forwarded addresses (uses first valid entry)
gateway_handler.erl:extract_client_ip/1.
Next Steps
Connection Lifecycle
Learn about connecting, identifying, resuming, and heartbeating
Opcodes
Reference for all Gateway opcodes and their payloads
Events
Complete list of dispatch events you can receive
Close Codes
Understand disconnection reasons and how to handle them