Chat (Streaming)
curl --request POST \
--url https://composer.personal.ai/lab/api/v1/agent.chat/stream \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"agent_slug": "<string>",
"conversation_id": "<string>",
"message": "<string>",
"timezone": "<string>",
"channel": "<string>",
"attachments": [
{}
]
}
'import requests
url = "https://composer.personal.ai/lab/api/v1/agent.chat/stream"
payload = {
"agent_slug": "<string>",
"conversation_id": "<string>",
"message": "<string>",
"timezone": "<string>",
"channel": "<string>",
"attachments": [{}]
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_slug: '<string>',
conversation_id: '<string>',
message: '<string>',
timezone: '<string>',
channel: '<string>',
attachments: [{}]
})
};
fetch('https://composer.personal.ai/lab/api/v1/agent.chat/stream', 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://composer.personal.ai/lab/api/v1/agent.chat/stream",
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([
'agent_slug' => '<string>',
'conversation_id' => '<string>',
'message' => '<string>',
'timezone' => '<string>',
'channel' => '<string>',
'attachments' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$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://composer.personal.ai/lab/api/v1/agent.chat/stream"
payload := strings.NewReader("{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
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://composer.personal.ai/lab/api/v1/agent.chat/stream")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://composer.personal.ai/lab/api/v1/agent.chat/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"response": "<string>",
"run_id": "<string>",
"conversation_id": "<string>",
"graphics": [
{}
],
"places": [
{}
],
"stopped": true,
"turn_ttft_ms": 123
}Agents & Chat
Chat (Streaming)
Receive an assistant reply as it is written
POST
/
lab
/
api
/
v1
/
agent.chat
/
stream
Chat (Streaming)
curl --request POST \
--url https://composer.personal.ai/lab/api/v1/agent.chat/stream \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"agent_slug": "<string>",
"conversation_id": "<string>",
"message": "<string>",
"timezone": "<string>",
"channel": "<string>",
"attachments": [
{}
]
}
'import requests
url = "https://composer.personal.ai/lab/api/v1/agent.chat/stream"
payload = {
"agent_slug": "<string>",
"conversation_id": "<string>",
"message": "<string>",
"timezone": "<string>",
"channel": "<string>",
"attachments": [{}]
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
agent_slug: '<string>',
conversation_id: '<string>',
message: '<string>',
timezone: '<string>',
channel: '<string>',
attachments: [{}]
})
};
fetch('https://composer.personal.ai/lab/api/v1/agent.chat/stream', 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://composer.personal.ai/lab/api/v1/agent.chat/stream",
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([
'agent_slug' => '<string>',
'conversation_id' => '<string>',
'message' => '<string>',
'timezone' => '<string>',
'channel' => '<string>',
'attachments' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$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://composer.personal.ai/lab/api/v1/agent.chat/stream"
payload := strings.NewReader("{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
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://composer.personal.ai/lab/api/v1/agent.chat/stream")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://composer.personal.ai/lab/api/v1/agent.chat/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"agent_slug\": \"<string>\",\n \"conversation_id\": \"<string>\",\n \"message\": \"<string>\",\n \"timezone\": \"<string>\",\n \"channel\": \"<string>\",\n \"attachments\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"response": "<string>",
"run_id": "<string>",
"conversation_id": "<string>",
"graphics": [
{}
],
"places": [
{}
],
"stopped": true,
"turn_ttft_ms": 123
}Overview
Takes the same body as Chat, but streams the reply back as server-sent events while the assistant writes it. Member keys can use it.Authorization
Body
The conversation, from Create Conversation.
Files attached to this message:
[{ filename, excerpt }]. An attachment can also carry image (the object_uri of an uploaded image) and mime.Example Request
{
"agent_slug": "my-assistant",
"conversation_id": "9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a",
"message": "Draw a chart of my sessions for the last six weeks",
"timezone": "America/New_York"
}
Events
The response istext/event-stream. Each event has a name and data:
| Event | Data | When |
|---|---|---|
run | { "run_id" } | Always first. Keep run_id to stop the reply. |
goal | { "goal", "conversation_id" } | The message opened or continued something the assistant is arranging with you. Send follow-ups to this conversation_id. |
activity | { "label", "iteration", "tool" } | The assistant is using a tool, such as searching the web |
token | Plain text, not JSON | The next piece of the reply |
connect | JSON | The assistant needs you to connect an account first |
done | JSON, see below | The reply is complete |
error | Plain text | Something went wrong |
The done event
True when the reply was stopped before it finished.
Example Stream
event: run
data: {"run_id":"3f8e2a1b-7c6d-4e5f-9a8b-0c1d2e3f4a5b"}
event: activity
data: {"label":"Drawing","iteration":1,"tool":"make_graphic"}
event: token
data: Here it is.
event: done
data: {"response":"Here it is.","run_id":"3f8e2a1b-7c6d-4e5f-9a8b-0c1d2e3f4a5b","conversation_id":"9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a","graphics":[{"title":"Weekly sessions, last six weeks"}],"places":[],"stopped":false}
Example cURL
cURL
curl --no-buffer --request POST 'https://composer.personal.ai/lab/api/v1/agent.chat/stream' \
--header 'Content-Type: application/json' \
--header 'x-api-key: <your-api-key>' \
--data '{"agent_slug": "my-assistant", "conversation_id": "9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a", "message": "Draw a chart of my sessions for the last six weeks"}'
Error Codes
| Code | Description |
|---|---|
| 400 | conversation_id isn’t a valid id |
| 401 | Missing or invalid API key |
| 403 | This key can’t post in this conversation |
| 404 | No assistant or conversation with that id |