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

# Create Session

> Create a new conversation session with an agent with configurable timeout and renewal policies

<Note>
  The Sessions API provides a simplified way to manage conversations without dealing with servers and channels. Sessions automatically handle timeout management, renewal, and expiration.
</Note>

## Request Body

<ParamField body="agentId" type="string" required>
  UUID of the agent to create a session with
</ParamField>

<ParamField body="userId" type="string" required>
  UUID of the user initiating the session
</ParamField>

<ParamField body="metadata" type="object">
  Optional metadata to attach to the session
</ParamField>

<ParamField body="timeoutConfig" type="object">
  Optional timeout configuration for the session

  <Expandable title="Timeout Configuration Properties">
    <ParamField body="timeoutMinutes" type="number">
      Inactivity timeout in minutes (5-1440). Default: 30
    </ParamField>

    <ParamField body="autoRenew" type="boolean">
      Whether to automatically renew on activity. Default: true
    </ParamField>

    <ParamField body="maxDurationMinutes" type="number">
      Maximum total session duration in minutes. Default: 720 (12 hours)
    </ParamField>

    <ParamField body="warningThresholdMinutes" type="number">
      Minutes before expiration to trigger warning. Default: 5
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="sessionId" type="string">
  Unique identifier for the created session
</ResponseField>

<ResponseField name="agentId" type="string">
  UUID of the agent
</ResponseField>

<ResponseField name="userId" type="string">
  UUID of the user
</ResponseField>

<ResponseField name="createdAt" type="string">
  ISO timestamp of session creation
</ResponseField>

<ResponseField name="expiresAt" type="string">
  ISO timestamp when the session will expire
</ResponseField>

<ResponseField name="timeoutConfig" type="object">
  The active timeout configuration for this session
</ResponseField>

<ResponseField name="metadata" type="object">
  Any metadata attached to the session
</ResponseField>


## OpenAPI

````yaml post /api/messaging/sessions
openapi: 3.1.0
info:
  title: Eliza OS API
  description: >-
    API documentation for Eliza OS v1.2.0 - A flexible and scalable AI agent
    framework.


    This API is designed to be used with a locally running Eliza instance.
    Endpoints allow for creating,

    managing, and interacting with AI agents through a REST interface.


    The API is organized into the following domains:

    - **System**: System-wide operations and environment management

    - **Agents**: Agent lifecycle and management operations

    - **Memory**: Agent memory and room management

    - **Messaging**: Message handling, channels, and servers

    - **Audio**: Audio processing and speech synthesis

    - **Media**: File upload and media management

    - **TEE**: Trusted Execution Environment operations

    - **WebSocket**: Real-time communication via Socket.IO
  version: 1.2.0
  contact:
    name: Eliza OS Community
    url: https://github.com/elizaos/eliza
servers:
  - url: http://localhost:3000
    description: Local development server
security: []
tags:
  - name: system
    description: System-wide operations and environment management
  - name: agents
    description: Operations for managing AI agents
  - name: memory
    description: Operations for managing agent memories
  - name: rooms
    description: Operations for managing rooms
  - name: messaging
    description: Operations for messages, channels, and servers
  - name: audio
    description: Operations for speech and audio processing
  - name: media
    description: Operations for file uploads and media management
  - name: logs
    description: Operations for accessing system and agent logs
  - name: tee
    description: Trusted Execution Environment operations
  - name: websocket
    description: Real-time WebSocket communication
paths:
  /api/messaging/sessions:
    post:
      tags:
        - messaging
      summary: Create a new session
      description: >
        Creates a new chat session for a user with a specific agent. Sessions
        provide a simplified way to interact

        with agents without the complexity of managing servers, channels, or
        participants.


        **Key Benefits:**

        - No channel management required - just provide agent and user IDs

        - Automatic infrastructure handling - no need to create servers or
        channels

        - Persistent conversation state maintained across messages

        - Ideal for building chat interfaces, personal assistants, and direct
        user-to-agent interactions


        Sessions maintain conversation state and context across multiple
        messages, providing a persistent chat experience

        similar to modern AI assistants.
      operationId: createSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - agentId
                - userId
              properties:
                agentId:
                  type: string
                  format: uuid
                  description: ID of the agent to start a session with
                userId:
                  type: string
                  format: uuid
                  description: ID of the user creating the session
                metadata:
                  type: object
                  description: Additional metadata for the session
                  properties:
                    platform:
                      type: string
                      description: Platform the session is created from
                    username:
                      type: string
                      description: Username of the user
                    discriminator:
                      type: string
                      description: User discriminator (e.g., Discord discriminator)
                    avatar:
                      type: string
                      description: URL to user's avatar
                timeoutConfig:
                  type: object
                  description: Optional timeout configuration for the session
                  properties:
                    timeoutMinutes:
                      type: integer
                      minimum: 5
                      maximum: 1440
                      description: Inactivity timeout in minutes (5-1440). Default 30
                    autoRenew:
                      type: boolean
                      description: Whether to automatically renew on activity. Default true
                    maxDurationMinutes:
                      type: integer
                      description: >-
                        Maximum total session duration in minutes. Default 720
                        (12 hours)
                    warningThresholdMinutes:
                      type: integer
                      description: Minutes before expiration to trigger warning. Default 5
      responses:
        '201':
          description: Session created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  sessionId:
                    type: string
                    description: Unique identifier for the created session
                  agentId:
                    type: string
                    format: uuid
                  userId:
                    type: string
                    format: uuid
                  createdAt:
                    type: string
                    format: date-time
                  metadata:
                    type: object
                  expiresAt:
                    type: string
                    format: date-time
                    description: When the session will expire
                  timeoutConfig:
                    type: object
                    description: Active timeout configuration for the session
                    properties:
                      timeoutMinutes:
                        type: integer
                      autoRenew:
                        type: boolean
                      maxDurationMinutes:
                        type: integer
                      warningThresholdMinutes:
                        type: integer
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Agent not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          properties:
            code:
              type: string
              description: Error code
            message:
              type: string
              description: Error message
            details:
              type: string
              description: Detailed error information

````