SSE & WebSocket Integrations
Lamdis supports three protocols for communicating with assistant APIs:
- HTTP Chat (default) - Standard HTTP POST requests with JSON responses
- Server-Sent Events (SSE) - Streaming responses over HTTP
- WebSocket - Bidirectional real-time communication
When to Use Each Protocol
| Protocol | Use Case |
|---|---|
| HTTP Chat | Simple request/response APIs, most traditional chatbots |
| SSE | Streaming LLM responses (OpenAI-compatible APIs, Claude API) |
| WebSocket | Real-time bidirectional chat, voice assistants, live agents |
Configuring SSE Connections
SSE (Server-Sent Events) is ideal for APIs that stream responses token-by-token, like OpenAI’s chat completions endpoint.
Organization Connection Configuration
Add SSE configuration to your organization’s connection:
{
"connections": {
"openai-streaming": {
"base_url": "https://api.openai.com/v1/chat/completions",
"protocol": "sse",
"headers": {
"Authorization": "Bearer sk-..."
},
"responseFieldPath": "choices[0].message.content",
"sse": {
"contentPath": "choices[0].delta.content",
"finishPath": "choices[0].finish_reason",
"finishValue": ["stop", "length"]
}
}
}
}SSE Configuration Options
| Option | Description | Example |
|---|---|---|
contentPath | JSON path to extract content from each SSE event | choices[0].delta.content |
finishPath | JSON path to check if stream is complete | choices[0].finish_reason |
finishValue | Value(s) that indicate the stream is done | "stop" or ["stop", "length"] |
Example: OpenAI-Compatible API
{
"protocol": "sse",
"sse": {
"contentPath": "choices[0].delta.content",
"finishPath": "choices[0].finish_reason",
"finishValue": ["stop", "length", "content_filter"]
}
}Example: Claude API (Anthropic)
{
"protocol": "sse",
"sse": {
"contentPath": "delta.text",
"finishPath": "type",
"finishValue": "message_stop"
}
}Configuring WebSocket Connections
WebSocket connections are ideal for real-time bidirectional communication, such as voice assistants or live agent interfaces.
Organization Connection Configuration
{
"connections": {
"realtime-assistant": {
"base_url": "wss://api.example.com/ws/chat",
"protocol": "websocket",
"websocket": {
"messageFormat": "json",
"messageField": "content",
"contentPath": "response.text",
"finishPath": "type",
"finishValue": "done"
}
}
}
}WebSocket Configuration Options
| Option | Description | Example |
|---|---|---|
messageFormat | Format for outgoing messages: json or text | "json" |
messageField | Field name for message content in JSON format | "message" |
contentPath | JSON path to extract content from received messages | "response.text" |
finishPath | JSON path to check if conversation is complete | "type" |
finishValue | Value(s) that indicate the conversation is done | "done" |
protocols | WebSocket sub-protocols to use | ["chat", "v1"] |
Example: Custom WebSocket API
{
"protocol": "websocket",
"websocket": {
"messageFormat": "json",
"messageField": "userMessage",
"contentPath": "assistantResponse.content",
"finishPath": "status",
"finishValue": "complete"
}
}Using Protocols in Tests
When running tests, Lamdis will automatically use the configured protocol for the selected connection. The protocol configuration flows through:
- Organization Connection → Protocol config stored with the connection
- Test Run → Connection selected when starting a run
- Engine → Uses appropriate client (HTTP, SSE, or WebSocket)
Live Progress with Streaming
For SSE and WebSocket connections, Lamdis provides real-time progress updates:
- Stream chunks are logged as they arrive
firstTokenMsshows time to first token (TTFT)streamChunkscount shows total chunks received
Example Test Log Entry
{
"type": "assistant_reply",
"content": "The full assembled response...",
"latencyMs": 2500,
"protocol": "sse",
"streamChunks": 45,
"firstTokenMs": 150
}Troubleshooting
SSE Connection Issues
- No content received: Verify
contentPathmatches your API’s event structure - Stream never ends: Check
finishPathandfinishValueconfiguration - Timeout errors: Increase
timeoutMsfor slow-streaming responses
WebSocket Connection Issues
- Connection refused: Verify the URL uses
wss://for secure WebSocket - Message format errors: Ensure
messageFormatmatches your API expectations - Authentication failed: Check that auth headers are properly configured
Debug Tips
- Enable verbose logging to see raw SSE events or WebSocket messages
- Test your connection configuration with a simple message first
- Check the run logs for
stream_chunkentries to verify streaming is working
Migration from HTTP Chat
To migrate an existing HTTP connection to SSE:
- Update the
protocolfield to"sse" - Add
sseconfiguration with appropriate paths - Test with a simple message to verify streaming works
{
"connections": {
"my-assistant": {
"base_url": "https://api.example.com/chat",
+ "protocol": "sse",
+ "sse": {
+ "contentPath": "delta.content",
+ "finishPath": "done",
+ "finishValue": true
+ }
}
}
}Last updated on