Chat Streaming (SSE)
Real-time streaming chat responses via Server-Sent Events (SSE).
POST /api/v1/chat/stream
POST /api/v1/chat/streamSSE Events
Event
Description
Data format
Example: Python
import requests
import json
url = "https://api.knowbase.ai/api/v1/chat/stream"
headers = {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
}
data = {
"question": "Summarize the main findings",
"file_ids": ["a1b2c3d4-e5f6-7890-abcd-ef1234567890"]
}
response = requests.post(url, headers=headers, json=data, stream=True)
event_type = None
for line in response.iter_lines():
line = line.decode("utf-8")
if line.startswith("event: "):
event_type = line[7:]
elif line.startswith("data: "):
payload = json.loads(line[6:])
if event_type == "token":
print(payload["t"], end="", flush=True)
elif event_type == "sources":
print(f"\nSources: {len(payload['sources'])} found")
elif event_type == "done":
print(f"\n\nDone. Conversation: {payload['conversation_id']}")Example: JavaScript
Last updated