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

# Manage Sessions

> Inspect and update sessions, cancel the current turn, and manage the session lifecycle.

Sessions run agents. After creating a session, submit input by sending `user.message` through the events endpoint. To create a session, see [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md).

## Check session status

`status` indicates the current state of a session. Public values are `idle`, `running`, `stopping`, and `terminated`.

| Status | Meaning |
| - | - |
| `idle` | Waiting for input, or the current turn has finished. |
| `running` | Executing the current turn. |
| `stopping` | A stop request was accepted and execution is being finalized. |
| `terminated` | The session has terminated and can no longer be used. |

Newly created sessions start in the `idle` state. When you send input, the session enters `running` and returns to `idle` once the turn finishes. Canceling the current turn moves the session to `stopping` while execution is finalized, then returns it to `idle`. Archiving transitions the session to `terminated`.

Use the command below to check the current status of a session. Replace `$SESSION_ID` with the `id` from the session creation response. For a full session creation example, see [Create a Session](https://platform.kimi.ai/docs/hosted-agents/sessions.md).

```bash cURL theme={null}
curl --silent --show-error --fail-with-body "https://api.moonshot.ai/v1/sessions/$SESSION_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions get "$SESSION_ID"
```

You can also observe status changes through `session.status` events in the event stream. When a session returns to `idle`, the event may include `data.stop_reason` indicating why the turn stopped; see [Event Stream](https://platform.kimi.ai/docs/hosted-agents/event-stream.md).

## List sessions

Call `GET /v1/sessions` to list sessions visible to the caller. `items` in the response contains the sessions on the current page; when more results exist, the response also includes `next_page_token` to fetch the next page.

| Parameter | Type | Description |
| - | - | - |
| `page_size` | `integer` | Number of items per page. |
| `page_token` | `string` | Pass `next_page_token` from the previous response to fetch the next page. |
| `order` | `"created_at" \| "created_at_desc" \| "updated_at" \| "updated_at_desc"` | Sort order for sessions; defaults to `updated_at_desc` when omitted. |
| `agent_id` | `string` | List only sessions for a specific agent. |
| `agent_version` | `string` | List only sessions pinned to a specific agent version; typically used together with `agent_id`. |
| `statuses` | `array[string]` | List only sessions in the specified lifecycle statuses (`idle`, `running`, `stopping`, `terminated`); includes all statuses when omitted. |
| `include_archived` | `boolean` | Pass `true` to include archived sessions in the list; excluded by default. |

```bash cURL theme={null}
curl --silent --show-error --fail-with-body "https://api.moonshot.ai/v1/sessions?page_size=20&order=updated_at_desc" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions list --limit 20 --order updated_at_desc
```

## Retrieve a session

Call `GET /v1/sessions/{id}` to retrieve session details.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body "https://api.moonshot.ai/v1/sessions/$SESSION_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions get "$SESSION_ID"
```

In the response, `agent` is the snapshot of the agent version pinned at creation time, and `resources` lists the resource references bound to the session (including files added after creation).

## Update the session title

Call `PATCH /v1/sessions/{id}` to update the session title. Fields omitted from the request body remain unchanged.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body --request PATCH "https://api.moonshot.ai/v1/sessions/$SESSION_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "title": "Updated session title"
  }'
```

```bash CLI theme={null}
kha sessions update "$SESSION_ID" --title "Updated session title"
```

## Override agent configuration in a session

You can update `agent_overrides` on a session to override the MCP server, skill, and tool configurations from the pinned agent version for subsequent turns in that session.

This operation does not modify the agent itself or create a new agent version.

`agent_overrides` supports `mcp_servers`, `skills`, `plugins`, `tools`, `model`, and `system`. `mcp_servers` accepts at most 20 servers, `skills` accepts at most 64 skills, `plugins` accepts at most 64 plugins, and `tools` accepts at most 128 declarations. `roster` can also be set when creating a session, and its entries are resolved and pinned to exact versions at creation time; passing `roster` when updating a session returns HTTP 400 `invalid_parameter_error`. The provider of `model` must match the session's model provider.

Each collection field is replaced in full rather than merged with the existing collection:

* Omitting a field retains the existing override configuration for that collection.
* Passing an empty array clears the override for that collection and falls back to the corresponding collection on the pinned agent version.
* Passing a non-empty array replaces the entire override for that collection.

The example below clears the `mcp_servers` override. It leaves `skills` and `tools` unchanged because neither field appears in the request body.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body --request PATCH "https://api.moonshot.ai/v1/sessions/$SESSION_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "agent_overrides": {
      "mcp_servers": []
    }
  }'
```

```bash CLI theme={null}
kha sessions update "$SESSION_ID" --file - <<'JSON'
{
  "agent_overrides": {
    "mcp_servers": []
  }
}
JSON
```

Updating `agent_overrides` does not require the session to be `idle`. Any turn currently in progress continues with the previous configuration, and subsequent turns use the updated configuration.

## Cancel the current turn

Send a `user.interrupt` event to `POST /v1/sessions/{id}/events` to stop the session and its active threads; `user.interrupt` must be the only event in the request. Both `running` and `idle` sessions accept stop requests; calling this endpoint on a `terminated` session returns HTTP 400 `failed_precondition_error`. When accepted, the endpoint responds with `202`; `user.interrupt` is not queued, and the response does not include an `event_id`.

Once canceled, the session returns to `idle` and can still receive new input.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body --request POST "https://api.moonshot.ai/v1/sessions/$SESSION_ID/events" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta" \
  --header "Content-Type: application/json" \
  --data '{
    "events": [
      { "type": "user.interrupt" }
    ]
  }'
```

```bash CLI theme={null}
kha sessions interrupt "$SESSION_ID"
```

## Archive a session

Call `POST /v1/sessions/{id}/archive` to set the session status to `terminated`. A `running` session cannot be archived (HTTP 400 `failed_precondition_error`). Cancel the current turn or wait for it to finish, and wait until the session returns to `idle` before archiving; a session that is still `stopping` returns HTTP 409 `conflict_error`. Archiving is irreversible. You can still read events and download files after archiving. If you plan to delete the session later, download anything you need to keep before deleting it, because deletion permanently removes them. An archived session is read-only and cannot accept further input.

The archive endpoint responds with `204`.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body --request POST "https://api.moonshot.ai/v1/sessions/$SESSION_ID/archive" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions archive "$SESSION_ID"
```

## Delete a session

Only `terminated` sessions can be deleted. Archive the session first, and then call `DELETE /v1/sessions/{id}` to delete it permanently. If the session is still bound to a trigger in `reuse_session` mode, archive that trigger first (otherwise deletion returns HTTP 400 `failed_precondition_error`). If lifecycle work or active threads remain right after archiving, deletion returns HTTP 409 `conflict_error`; retry once they finish. Deletion is irreversible—once deleted, the session, its events, and its resources can no longer be queried.

```bash cURL theme={null}
curl --silent --show-error --fail-with-body --request DELETE "https://api.moonshot.ai/v1/sessions/$SESSION_ID" \
  --header "Authorization: Bearer $KIMI_API_KEY" \
  --header "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions delete "$SESSION_ID"
```

The delete endpoint responds with `204`.
