# End chat session (/docs/api-reference/chat-sessions/endChatSession)

> Save the chat and start post-call analysis (and, in a live chat, the agent's post-call actions). Ending a chat twice is harmless. A session with no message for 30 minutes is ended for you. Then call Get chat session until analysis_status is done to read the full record.

**POST** `/chat/sessions/{session_id}/end`

Save the chat and start post-call analysis (and, in a live chat, the
agent's post-call actions). Ending a chat twice is harmless. A session
with no message for 30 minutes is ended for you. Then call Get chat session until `analysis_status` is
`done` to read the full record.

```yaml
operationId: endChatSession
parameters:
  - name: session_id
    in: path
    required: true
    schema:
      type: integer
    description: The `session_id` from Create chat session.
responses:
  '200':
    description: The chat is saved. If it had already ended, how it ended is reported and nothing changes.
    content:
      application/json:
        schema:
          type: object
          properties:
            session_id:
              type: integer
              example: 4521
            status:
              type: string
              enum:
                - ended
            ended_by:
              type: string
              nullable: true
              enum:
                - agent
                - transfer
                - client
                - idle
                - turn_limit
              description: |
                How the chat ended: the agent ran its end call tool (`agent`) or
                transfer tool (`transfer`), you called End chat session (`client`),
                nobody wrote for 30 minutes (`idle`), or the agent sent 100 replies
                (`turn_limit`). Null while the chat is active.
            transferred_to:
              type: string
              nullable: true
              description: The number the agent transferred the customer to, if it did.
            transcript:
              type: array
              description: The whole chat, oldest first, once it has ended. The greeting has no customer line.
              items:
                type: object
                properties:
                  role:
                    type: string
                    enum:
                      - agent
                      - customer
                  text:
                    type: string
              example:
                - role: agent
                  text: Hi, this is Sam from Demo Dental. How can I help?
                - role: customer
                  text: I need to talk to a person.
                - role: agent
                  text: Sure, I am transferring you to +15551234567 now.
  '401':
    description: Missing or invalid API key.
  '404':
    description: Session not found in your organization.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: session_not_found
          error_description: Chat session not found or access denied
  '502':
    description: The chat could not be saved. Retry the request.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: agent_unavailable
          error_description: The chat could not be saved. Try again.
```

**curl**

```bash
curl -X POST "https://omnidim.io/api/v1/chat/sessions/{session_id}/end" \
  -H "Authorization: Bearer $OMNIDIM_API_KEY"
```