Send session events
curl --request POST \
--url https://api.example.com/v1/sessions/{session_id}/events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"type": "user.message",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"id": "<string>"
}
]
}
'import requests
url = "https://api.example.com/v1/sessions/{session_id}/events"
payload = { "events": [
{
"type": "user.message",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"id": "<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({
events: [
{
type: 'user.message',
content: [{type: 'text', text: '<string>'}],
id: '<string>'
}
]
})
};
fetch('https://api.example.com/v1/sessions/{session_id}/events', 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://api.example.com/v1/sessions/{session_id}/events",
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([
'events' => [
[
'type' => 'user.message',
'content' => [
[
'type' => 'text',
'text' => '<string>'
]
],
'id' => '<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://api.example.com/v1/sessions/{session_id}/events"
payload := strings.NewReader("{\n \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\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://api.example.com/v1/sessions/{session_id}/events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/sessions/{session_id}/events")
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 \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"type": "system.message",
"id": "<string>",
"processed_at": "<string>",
"content": [
{
"type": "text",
"text": "<string>"
}
]
}
]
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "authentication_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "not_found_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "conflict_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "payload_too_large",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "unsupported_media_type",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "internal_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "service_unavailable",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}Send session events
Send events to start, resume, follow up, or interrupt. Send up to 8 events and 802816 UTF-8 JSON bytes. Each user message must contain 1 to 16384 UTF-16 code units after joining blocks with newlines.
POST
/
v1
/
sessions
/
{session_id}
/
events
Send session events
curl --request POST \
--url https://api.example.com/v1/sessions/{session_id}/events \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"type": "user.message",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"id": "<string>"
}
]
}
'import requests
url = "https://api.example.com/v1/sessions/{session_id}/events"
payload = { "events": [
{
"type": "user.message",
"content": [
{
"type": "text",
"text": "<string>"
}
],
"id": "<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({
events: [
{
type: 'user.message',
content: [{type: 'text', text: '<string>'}],
id: '<string>'
}
]
})
};
fetch('https://api.example.com/v1/sessions/{session_id}/events', 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://api.example.com/v1/sessions/{session_id}/events",
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([
'events' => [
[
'type' => 'user.message',
'content' => [
[
'type' => 'text',
'text' => '<string>'
]
],
'id' => '<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://api.example.com/v1/sessions/{session_id}/events"
payload := strings.NewReader("{\n \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\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://api.example.com/v1/sessions/{session_id}/events")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/sessions/{session_id}/events")
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 \"events\": [\n {\n \"type\": \"user.message\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"<string>\"\n }\n ],\n \"id\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"type": "system.message",
"id": "<string>",
"processed_at": "<string>",
"content": [
{
"type": "text",
"text": "<string>"
}
]
}
]
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "authentication_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "not_found_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "conflict_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "payload_too_large",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "unsupported_media_type",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "rate_limit_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "internal_error",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}{
"type": "error",
"error": {
"type": "service_unavailable",
"message": "<string>",
"code": "session_awaiting_action"
},
"request_id": "<string>",
"accepted": "<array>",
"failed_index": 123,
"unconfirmed_index": 123
}Headers
Body
application/json