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

# Deactivate Agent

> End the active session for an agent and return a summary.

## Overview

Terminates the current session for the specified agent and returns a summary including the start/end time, total duration, and number of memories stored during the session. If the session was authenticated via the `memanto_session_token` cookie, this call also clears that cookie.

## Authentication

<ParamField header="X-Session-Token" type="string" required>
  Session token from [Activate Agent](/api-reference/sessions/activate-agent). Must match `agent_id`.
</ParamField>

<ParamField header="Authorization" type="string">
  `Bearer <key>` — this endpoint additionally requires the management credential (or a loopback client), on top of the session token above. See [Management Endpoint Authentication](/api-reference/authentication#management-endpoint-authentication-agent-lifecycle).
</ParamField>

<ParamField header="X-Api-Key" type="string">
  Alternative to `Authorization: Bearer` — same credential.
</ParamField>

## Path Parameters

<ParamField path="agent_id" type="string" required>
  The unique identifier of the agent whose session should be ended.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "http://localhost:8000/api/v2/agents/my-agent/deactivate" \
    -H "X-Session-Token: your_session_token"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - OK theme={null}
  {
    "session_id": "9f733fdb-ebf2-494e-8eb6-fb3320d6020d",
    "agent_id": "my-agent",
    "started_at": "2026-05-09T02:40:00.313078Z",
    "ended_at": "2026-05-09T03:15:00.000000Z",
    "duration_hours": 0.58,
    "memories_created": 3,
    "summary_memory_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  }
  ```

  ```json 401 - Unauthorized (Missing Token) theme={null}
  {
    "detail": "Missing session token. Use X-Session-Token header."
  }
  ```

  ```json 401 - Unauthorized (Invalid or Expired Token) theme={null}
  {
    "detail": {
      "error": "InvalidSessionToken",
      "message": "Invalid session token: Not enough segments",
      "details": {}
    }
  }
  ```

  ```json 401 - Unauthorized (Management Auth Required) theme={null}
  {
    "detail": "Unauthorized. Agent management endpoints require either a loopback client or a valid management credential (Authorization: Bearer <key> or X-Api-Key)."
  }
  ```

  ```json 404 - Not Found theme={null}
  {
    "detail": {
      "error": "SessionNotFound",
      "message": "Session for agent 'my-agent' not found",
      "details": {}
    }
  }
  ```

  ```json 500 - Server Error theme={null}
  {
    "detail": {
      "error": "InternalServerError",
      "message": "An unexpected error occurred",
      "details": {
        "original_error": "Session is for agent 'other-agent', cannot access 'my-agent'"
      }
    }
  }
  ```
</ResponseExample>

## Next Steps

* [Activate Agent](/api-reference/sessions/activate-agent) to start a new session
* [List Agents](/api-reference/agents/list-agents) to view updated session counters
