Streaming messages
Send a message; receive a Server-Sent Events stream of the agent's response.
POST /v1/sessions/{id}/messages
Send a message; the response is a Server-Sent Events stream.
Request body:
{"message": "Your prompt here. Plain text or markdown."}Response: text/event-stream, one event per line-pair. Stream ends with a message.completed or message.error event; the connection closes shortly after.
A session can only run one message at a time. Sending while busy returns 409 Conflict. Once a message starts, the agent runs to completion even if you disconnect — the next call will see the session as busy until the prior turn finishes.
Streaming format
Each event is two lines:
event: <type>
data: <json>
Followed by a blank line. Examples:
| Event | Data shape | Meaning |
|---|---|---|
message.created | {id, session_id, status:"in_progress"} | First event — gives you the response id |
text.start | {} | Text block opened |
text.delta | {content: "..."} | Incremental text |
text.stop | {} | Text block closed |
thinking.start/.delta/.stop | similar to text | Agent's reasoning trace (when extended thinking is on) |
tool_use.start | {name, id} | Agent invoked a tool |
tool_use.input_delta | {content: "..."} | Tool's input args streaming |
tool_use.executing | {name, id, input} | Final input, about to execute |
tool_use.stop | {} | Tool block closed |
tool_result | {id, content, is_error} | Tool returned (matches tool_use.start.id) |
message.completed | {id, status:"completed", usage:{...}} | Successful end of turn |
message.error | {id, error: "..."} | Failed end of turn |
Reading robustly: parse on \n\n boundaries. Many SSE clients (browser EventSource, Python httpx-sse, etc.) handle the framing for you.
Disconnection: if your client disconnects mid-stream, the agent keeps running. The next message on the same session will return 409 until the prior turn completes. Use GET /v1/sessions/{id} to poll busy.
Python example
import json
import os
import httpx
API = os.environ["POKEE_API"]
KEY = os.environ["POKEE_KEY"]
H = {"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"}
with httpx.Client(base_url=API, headers=H, timeout=httpx.Timeout(None)) as c:
sid = c.post("/v1/sessions", json={"persistent": True}).json()["id"]
with c.stream("POST", f"/v1/sessions/{sid}/messages",
json={"message": "Write a short poem about persistent storage."}) as r:
for line in r.iter_lines():
if line.startswith("event:"):
event = line[6:].strip()
elif line.startswith("data:"):
data = json.loads(line[5:].strip())
if event == "text.delta":
print(data["content"], end="", flush=True)
elif event == "message.completed":
print(f"\n\n[done] usage: {data['usage']}")
elif event == "message.error":
print(f"\n\n[error] {data['error']}")