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

# End session

> Ends an active session: marks it `ended` and tears down its LiveKit room so per-minute billing stops. A session that is already terminal (ended/failed/expired) is frozen, so this returns the row unchanged. Takes no request body. Scope `sessions:write`.



## OpenAPI

````yaml /api-reference/openapi.json post /sessions/{session_id}/end
openapi: 3.1.0
info:
  title: Lehar API
  version: v0
  description: >-
    Customer-facing REST API for the Lehar voice-AI platform. Platform-admin
    endpoints are intentionally excluded from this reference. Regenerate with
    `npm run sync:openapi`.
servers:
  - url: https://api.lehar.ai/ca/api/v0
security:
  - ApiKeyAuth: []
  - BearerAuth: []
paths:
  /sessions/{session_id}/end:
    post:
      tags:
        - Sessions
      summary: End session
      description: >-
        Ends an active session: marks it `ended` and tears down its LiveKit room
        so per-minute billing stops. A session that is already terminal
        (ended/failed/expired) is frozen, so this returns the row unchanged.
        Takes no request body. Scope `sessions:write`.
      operationId: end_customer_session_ca_api_v0_sessions__session_id__end_post
      parameters:
        - name: session_id
          in: path
          required: true
          description: The session's session_id.
          schema:
            type: string
      responses:
        '200':
          description: The session after the end transition.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  session_id:
                    type: string
                  customer_id:
                    type: string
                  user_id:
                    type: string
                    nullable: true
                  user_name:
                    type: string
                    nullable: true
                  agent_id:
                    type: string
                  room_name:
                    type: string
                    nullable: true
                  participant_identity:
                    type: string
                    nullable: true
                  participant_name:
                    type: string
                    nullable: true
                  dispatch_id:
                    type: string
                    nullable: true
                  livekit_url:
                    type: string
                    nullable: true
                  status:
                    type: string
                    enum:
                      - active
                      - ended
                      - failed
                      - expired
                  qualification_status:
                    type: string
                    enum:
                      - pending
                      - qualified
                      - not_qualified
                      - inconclusive
                    nullable: true
                  sentiment:
                    type: string
                    enum:
                      - positive
                      - negative
                      - neutral
                    nullable: true
                  metadata:
                    type: object
                    additionalProperties: true
                  call_type:
                    type: string
                    description: web, outbound_phone, or inbound_phone.
                  origin:
                    type: string
                    enum:
                      - dashboard
                      - api
                      - campaign
                      - inbound
                      - test
                    nullable: true
                  call_id:
                    type: string
                    nullable: true
                  started_at:
                    type: string
                    format: date-time
                  ended_at:
                    type: string
                    format: date-time
                    nullable: true
                  created_at:
                    type: string
                    format: date-time
                  updated_at:
                    type: string
                    format: date-time
              example:
                id: 01k4qx7m8p2rs5t7v9w1x3y5z7
                session_id: session_01k4qx7m8p2rs5t7v9w1x3y5z7
                customer_id: customer_01k3ab2c4d6e8f0g2h4j6k8m0n
                user_id: user_01k2zzs7q9r1s3t5v7w9x1y3z5
                user_name: Priya Sharma
                agent_id: agent_01k1mn3p5q7r9s1t3v5w7x9y1z
                room_name: session_01k4qx7m8p2rs5t7v9w1x3y5z7
                participant_identity: user_01k2zzs7q9r1s3t5v7w9x1y3z5
                participant_name: Priya Sharma
                dispatch_id: AD_9f2c1a7b
                livekit_url: wss://lehar-staging.livekit.cloud
                status: ended
                qualification_status: null
                sentiment: null
                metadata:
                  agent_id: agent_01k1mn3p5q7r9s1t3v5w7x9y1z
                  user_name: Priya Sharma
                  call_type: web
                call_type: web
                origin: dashboard
                call_id: null
                started_at: '2026-09-02T10:15:30.482119+00:00'
                ended_at: '2026-09-02T10:19:04.113587+00:00'
                created_at: '2026-09-02T10:15:30.482119+00:00'
                updated_at: '2026-09-02T10:19:04.113587+00:00'
        '400':
          description: The request has no resolvable customer_id.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
              example:
                error:
                  code: invalid_request
                  message: >-
                    customer_id is required for session APIs. Use a
                    customer-scoped user or send X-Customer-ID with a platform
                    bearer token.
        '401':
          description: No valid authentication was provided.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
              example:
                error:
                  code: unauthorized
                  message: Authentication required
        '403':
          description: The caller lacks the sessions:write scope.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
              example:
                error:
                  code: forbidden
                  message: Scope 'sessions:write' is required
        '404':
          description: >-
            No such session (or not visible to this caller), or the resolved
            customer_id does not exist.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
              example:
                error:
                  code: not_found
                  message: Session not found
        '500':
          description: An unexpected server error occurred.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
              example:
                error:
                  code: internal_error
                  message: An unexpected error occurred
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
    BearerAuth:
      type: http
      scheme: bearer

````