API Reference
Send a message to an agent and receive an AI response. Supports multi-turn conversations and optional SSE streaming.
/api/v1/agents/{id}/chat
Plus+| Name | Type | Required | Description |
|---|---|---|---|
| message | string | Required | The user message to send |
| conversationId | string | Session ID for multi-turn. Omit to start a new conversation | |
| stream | boolean | Enable SSE streaming. Default: false | |
| temperature | number | Model temperature (0-2). Default: 0.2 |
| Name | Type | Required | Description |
|---|---|---|---|
| text | string | Required | The full AI response text |
| conversationId | string | Required | Session ID for multi-turn. Pass this in the next request |
| model | string | Required | Model used (e.g. gpt-4o-mini, gpt-4o) |
json
{
"text": "Hello! How can I help you today?",
"conversationId": "clx123abc456",
"model": "gpt-4o-mini"
}When stream: true, the response is text/event-stream. Each event contains:
text
data: {"delta": "Hello", "conversationId": "clx123abc456"}
data: {"delta": "!", "conversationId": "clx123abc456"}
data: [DONE]The delta field contains incremental text. The stream ends with [DONE].
javascript
// Turn 1 - Start new conversation
const r1 = await fetch("https://chatspark.io/api/v1/agents/123/chat", {
method: "POST",
headers: {
"Authorization": "Bearer cs_live_...",
"Content-Type": "application/json",
},
body: JSON.stringify({ message: "What are your hours?" }),
});
const { text, conversationId } = await r1.json();
// Turn 2 - Continue with same conversation
const r2 = await fetch("https://chatspark.io/api/v1/agents/123/chat", {
method: "POST",
headers: {
"Authorization": "Bearer cs_live_...",
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "Are you open on weekends?",
conversationId,
}),
});curl -X POST https://chatspark.io/api/v1/agents/123/chat \
-H "Authorization: Bearer cs_live_..." \
-H "Content-Type: application/json" \
-d '{"message":"Hello!"}'