curl --request POST \
--url https://api.example.com/api/v1/sessions/{session_id}/turns \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"input": [
{
"content": "<string>",
"type": "user.message"
}
],
"previous_turn_id": "auto",
"stream": true
}
'import requests
url = "https://api.example.com/api/v1/sessions/{session_id}/turns"
payload = {
"input": [
{
"content": "<string>",
"type": "user.message"
}
],
"previous_turn_id": "auto",
"stream": True
}
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({
input: [{content: '<string>', type: 'user.message'}],
previous_turn_id: 'auto',
stream: true
})
};
fetch('https://api.example.com/api/v1/sessions/{session_id}/turns', 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/api/v1/sessions/{session_id}/turns",
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([
'input' => [
[
'content' => '<string>',
'type' => 'user.message'
]
],
'previous_turn_id' => 'auto',
'stream' => true
]),
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/api/v1/sessions/{session_id}/turns"
payload := strings.NewReader("{\n \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\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/api/v1/sessions/{session_id}/turns")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/sessions/{session_id}/turns")
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 \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\n}"
response = http.request(request)
puts response.read_body{
"data": {
"created_at": "<string>",
"id": "<string>",
"previous_turn_id": "<string>",
"session_id": "<string>",
"state": {
"status": "running"
},
"input": [
{
"content": "<string>",
"type": "user.message"
}
]
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}Create and execute a turn in a session
Create a turn within a session and execute it.
Only the session creator may create turns.
When stream is true (default), respond with a Server-Sent Events stream of turn events.
When stream is false, return the turn immediately with state.status: "running" while execution continues in the background; use get turn or subscribe to observe completion.
Use previous_turn_id to chain to the session’s last turn (defaults to auto); use none for a new root.
curl --request POST \
--url https://api.example.com/api/v1/sessions/{session_id}/turns \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"input": [
{
"content": "<string>",
"type": "user.message"
}
],
"previous_turn_id": "auto",
"stream": true
}
'import requests
url = "https://api.example.com/api/v1/sessions/{session_id}/turns"
payload = {
"input": [
{
"content": "<string>",
"type": "user.message"
}
],
"previous_turn_id": "auto",
"stream": True
}
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({
input: [{content: '<string>', type: 'user.message'}],
previous_turn_id: 'auto',
stream: true
})
};
fetch('https://api.example.com/api/v1/sessions/{session_id}/turns', 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/api/v1/sessions/{session_id}/turns",
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([
'input' => [
[
'content' => '<string>',
'type' => 'user.message'
]
],
'previous_turn_id' => 'auto',
'stream' => true
]),
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/api/v1/sessions/{session_id}/turns"
payload := strings.NewReader("{\n \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\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/api/v1/sessions/{session_id}/turns")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/sessions/{session_id}/turns")
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 \"input\": [\n {\n \"content\": \"<string>\",\n \"type\": \"user.message\"\n }\n ],\n \"previous_turn_id\": \"auto\",\n \"stream\": true\n}"
response = http.request(request)
puts response.read_body{
"data": {
"created_at": "<string>",
"id": "<string>",
"previous_turn_id": "<string>",
"session_id": "<string>",
"state": {
"status": "running"
},
"input": [
{
"content": "<string>",
"type": "user.message"
}
]
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"code": "<string>",
"param": "<string>",
"type": "<string>"
}
}Authorizations
Caller credential (Authorization: Bearer <token>). Required on protected routes when auth is enabled. Browser sessions may use the HttpOnly id_token or accessToken cookie instead.
Path Parameters
Session identifier.
1 - 64Body
Turn input items: user messages and/or approval/tool-response resumes. Do not mix user messages with approval or tool-response items.
- Option 1
- Option 2
- Option 3
Show child attributes
Show child attributes
Defaults to 'auto' (chain to session last turn). Use 'none' for a new root turn.
auto When true (default), stream turn events as SSE. When false, return the running turn immediately.
Response
When stream is false: the running turn. When stream is true: Server-Sent Events stream of turn events.
Show child attributes
Show child attributes