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

# Create new session



## OpenAPI

````yaml post /sessions
openapi: 3.1.0
info:
  title: Agno AgentOS
  description: An agent operating system.
  version: 1.0.0
servers: []
security: []
paths:
  /sessions:
    post:
      tags:
        - Sessions
      summary: Create New Session
      description: >-
        Create a new empty session with optional configuration. Useful for
        pre-creating sessions with specific session_state, metadata, or other
        properties before running any agent/team/workflow interactions. The
        session can later be used by providing its session_id in run requests.
      operationId: create_session
      parameters:
        - name: type
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/SessionType'
            description: Type of session to create (agent, team, or workflow)
            default: agent
          description: Type of session to create (agent, team, or workflow)
        - name: db_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Database ID to create session in
            title: Db Id
          description: Database ID to create session in
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSessionRequest'
              description: Session configuration data
              default: {}
      responses:
        '201':
          description: Session created successfully
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/AgentSessionDetailSchema'
                  - $ref: '#/components/schemas/TeamSessionDetailSchema'
                  - $ref: '#/components/schemas/WorkflowSessionDetailSchema'
                title: Response Create Session
              examples:
                agent_session_example:
                  summary: Example created agent session
                  value:
                    user_id: user-123
                    agent_session_id: new-session-id
                    session_id: new-session-id
                    session_name: New Session
                    session_state:
                      key: value
                    metadata:
                      key: value
                    agent_id: agent-1
                    created_at: '2025-10-21T12:00:00Z'
                    updated_at: '2025-10-21T12:00:00Z'
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthenticatedResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundResponse'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
        '500':
          description: Failed to create session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
      security:
        - HTTPBearer: []
components:
  schemas:
    SessionType:
      type: string
      enum:
        - agent
        - team
        - workflow
      title: SessionType
    CreateSessionRequest:
      properties:
        session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Id
        session_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Name
        session_state:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session State
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
        team_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Team Id
        workflow_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Workflow Id
      type: object
      title: CreateSessionRequest
    AgentSessionDetailSchema:
      properties:
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
        agent_session_id:
          type: string
          title: Agent Session Id
        session_id:
          type: string
          title: Session Id
        session_name:
          type: string
          title: Session Name
        session_summary:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session Summary
        session_state:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session State
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
        total_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Total Tokens
        agent_data:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Agent Data
        metrics:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metrics
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
        chat_history:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Chat History
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
      type: object
      required:
        - user_id
        - agent_session_id
        - session_id
        - session_name
        - session_summary
        - session_state
        - agent_id
        - total_tokens
        - agent_data
        - metrics
        - metadata
        - chat_history
        - created_at
        - updated_at
      title: AgentSessionDetailSchema
    TeamSessionDetailSchema:
      properties:
        session_id:
          type: string
          title: Session Id
        session_name:
          type: string
          title: Session Name
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
        team_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Team Id
        session_summary:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session Summary
        session_state:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session State
        metrics:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metrics
        team_data:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Team Data
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
        chat_history:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Chat History
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
        total_tokens:
          anyOf:
            - type: integer
            - type: 'null'
          title: Total Tokens
      type: object
      required:
        - session_id
        - session_name
        - user_id
        - team_id
        - session_summary
        - session_state
        - metrics
        - team_data
        - metadata
        - chat_history
        - created_at
        - updated_at
        - total_tokens
      title: TeamSessionDetailSchema
    WorkflowSessionDetailSchema:
      properties:
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
        workflow_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Workflow Id
        workflow_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Workflow Name
        session_id:
          type: string
          title: Session Id
        session_name:
          type: string
          title: Session Name
        session_data:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session Data
        session_state:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Session State
        workflow_data:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Workflow Data
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
        created_at:
          anyOf:
            - type: integer
            - type: 'null'
          title: Created At
        updated_at:
          anyOf:
            - type: integer
            - type: 'null'
          title: Updated At
      type: object
      required:
        - user_id
        - workflow_id
        - workflow_name
        - session_id
        - session_name
        - session_data
        - session_state
        - workflow_data
        - metadata
        - created_at
        - updated_at
      title: WorkflowSessionDetailSchema
    BadRequestResponse:
      properties:
        detail:
          type: string
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
      type: object
      required:
        - detail
      title: BadRequestResponse
      example:
        detail: Bad request
        error_code: BAD_REQUEST
    UnauthenticatedResponse:
      properties:
        detail:
          type: string
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
      type: object
      required:
        - detail
      title: UnauthenticatedResponse
      example:
        detail: Unauthenticated access
        error_code: UNAUTHENTICATED
    NotFoundResponse:
      properties:
        detail:
          type: string
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
      type: object
      required:
        - detail
      title: NotFoundResponse
      example:
        detail: Not found
        error_code: NOT_FOUND
    ValidationErrorResponse:
      properties:
        detail:
          type: string
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
      type: object
      required:
        - detail
      title: ValidationErrorResponse
      example:
        detail: Validation error
        error_code: VALIDATION_ERROR
    InternalServerErrorResponse:
      properties:
        detail:
          type: string
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
      type: object
      required:
        - detail
      title: InternalServerErrorResponse
      example:
        detail: Internal server error
        error_code: INTERNAL_SERVER_ERROR
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````