Chat Endpoint
Send messages to your agent and receive AI responses programmatically.
The Chat endpoint lets you send messages to your agent and receive AI responses. Use it to build custom chat interfaces or integrate agent functionality into your applications.
Endpoint
POST /api/v1/chat
Authentication
Requires Bearer token authentication.
Authorization: Bearer YOUR_API_KEY
Request Body
{
"chatbotId": "uuid",
"messages": [
{ "role": "user", "content": "What are your pricing plans?" }
],
"conversationId": "optional-id",
"stream": false
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
chatbotId | string (UUID) | Yes | Your agent's ID |
messages | array | Yes | Array of message objects (1-100 items) |
conversationId | string (max 16 chars) | No | Reference ID returned by a prior call's x-conversation-id header. Invalid or missing values cause the server to assign a fresh ID. |
stream | boolean | No | Enable streaming response (default: false) |
Message Object
| Field | Type | Values | Description |
|---|---|---|---|
role | string | "user", "assistant" | Who sent the message |
content | string | 1-32000 chars | Message text |
Limits
- Maximum 100 messages per request
- Maximum 32,000 characters per message
Response
Non-Streaming (default)
Success (200):
{
"text": "Our pricing starts at $29.99/month for the Hobby plan..."
}
Headers include:
X-Conversation-ID: abc123
Streaming
Set "stream": true for streaming responses.
Success (200):
Content-Type: text/plain; charset=utf-8
Response streams plain text as it's generated. Use this for real-time UI updates.
Example Requests
Basic Request
curl -X POST 'https://your-domain.com/api/v1/chat' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"chatbotId": "123e4567-e89b-12d3-a456-426614174000",
"messages": [
{"role": "user", "content": "What are your pricing plans?"}
]
}'
Multi-Turn Conversation
curl -X POST 'https://your-domain.com/api/v1/chat' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"chatbotId": "123e4567-e89b-12d3-a456-426614174000",
"conversationId": "conv_abc123",
"messages": [
{"role": "user", "content": "What are your pricing plans?"},
{"role": "assistant", "content": "We offer three plans..."},
{"role": "user", "content": "Tell me more about the Pro plan"}
]
}'
Streaming Response
curl -X POST 'https://your-domain.com/api/v1/chat' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"chatbotId": "123e4567-e89b-12d3-a456-426614174000",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}'
Error Responses
| Status | Message | Cause |
|---|---|---|
| 400 | Invalid JSON body | Malformed JSON |
| 400 | Invalid request body | Missing/invalid fields |
| 401 | Missing or invalid Authorization header | Header not provided or wrong format |
| 401 | Invalid API key | Key not recognized |
| 403 | API access requires a Hobby plan or above with active billing | Plan/billing does not allow API access |
| 403 | Chatbot does not belong to this account | Agent belongs to a different account |
| 404 | Chatbot not found | Invalid agent ID |
| 429 | Rate limit exceeded | Too many requests |
Error Response Format
{
"message": "Invalid request body",
"details": {
"chatbotId": ["Required"]
}
}
Code Examples
Node.js
async function sendMessage(chatbotId, message) {
const response = await fetch('https://your-domain.com/api/v1/chat', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AGENTKIT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chatbotId,
messages: [{ role: 'user', content: message }],
}),
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
return data.text;
}
Python
import requests
def send_message(chatbot_id: str, message: str) -> str:
response = requests.post(
'https://your-domain.com/api/v1/chat',
headers={
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json',
},
json={
'chatbotId': chatbot_id,
'messages': [{'role': 'user', 'content': message}],
},
)
response.raise_for_status()
return response.json()['text']
Node.js with Streaming
async function streamMessage(chatbotId, message) {
const response = await fetch('https://your-domain.com/api/v1/chat', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.AGENTKIT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chatbotId,
messages: [{ role: 'user', content: message }],
stream: true,
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
process.stdout.write(text); // Print as it streams
}
}
Conversation Management
Starting a Conversation
Omit conversationId to start a new conversation. The response header X-Conversation-ID returns the new ID.
Continuing a Conversation
Include the conversationId and all previous messages to maintain context.
Message History
You must include previous messages in each request. The API is stateless - we don't store conversation history on the server between requests.
Next Steps
- Set up webhook subscriptions for event notifications
- View all API endpoints
- Manage API keys