Code Examples
Copy-paste integrations for the languages you're most likely to use. Every snippet calls /v1/chat with two headers and a message body — same shape as Authentication and the Chat Endpoint.
Hello, agent — single call
bash
curl -X POST https://api.sentientone.ai/v1/chat \
-H "Content-Type: application/json" \
-H "X-Api-Key: $SENTIENTONE_KEY" \
-H "X-Agent-Id: $SENTIENTONE_AGENT" \
-d '{ "message": "Hello, agent!" }'Multi-turn — continuing a conversation
bash
# 1) Start a thread
curl -X POST https://api.sentientone.ai/v1/chat \
-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." }'
# Response includes "conversation_id": "conv-abc123"
# 2) Continue it
curl -X POST https://api.sentientone.ai/v1/chat \
-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.