> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gateway Close Code • AI Agent SDK

> GatewayCloseCode: Structured, machine-readable reasons for a server-initiated close.

# GatewayCloseCode

> Defined in the [**protocols**](https://praison.ai/docs/sdk/reference/praisonaiagents/modules/protocols.md) module.

AI Agent

Structured, machine-readable reasons for a server-initiated close.

Distinct from :class:`ConnectErrorCode` (which describes why a *connection*
was rejected at/handshake time), these describe why an already-established
connection is being torn down by the server mid-session.

Codes:
SLOW\_CONSUMER: The client's outbound buffer exceeded the gateway's
advertised `max_buffered_bytes` policy (a genuinely slow/stalled
consumer). The server evicts it so its backlog cannot grow without
bound or stall delivery to healthy clients.
CREDENTIALS\_ROTATED: The shared gateway secret this session
authenticated under is no longer the active secret (an operator
rotated `auth_token` and hot-reloaded, or otherwise revoked it).
The server force-closes every session stamped with a stale secret
so a leaked/revoked credential stops working within one reload
cycle, without a full process restart. Clients should
re-authenticate (see :attr:`ConnectRecoveryStep.REAUTHENTICATE`)
and reconnect with fresh credentials rather than backing off as if
the server were down.
LIVENESS\_TIMEOUT: The connection missed too many application-level
heartbeats (see :class:`LivenessPolicy`): its `last_activity`
exceeded `interval_ms × missed_beats_before_reap`, so the server
treats it as a dead/half-open peer and reaps it, releasing the
session/presence/queue state deterministically. Half-open sockets
behind NAT/proxies/mobile networks — where the peer has vanished
but no FIN/RST ever arrives — are the motivating case. Clients
should reconnect (their own watchdog typically force-reconnects
first) rather than treating this as a fatal error.

## Source

> [card] [View on GitHub](https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L72)
>
> `praisonaiagents/gateway/protocols.py` at line 72

***

## Related Documentation

> [card] [Gateway Feature](https://praison.ai/docs/docs/features/gateway)

> [card] [Code Agent](https://praison.ai/docs/docs/features/codeagent)

> [card] [Code Feature](https://praison.ai/docs/docs/features/code)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.