Skip to content

Chat API

The Chat API allows you to send messages to your AI assistant and receive responses programmatically. Core API

Send Message

POST

Send a message and receive a response.

Stream Response

POST SSE

Real-time streaming responses.

Get History

GET

Retrieve conversation messages.

List Conversations

GET

Paginated conversation list.

POST /chat/{botId}/message

Send a message to your AI assistant and receive a response.

{
"message": "What are your business hours?",
"conversationId": "conv_123456", // Optional - omit to start new conversation
"metadata": { // Optional - custom data
"userId": "user_789",
"source": "mobile_app"
}
}

Streaming Responses Stable SSE

Section titled “Streaming Responses ”

POST /chat/{botId}/stream

For real-time responses, use the streaming endpoint with Server-Sent Events (SSE):

const response = await fetch(`https://api.mygptassistants.com/api/v1/chat/${botId}/stream`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: 'Tell me a story' }),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
// Process streamed chunks
console.log(chunk);
}

Get Conversation History Stable

Section titled “Get Conversation History ”

GET /chat/{botId}/conversations/{conversationId}

Retrieve the full message history for a conversation.

{
"success": true,
"data": {
"conversationId": "conv_123456",
"messages": [
{
"id": "msg_001",
"role": "user",
"content": "Hello",
"timestamp": "2024-01-15T10:00:00Z"
},
{
"id": "msg_002",
"role": "assistant",
"content": "Hi! How can I help you today?",
"timestamp": "2024-01-15T10:00:01Z"
}
],
"metadata": {
"createdAt": "2024-01-15T10:00:00Z",
"messageCount": 2
}
}
}

GET /chat/{botId}/conversations

List all conversations for a bot with pagination.

ParameterTypeDefaultDescription
pagenumber1Page number
limitnumber20Items per page (max 100)
sinceISO date-Filter conversations after this date
CodeDescriptionSolution
400Invalid request bodyCheck request format
401Invalid or missing API keyVerify authentication
404Bot or conversation not foundCheck IDs
429Rate limit exceededImplement backoff
500Server errorRetry with backoff
  1. Get your API key

    Generate a key in Settings → API Keys.

  2. Send your first message

    Use the /chat/{botId}/message endpoint.

  3. Store the conversation ID

    Save conversationId from the response.

  4. Continue the conversation

    Include conversationId in subsequent requests.

  5. Add streaming (optional)

    Use /chat/{botId}/stream for real-time UX.

EndpointMethodDescription
/chat/{botId}/messagePOSTSend message, get response
/chat/{botId}/streamPOSTStream response (SSE)
/chat/{botId}/conversations/{id}GETGet conversation history
/chat/{botId}/conversationsGETList all conversations