Chatspark
K

API Reference

v1
K

Send Message

Send a message to an agent and receive an AI response. Supports multi-turn conversations and optional SSE streaming.

POST

/api/v1/agents/{id}/chat

Plus+

Request Parameters

NameTypeRequiredDescription
messagestringRequired

The user message to send

conversationIdstring

Session ID for multi-turn. Omit to start a new conversation

streamboolean

Enable SSE streaming. Default: false

temperaturenumber

Model temperature (0-2). Default: 0.2

Response Schema (Non-Streaming)

NameTypeRequiredDescription
textstringRequired

The full AI response text

conversationIdstringRequired

Session ID for multi-turn. Pass this in the next request

modelstringRequired

Model used (e.g. gpt-4o-mini, gpt-4o)

json

{
  "text": "Hello! How can I help you today?",
  "conversationId": "clx123abc456",
  "model": "gpt-4o-mini"
}

SSE Streaming Response

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].

Multi-Turn Conversation

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,
  }),
});

Code Examples

curl -X POST https://chatspark.io/api/v1/agents/123/chat \
  -H "Authorization: Bearer cs_live_..." \
  -H "Content-Type: application/json" \
  -d '{"message":"Hello!"}'

Previous

Health

Next

List Agents