This endpoint consumes AI credits (typically 1 - 5 credits per request depending on tool usage). If the workspace balance is insufficient, the API returns 402 insufficient_credits immediately, before any events are streamed.
Request
This is the streaming counterpart to POST /v1/lexi/chat. The response is a text/event-stream that emits incremental events as Lexi reasons through the prompt and uses tools. Because the request is a POST, you must use a fetch-based SSE client - the browser’s EventSource only supports GET.
Authorization: Bearer wbk_your_api_key_here
Content-Type: application/json
Accept: text/event-stream
Optional UUID to deduplicate retries within 24 hours. Credits are charged only on the first successful stream.
Body Parameters
User message to send to Lexi. Maximum 12,000 characters.
Optional conversation UUID. When omitted, a new conversation is created and its ID is emitted in the first text event’s conversation_id metadata.
Optional page / entity context: contact_id, deal_id, matter_id, company_id, page.
When false, Lexi will not invoke any CRM tools and will respond purely from the conversation context.
Event Types
| Event | Purpose |
|---|
thinking | Intermediate reasoning step. Payload: data: {"text": "..."}. Safe to ignore if not rendering a progress UI. |
tool_step | Lexi is about to invoke or has completed a CRM tool. Payload: data: {"tool": "...", "status": "started" or "completed", "summary": "..."}. |
text | Incremental assistant text. Payload: data: {"delta": "...", "conversation_id": "..."}. Concatenate delta values to build the final response. |
done | Final event with usage metadata. Payload: data: {"credits_remaining": 4840, "message_id": "msg_01HY1"}. |
The stream terminates with the literal line data: [DONE] followed by a newline, consistent with the OpenAI SSE convention.
event: thinking
data: {"text": "Looking up the contact in your pipeline..."}
event: tool_step
data: {"tool": "contacts.get", "status": "started"}
event: tool_step
data: {"tool": "contacts.get", "status": "completed", "summary": "Found 1 contact"}
event: text
data: {"delta": "Jane Doe is currently", "conversation_id": "conv_01HY1"}
event: text
data: {"delta": " in the Proposal stage...", "conversation_id": "conv_01HY1"}
event: done
data: {"credits_remaining": 4840, "message_id": "msg_01HY1"}
data: [DONE]
Responses include X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, and X-Request-ID headers on the initial HTTP response.
curl -N -X POST \
https://data.leadlex.com/functions/v1/api-gateway/v1/lexi/chat/stream \
-H "Authorization: Bearer wbk_your_api_key_here" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"message": "Summarize my pipeline",
"conversation_id": null
}'
Errors
| Status | Code | Description |
|---|
| 400 | validation_error | Missing message, or prompt exceeds size limit |
| 401 | invalid_key | Invalid or expired API key |
| 402 | insufficient_credits | Workspace credit balance is exhausted |
| 403 | insufficient_permissions | Missing write:ai permission |
| 404 | conversation_not_found | Supplied conversation_id does not exist |
| 429 | rate_limited | Rate limit exceeded |
Errors surface as a single event: error in the SSE stream when they occur after the HTTP headers have been sent, with the same code / message payload as JSON responses. Clients should therefore handle both HTTP-level and in-stream error events.