> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agenthuman.com/llms.txt
> Use this file to discover all available pages before exploring further.

# End Session

> Stop the avatar server and release resources

<Note>
  **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.
</Note>

### Path Parameters

<ParamField path="session_id" type="string" required>
  The session ID to end
</ParamField>

### Response

<ResponseField name="success" type="boolean">
  Whether the request was successful
</ResponseField>

<ResponseField name="session" type="object">
  The updated session object (See [Session schema](/api-reference/schemas/session)).
</ResponseField>

### Important Notes

<Note>
  * 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`.
</Note>

### Automatic Termination Handling

<Warning>
  **Best Practice:** Always explicitly call this endpoint when you're done with a session to ensure immediate resource release and billing accuracy.
</Warning>

**Sessions are automatically terminated instantly when:**

* **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.

<ResponseExample>
  ```json 200 - Success theme={null}
  {
    "success": true,
    "session": {
      "session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
      "status": "ended",
      "started_at": "2024-01-15T10:30:00Z",
      "ended_at": "2024-01-15T10:35:00Z"
    }
  }
  ```

  ```json 200 - Already Ended theme={null}
  {
    "success": true,
    "session": {
      "session_id": "sess_01H3Z8G9YR3K2N5M6P7Q8W4T",
      "status": "ended"
    }
  }
  ```

  ```json 400 - Not Started theme={null}
  {
    "success": false,
    "error": {
      "message": "Cannot end a session that was never started",
      "suggestion": "Only sessions with status \"started\" can be ended"
    }
  }
  ```

  ```json 404 - Not Found theme={null}
  {
    "success": false,
    "error": {
      "message": "Session not found",
      "suggestion": "Verify the session ID is correct"
    }
  }
  ```
</ResponseExample>
