curl --request POST \
--url https://www.chatbase.co/api/v2/agents/{agentId}/chat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"message": "Hello, how can you help me?",
"conversationId": "<string>",
"stream": true,
"userId": "<string>"
}
'import requests
url = "https://www.chatbase.co/api/v2/agents/{agentId}/chat"
payload = {
"message": "Hello, how can you help me?",
"conversationId": "<string>",
"stream": True,
"userId": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: 'Hello, how can you help me?',
conversationId: '<string>',
stream: true,
userId: '<string>'
})
};
fetch('https://www.chatbase.co/api/v2/agents/{agentId}/chat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chatbase.co/api/v2/agents/{agentId}/chat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'message' => 'Hello, how can you help me?',
'conversationId' => '<string>',
'stream' => true,
'userId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chatbase.co/api/v2/agents/{agentId}/chat"
payload := strings.NewReader("{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chatbase.co/api/v2/agents/{agentId}/chat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chatbase.co/api/v2/agents/{agentId}/chat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"messageId": "<string>",
"userMessageId": "<string>",
"conversationId": "<string>",
"userId": "<string>",
"usage": {
"credits": 2
}
}{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "Invalid request"
}
}{
"error": {
"code": "AUTH_MISSING_API_KEY",
"message": "Authentication required"
}
}{
"error": {
"code": "CHAT_CREDITS_EXHAUSTED",
"message": "Message limit reached"
}
}{
"error": {
"code": "SUBSCRIPTION_API_RESTRICTED_PLAN",
"message": "A Basic plan or higher is required to access the API"
}
}{
"error": {
"code": "AGENT_NOT_FOUND",
"message": "Agent not found"
}
}{
"error": {
"code": "RATE_LIMIT_TOO_MANY_REQUESTS",
"message": "Too many requests, please try again later"
}
}{
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "Something went wrong, please try again"
}
}{
"error": {
"code": "SERVICE_UNDER_MAINTENANCE",
"message": "The API is temporarily unavailable for scheduled maintenance, please try again later"
}
}Chat with an agent
Send a message to an agent and receive a response. Supports streaming responses when stream: true is set in the request body.
curl --request POST \
--url https://www.chatbase.co/api/v2/agents/{agentId}/chat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"message": "Hello, how can you help me?",
"conversationId": "<string>",
"stream": true,
"userId": "<string>"
}
'import requests
url = "https://www.chatbase.co/api/v2/agents/{agentId}/chat"
payload = {
"message": "Hello, how can you help me?",
"conversationId": "<string>",
"stream": True,
"userId": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
message: 'Hello, how can you help me?',
conversationId: '<string>',
stream: true,
userId: '<string>'
})
};
fetch('https://www.chatbase.co/api/v2/agents/{agentId}/chat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chatbase.co/api/v2/agents/{agentId}/chat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'message' => 'Hello, how can you help me?',
'conversationId' => '<string>',
'stream' => true,
'userId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chatbase.co/api/v2/agents/{agentId}/chat"
payload := strings.NewReader("{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chatbase.co/api/v2/agents/{agentId}/chat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chatbase.co/api/v2/agents/{agentId}/chat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"message\": \"Hello, how can you help me?\",\n \"conversationId\": \"<string>\",\n \"stream\": true,\n \"userId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"messageId": "<string>",
"userMessageId": "<string>",
"conversationId": "<string>",
"userId": "<string>",
"usage": {
"credits": 2
}
}{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "Invalid request"
}
}{
"error": {
"code": "AUTH_MISSING_API_KEY",
"message": "Authentication required"
}
}{
"error": {
"code": "CHAT_CREDITS_EXHAUSTED",
"message": "Message limit reached"
}
}{
"error": {
"code": "SUBSCRIPTION_API_RESTRICTED_PLAN",
"message": "A Basic plan or higher is required to access the API"
}
}{
"error": {
"code": "AGENT_NOT_FOUND",
"message": "Agent not found"
}
}{
"error": {
"code": "RATE_LIMIT_TOO_MANY_REQUESTS",
"message": "Too many requests, please try again later"
}
}{
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "Something went wrong, please try again"
}
}{
"error": {
"code": "SERVICE_UNDER_MAINTENANCE",
"message": "The API is temporarily unavailable for scheduled maintenance, please try again later"
}
}Path Parameters
Body
Optional user ID to associate with a new conversation. Only applied when creating a new conversation (no conversationId). Once set, a conversation's userId is immutable — this field is ignored for existing conversations. Must contain only URL-safe characters (letters, digits, hyphens, underscores, dots).
128^[a-zA-Z0-9._-]+$Response
Successful response
Streaming response using the AI SDK UIMessage Stream protocol.
Each SSE event has an event: field with the type and a data: field with JSON content.
AI SDK events:
message-start—{ type, messageId }— Start of a new messagetext-start—{ type, id }— Start of a text blocktext-delta—{ type, id, delta }— Incremental text chunktext-end—{ type, id }— End of a text blocktool-input-start—{ type, toolCallId, toolName }— Start of tool call inputtool-input-delta—{ type, toolCallId, inputTextDelta }— Incremental tool inputtool-input-available—{ type, toolCallId, toolName, input }— Complete tool inputtool-output-available—{ type, toolCallId, output }— Tool execution resultstart-step—{ type }— Start of a processing stepfinish-step—{ type }— End of a processing stepfinish—{ type }— Stream completeerror—{ type, errorText }— Error occurred
Chatbase metadata (emitted as message-metadata on the finish event):
The schema below describes the custom metadata attached to the finish event. Use conversationId for follow-up messages.
Stream terminates with data: [DONE].