Stop Session
Ends an active session and releases server resources. You should always call this when the user finishes the conversation or closes the browser so usage is billed correctly. This is the final step in the overall flow.
POST/api/v2/sessions/stop
Headers
| Header | Value |
|---|---|
| STUDIO-API-KEY | {userKey} |
| Content-Type | application/json |
Body
| Parameter | Type | Required | Description |
|---|---|---|---|
| session_id | string | required | Session to stop. Use data.session_id from the Start Session response |
| reason | enum | required | Close reason. See supported values below. |
Supported reason values:
UNKNOWN, USER_DISCONNECTED, SERVER_ERROR, IDLE_TIMEOUT, NO_CREDITS, USER_CLOSED, AVATAR_DELETED, MAX_DURATION_REACHED, ZOMBIE_SESSION_REAP, USER_REQUEST_STOP, JOB_COMPLETED, JOB_CANCELLED, JOB_FAILED, BILLING_FAILED, BILLING_CANCELLED, TIMEOUT_INACTIVE, SERVER_SHUTDOWN
Examples
- cURL
- Node.js
- Python
curl https://ai-streamer.deepbrain.io/api/v2/sessions/stop \
-H "Content-Type: application/json" \
-H "STUDIO-API-KEY: ${userKey}" \
-X POST \
-d '{
"session_id": "${SESSION_ID}",
"reason": "USER_CLOSED"
}'
import axios from "axios";
const userKey = "${userKey}";
axios
.post(
"https://ai-streamer.deepbrain.io/api/v2/sessions/stop",
{
session_id: "${SESSION_ID}",
reason: "USER_CLOSED",
},
{
headers: {
"STUDIO-API-KEY": userKey,
"Content-Type": "application/json",
},
},
)
.then((res) => {
console.log(res.data);
})
.catch((error) => {
console.error(error);
});
import requests
url = 'https://ai-streamer.deepbrain.io/api/v2/sessions/stop'
user_key = '${userKey}'
headers = {
'STUDIO-API-KEY': user_key,
'Content-Type': 'application/json'
}
body = {
'session_id': '${SESSION_ID}',
'reason': 'USER_CLOSED'
}
response = requests.post(url, headers=headers, json=body)
print(response.json())
Success (code: 1000)
{
"code": 1000,
"data": null,
"message": "Session stopped successfully"
}
Next step
After a successful stop, billing stops and all resources for the session are released.