SSE Streaming
What Is SSE Streaming?
Defimara uses Server-Sent Events (SSE) to stream agent responses in real time. Instead of waiting for the full response, you receive a continuous stream of events: thinking steps, tool calls, intermediate results, and the final answer - as they happen.
• How It Works
• Requirements
• Code Example
import requests, json
with requests.post(
"http://localhost:8000/chat",
headers={"Authorization": f"Bearer {token}"},
json={"message": "swap 10 USDC for ETH", "stream": True},
stream=True
) as r:
for line in r.iter_lines():
if line.startswith(b"data: "):
event = json.loads(line[6:])
if event["type"] == "token":
print(event["content"], end="", flush=True)
elif event["type"] == "done":
break