Creating a session
POST /api/v1/realtime/sessions runs these checks. If one fails, no session is created.
The rate limit check runs last. So
402, 403, 404 and 422 do not use up a session.
Close codes
When the server refuses a connection, it accepts the WebSocket and then closes it right away with a code. No message is sent first. Soonopen fires even when the connection is refused. Read event.code and event.reason in onclose.
4001: invalid token
All token problems return4001 with the same reason. Check these in order:
- The token was already used. This is the most common cause during development. A token is used up by the first connection attempt, even if that attempt fails. Common causes:
- React Strict Mode runs effects twice in development.
- Hot reload runs the connect code again with the old token.
- Your retry code reconnects with the same
ws_url.
- The token expired. It lasts 60 seconds. Creating the session on page load and connecting later on a click can take longer.
- The URL was changed. Open
ws_urlexactly as returned. - The agent was deleted or moved between creating the session and connecting.
4029: too many connections
Read thereason to tell the two limits apart.
- Per-IP limit (20 attempts per 60 seconds). This check runs before the socket is accepted. So a browser usually reports code
1006with an empty reason, not4029. If your reconnect loop gets1006, this is likely the cause. - Plan limit. A session holds a slot until it disconnects. Close sessions with
ws.close(1000)and stop all media tracks, including onbeforeunload. A tab closed without cleanup can hold its slot for up to 2 hours.
A 1000 close you did not expect
When the agent ends the conversation, the server sendssession_ended. On voice, camera and screen sessions it does not close the socket. Call ws.close() yourself when you get session_ended.
A 1000 close that you did not start, with no session_ended before it, gives you nothing to go on. Log the last error message and the last turn you received.
Error messages
During a session, the server sends anerror message when it cannot use something you sent:
code and show it while you develop. Match on code. The error text can change.
no_audio_received is checked when an image arrives, not on a timer. It fires on the first image that arrives at least 8 seconds after the first one. If you send two images and stop, you never get it.Text sessions
Atext session only sends two of these codes: binary_frame_unsupported and missing_data. It ignores audio and images without any error. If you send invalid JSON, the agent replies with a normal-looking apology message instead of an error. Check your own JSON on text sessions.
Client library errors
session.start() rejects with an EclatiraError. Its code tells you what happened: