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

# Real-time & WebSockets

> Build interactive, low-latency AI applications with persistent connections.

Traceport provides dedicated WebSocket endpoints for building interactive, multi-turn chat applications and high-fidelity real-time audio/text sessions. These APIs enable persistent connections, reducing handshake overhead and supporting stateful interactions.

## Key Capabilities

<CardGroup cols={2}>
  <Card title="Standard Chat WS" icon="messages" href="/api-reference/realtime/chat-ws">
    A simple wrapper around the Chat Completion API for persistent, multi-turn text conversations.
  </Card>

  <Card title="Realtime Protocol" icon="bolt" href="/api-reference/realtime/openai-realtime">
    OpenAI-compatible Realtime API for ultra-low latency text (Speech coming soon).
  </Card>
</CardGroup>

## Session Recovery

Traceport supports advanced session recovery for the Realtime API. When a client reconnects using a previously active `session_id`, the Gateway automatically:

1. **Restores State**: Automatically restores conversation history and configurations (Instructions/Tools) from the cache.
2. **Synchronizes State**: Emits a `session.created` event with the restored state immediately upon connection.
3. **Tool Continuity**: (Upcoming) Ensures that in-flight workflows or tools are re-associated with the session.

## Error Handling

WebSocket connections use standard closing codes to communicate gateway and provider errors:

| Code   | Message         | Description                                             |
| ------ | --------------- | ------------------------------------------------------- |
| `4001` | `gateway_error` | A generic error occurred in the underlying AI provider. |
| `401`  | `unauthorized`  | The provided `x-api-key` is missing or invalid.         |
| `404`  | `not_found`     | The specified session ID or model was not found.        |

<Tip>
  We recommend implementing **Exponential Backoff** for WebSocket reconnections. Always pass the `session_id` immediately upon reconnection to resume the existing state.
</Tip>
