Skip to main content
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>'
{
  "success": true,
  "session": {
    "session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
    "status": "ended",
    "started_at": "2024-01-15T10:30:00Z",
    "ended_at": "2024-01-15T10:35:00Z"
  }
}
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

session_id
string
required
The session ID to end

Response

success
boolean
Whether the request was successful
session
object
The updated session object (See Session schema).

Important Notes

  • Only active sessions (status: started) can be ended
  • Marks the session with an ended_at timestamp
  • Session status transitions from started to ended
  • 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.
Sessions are automatically terminated instantly when:
  • WebSocket disconnects - When the WebSocket connection is closed or lost
  • 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
Safety Mechanism: If automatic termination fails for any reason, our system has a safety check that will detect and clean up orphaned sessions within 3 minutes. This ensures sessions are always terminated even in edge cases where the instant triggers don’t fire.
{
  "success": true,
  "session": {
    "session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
    "status": "ended",
    "started_at": "2024-01-15T10:30:00Z",
    "ended_at": "2024-01-15T10:35:00Z"
  }
}