Code Examples
Copy-paste integrations for the languages you're most likely to use. Every snippet calls /v1/chat/stream with two headers and a message body — same shape as Authentication and the Chat Endpoint. Responses are Server-Sent Events; concatenate every delta content for the full answer.
Hello, agent — single call
bash
curl -N -X POST https://api.sentientone.ai/v1/chat/stream \
-H "Content-Type: application/json" \
-H "X-Api-Key: $SENTIENTONE_KEY" \
-H "X-Agent-Id: $SENTIENTONE_AGENT" \
-d '{ "message": "Hello, agent!" }'
# Server-Sent Events — one event per "data:" line:
# data: {"type":"meta","conversation_id":"conv-abc123","trace_id":"..."}
# data: {"type":"sources","sources":[{"index":0,"id":"...","title":"...","url":"...","source_type":"...","score":0.91,"snippet":"..."}]}
# data: {"type":"delta","content":"Hello"}
# data: {"type":"delta","content":", agent!"}
# data: {"type":"done","conversation_id":"conv-abc123","trace_id":"..."}
# The full answer is the concatenation of every delta content.Multi-turn — continuing a conversation
bash
# 1) Start a thread
curl -N -X POST https://api.sentientone.ai/v1/chat/stream \
-H "Content-Type: application/json" \
-H "X-Api-Key: $SENTIENTONE_KEY" \
-H "X-Agent-Id: $SENTIENTONE_AGENT" \
-d '{ "message": "Hi, my order ORD-1234 hasn'\''t arrived." }'
# The "meta" / "done" events carry "conversation_id": "conv-abc123"
# data: {"type":"meta","conversation_id":"conv-abc123","trace_id":"..."}
# data: {"type":"delta","content":"..."}
# data: {"type":"done","conversation_id":"conv-abc123","trace_id":"..."}
# 2) Continue it — pass that conversation_id back in
curl -N -X POST https://api.sentientone.ai/v1/chat/stream \
-H "Content-Type: application/json" \
-H "X-Api-Key: $SENTIENTONE_KEY" \
-H "X-Agent-Id: $SENTIENTONE_AGENT" \
-d '{ "conversation_id": "conv-abc123", "message": "What carrier is it on?" }'Streaming — token-by-token
bash
curl -N -X POST https://api.sentientone.ai/v1/chat/stream \
-H "Content-Type: application/json" \
-H "X-Api-Key: $SENTIENTONE_KEY" \
-H "X-Agent-Id: $SENTIENTONE_AGENT" \
-d '{ "message": "Stream me a haiku." }'Best practices
- Store
X-Api-Keyin your server environment, never in client code. Always proxy through your backend. - Persist the
conversation_idper end-user session so follow-up messages keep context. - Honour
Retry-Afteron 429 and use exponential backoff on 5xx — see Rate Limits. - Log the
X-Trace-Idfrom every response alongside your application logs so you can pivot into Tracing in one click. - For chat UIs, use SSE instead of polling — the perceived latency is dramatically better.
Need a request with your real values?
Use the API Sandbox and click
Copy as cURL / Copy as TypeScript / Copy as Python. The snippet is generated with your real headers and your actual request body.