---
title: "Create Session"
method: POST
path: "/mle-agent/sessions"
tags: ["agent-chat-sessions"]
---

# Create Session

`POST /mle-agent/sessions`

Create a new chat session.

Args:
    request: FastAPI request used by the rate-limiter.
    body: Create payload.
    auth: Authenticated caller.
    service: Chat-session service.

Returns:
    ChatSessionResponse for the created session.

## Request body

- ChatSessionCreate — Request model for creating a chat session.
  - `title` string, nullable — Session title (auto-generated if not provided)
  - `first_message` string, nullable — First user message (used for auto-title generation)
  - `project_id` string, nullable — Optional project ID to scope the session to

## Response `200`

Successful Response

- ChatSessionResponse — Response model for a chat session (without messages).
  - `id` string, required
  - `user_id` string, required
  - `title` string, required
  - `created_at` string, required
  - `updated_at` string, required
  - `is_archived` boolean
  - `project_id` string, nullable
  - `images_retention_days` integer, nullable — Per-session image retention window in days for this chat's image attachments. NULL inherits the 30-day default; 0 means keep forever. Drives image eviction by the nightly cleanup job.
  - `modal_sandbox_id` string, nullable — Modal sandbox id for the persistent MLE agent runtime, if a sandbox is associated with this session. Surfaced for nightly smoke tests and observability — never used for client routing.
  - `first_user_attached_resources` AttachedResourceRef[] — Resource chips the user attached to the *first* user message of this session, parsed from its attached-context preamble. Powers the threads-sidebar preview so users can see at a glance what context a thread was anchored on without opening it. Empty when the session has no user messages or none of them carry a preamble.
    - `id` string, required — Type-prefixed resource id used by the frontend chip rendering. For example ``dataset:abc-123`` or ``model:tj-99``.
    - `name` string, required — Human-readable label rendered inside the chip.
    - `type` string, required — Resource type slug — one of ``dataset``, ``model``, ``evaluation``, or ``base-model``.

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/pioneer/apis/brain-api.md) · [All operations](https://skmtc.net/pioneer/apis/brain-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/pioneer/brain-api/revisions/31dfe831e079/schema)
