End Session
curl --request POST \
--url https://api.agenthuman.com/v1/sessions/{session_id}/end \
--header 'x-api-key: <api-key>'import requests
url = "https://api.agenthuman.com/v1/sessions/{session_id}/end"
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.agenthuman.com/v1/sessions/{session_id}/end', 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.agenthuman.com/v1/sessions/{session_id}/end",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-api-key: <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"
"net/http"
"io"
)
func main() {
url := "https://api.agenthuman.com/v1/sessions/{session_id}/end"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.agenthuman.com/v1/sessions/{session_id}/end")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agenthuman.com/v1/sessions/{session_id}/end")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended",
"started_at": "2024-01-15T10:30:00Z",
"ended_at": "2024-01-15T10:35:00Z"
}
}
{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended"
}
}
{
"success": false,
"error": {
"message": "Cannot end a session that was never started",
"suggestion": "Only sessions with status \"started\" can be ended"
}
}
{
"success": false,
"error": {
"message": "Session not found",
"suggestion": "Verify the session ID is correct"
}
}
Sessions
End Session
Stop the avatar server and release resources
POST
/
v1
/
sessions
/
{session_id}
/
end
End Session
curl --request POST \
--url https://api.agenthuman.com/v1/sessions/{session_id}/end \
--header 'x-api-key: <api-key>'import requests
url = "https://api.agenthuman.com/v1/sessions/{session_id}/end"
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.agenthuman.com/v1/sessions/{session_id}/end', 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.agenthuman.com/v1/sessions/{session_id}/end",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-api-key: <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"
"net/http"
"io"
)
func main() {
url := "https://api.agenthuman.com/v1/sessions/{session_id}/end"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.agenthuman.com/v1/sessions/{session_id}/end")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agenthuman.com/v1/sessions/{session_id}/end")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended",
"started_at": "2024-01-15T10:30:00Z",
"ended_at": "2024-01-15T10:35:00Z"
}
}
{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended"
}
}
{
"success": false,
"error": {
"message": "Cannot end a session that was never started",
"suggestion": "Only sessions with status \"started\" can be ended"
}
}
{
"success": false,
"error": {
"message": "Session not found",
"suggestion": "Verify the session ID is correct"
}
}
What This Does: Gracefully stops the avatar server, releases GPU resources and marks the session as ended. Call this when you’re done with the conversation to avoid unnecessary charges.
Path Parameters
string
required
The session ID to end
Response
boolean
Whether the request was successful
object
The updated session object (See Session schema).
Important Notes
- Only active sessions (status:
started) can be ended - Marks the session with an
ended_attimestamp - Session status transitions from
startedtoended - Once ended, the session cannot be restarted
- If the session is already ended, the API returns
success: true.
Automatic Termination Handling
Best Practice: Always explicitly call this endpoint when you’re done with a session to ensure immediate resource release and billing accuracy.
- Client leaves the video room - When all participants leave the Daily/LiveKit room
- Session timeout - When the session reaches its expiration time based on plan limits
{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended",
"started_at": "2024-01-15T10:30:00Z",
"ended_at": "2024-01-15T10:35:00Z"
}
}
{
"success": true,
"session": {
"session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
"status": "ended"
}
}
{
"success": false,
"error": {
"message": "Cannot end a session that was never started",
"suggestion": "Only sessions with status \"started\" can be ended"
}
}
{
"success": false,
"error": {
"message": "Session not found",
"suggestion": "Verify the session ID is correct"
}
}