WebSocket Protocol
Connection
Connect to the WebSocket endpoint:
ws://localhost:48911/ws/{lanlan_name}Where {lanlan_name} is the character identifier (e.g., 小天).
Connection flow
- Client opens WebSocket connection
- Server assigns a session ID (UUID) and validates the character exists
- Client sends
start_sessionto initialize the LLM session - Client sends
stream_datamessages with audio or text input - Server streams responses back (text, audio, status, emotion)
- Client sends
end_sessionto close - Server performs hot-swap to a pre-warmed session
Keep-alive
Send periodic ping messages to prevent connection timeout:
json
{ "action": "ping" }Server responds with:
json
{ "type": "pong" }Session management
Start session
json
{
"action": "start_session",
"input_type": "audio",
"new_session": true
}| Field | Type | Description |
|---|---|---|
action | "start_session" | Required |
input_type | "audio" | "text" | Input mode |
new_session | boolean | Whether to create a fresh session |
End session
json
{ "action": "end_session" }Triggers the hot-swap mechanism: the current LLM session is closed and replaced with a pre-warmed one.
Pause session
json
{ "action": "pause_session" }Keeps the WebSocket connected but pauses LLM processing.
Error handling
If the character name is invalid, the server closes the WebSocket with an appropriate close code. If the character is switched server-side, the server sends a catgirl_switched message directing the client to reconnect.
