WebSocket API
The WebSocket API enables real-time, streaming chat with your Biel.ai project. Use it when you need token-by-token AI responses instead of waiting for the full response via the REST API.
One message and its completed reply use one interaction, including documentation retrieval and continuing the same answer. Follow-up messages count separately. With extra usage enabled, interactions beyond the allowance cost $0.05 each.
Endpoint: wss://app.biel.ai/ws/messages/{projectId}/
To continue an existing chat: wss://app.biel.ai/ws/messages/chat/{chatId}/
Connect
Open a WebSocket connection to:
wss://app.biel.ai/ws/messages/{projectId}/
Replace {projectId} with your project slug (e.g., jfvzioa17q).
Send a message
Send a JSON message to the WebSocket:
{
"projectId": "your-project-slug",
"from": "user",
"message": "How do I authenticate?",
"url": "https://docs.example.com/auth",
}
-
projectId(string, optional): Project slug for client bookkeeping. The connection path selects the project. -
from(string, optional): Client message label. Use"user"when included. -
message(string, required): The user's message (Markdown supported). -
url(string, conditional): Current page URL. Required when the project restricts allowed domains. Otherwise, omit to search documentation without current-page context. Keep the same URL when retrying a message. -
email(string, optional): Email or ID for conversation tracking. -
apiKey(string, conditional): API key withchats_createpermission. Required in every message for private projects. -
thinkMode(boolean, optional): Deprecated compatibility field. Accepted and ignored. Omit in new integrations. -
retrievalMode(string, optional): Deprecated compatibility field. Accepted and ignored. Omit in new integrations. -
capabilities(array of strings, optional): Include"activity.v1"together with a validrequestIdto receive operational progress updates. -
requestId(string, optional): Unique caller-generated identifier for this turn: 1–80 characters fromA-Z,a-z,0-9,.,_,:, or-. Negotiating servers echo it on answer and status frames. -
idempotencyKey(string UUID, optional): Identity for retrying the same message in an existing chat. Reuse only for that message. Intentional new messages need new keys. This is separate fromrequestIdand does not replace chat access or restoration. -
restoreToken(string, conditional): Token returned by the server. Required in the first message after reconnecting to an existing conversation. Keep it withchatId. A chat ID alone does not grant access. -
metadata(string, optional): Tag to identify the conversation source.
Receive a response
The server sends JSON messages back. Partial messages stream token-by-token. The final message includes sources.
{
"projectId": "your-project-slug",
"chatId": "550e8400-e29b-41d4-a716-446655440000",
"restoreToken": "YOUR_RESTORE_TOKEN",
"from": "ai",
"messageId": "msg-uuid",
"message": "To authenticate, use the...",
"timestamp": "2026-01-15T10:30:00Z",
"isPartial": false,
"sources": [
{
"title": "Authentication guide",
"url": "https://docs.example.com/auth"
}
]
}
-
projectId(string): Project slug. -
chatId(string): Conversation UUID. Use it in the connection URL when reconnecting to this conversation. -
from(string): Always"ai". -
messageId(string): Message UUID. -
message(string): AI response content (Markdown). -
timestamp(string): ISO 8601 timestamp. -
isPartial(boolean):truefor streaming tokens,falsefor the final message. -
sources(array): Source references (only in final message). Each hastitleandurl. -
incomplete(boolean):trueif generation could not complete, including output limits or interruption. Only in the final message. -
stopReason(string): Provider stop reason or a classified recovery reason on the final frame. -
continuationCount(integer): Number of automatic continuations for this generation request. -
continuationAvailable(boolean): Whether the latest capped response can be continued through the REST API. -
requestId(string): Turn identifier, when progress was negotiated. May be absent on older servers. -
restoreToken(string): Opaque conversation restore token. Store it withchatId. Older servers may omit it. -
interrupted(boolean): Optional negotiated marker that generation was interrupted. Keep any useful draft and offer an explicit retry. -
isError(boolean): Optional negotiated error marker. Do not treat an error message as a replacement for an existing draft. -
retryable(boolean): Optional negotiated indication that retry is appropriate. Wait for the connection to recover before sending a retry.
Receive progress updates
To request progress, include both the capability and a new turn identifier in your message:
{
"projectId": "your-project-slug",
"from": "user",
"message": "How do I authenticate?",
"url": "https://docs.example.com/auth",
"capabilities": ["activity.v1"],
"requestId": "turn-1"
}
A supporting server sends status frames alongside the answer stream:
{
"type": "status",
"version": 1,
"requestId": "turn-1",
"sequence": 2,
"stage": "searching_docs",
"state": "started",
"detail": { "searchRound": 1 }
}
-
type,version:"status"and1identify this progress extension. -
requestId: Identifies the active turn. -
sequence: Increases within each turn, starting at 1. -
stage:contextualizing,compacting_content,searching_docs,reviewing_results,preparing_docs,searching_web,writing_answer,checking_sources,completed,failed, orinterrupted. -
state:started,completed, orfailed. -
detail: Optional details within the object:searchRound,documentCount,reason, orretryable.reasoncan begeneration_failed,stream_interrupted, ordisconnected.
Status frames describe actual operations, rather than private model reasoning. They have no from or message field: handle them separately from chat messages. Only accept supported frames for the active turn and ignore stale or duplicate sequence numbers. Not every operation appears in every answer, and a final completed status can arrive after the final answer.
Hide the writing indicator once answer text starts. Source-checking progress can still appear afterward. Hide successful progress when the final answer arrives. Preserve a useful interrupted draft and let the user choose whether to retry. Do not automatically replay requests. The widget follows this behavior and offers spinner or loading dots as a display option.
Compatibility
Clients that omit progress negotiation retain the existing answer stream, without status frames. New clients must also accept answers from older servers that omit requestId, restoreToken, and progress updates. Keep a generic loading indicator in that case. Update the installed widget to use the new progress display.
Authentication
The WebSocket API uses the same authentication model as the REST API:
- Public projects: No API key required. Domain restrictions still apply.
- Private projects: Include
apiKeywithchats_createpermission in every message. The legacychat_createpermission also works.
Domain validation is checked on every message using the url field. If your project has allowed domains configured, the url must match one of them.
Continue a conversation
Send follow-up messages on the same open connection. You do not need to send chatId or repeat restoreToken on that connection. Private projects still require apiKey in every message.
To reconnect later:
-
Save
chatIdandrestoreTokenfrom the response.YOUR_RESTORE_TOKENin the example above is a placeholder for the actual token. -
Connect to
wss://app.biel.ai/ws/messages/chat/{chatId}/, replacing{chatId}with the saved ID. -
Include the saved
restoreTokenin the first message:{"message": "How do I rotate that key?","restoreToken": "YOUR_RESTORE_TOKEN","url": "https://docs.example.com/auth"}
For a private project, also include apiKey. Keep restore tokens private and send them in the message body, never in the connection URL. If the token is missing or expired, connect to the project endpoint to start a new conversation.
Rate limiting
| Limit | Threshold | Penalty |
|---|---|---|
| Per chat session | 15 messages/minute | Rejected until window resets |
| Per IP address | 100 messages/minute | IP blocked for 1 hour |
| Burst detection | 10 messages within a 30-second window | Rejected while the burst threshold is met |
Continue a capped answer
REST and WebSocket replies can continue automatically when they reach the response length limit. For a manual continuation, use the REST message endpoint with chat_uuid and continue_message_id, omit message, and send the stored restore token in X-Chat-Restore-Token. The response contains the original assistant message UUID and its complete text including the appended suffix. Replace that message in your UI. Do not append a new user or assistant turn.