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

# End a chat session under the `user_end` reason.

> Runs the same lifecycle pipeline a voice call's completion does: post-call analysis,
completion webhook, Postgres CallResult, Elasticsearch index, audit event. Idempotent —
calling on an already-final session returns the current snapshot without re-running the
pipeline.



## OpenAPI

````yaml https://blackbox.dasha.ai/swagger/v1/swagger.json post /api/v1/chats/{id}/end
openapi: 3.0.4
info:
  title: Dasha BlackBox Agent API
  description: API for managing AI agents and calls
  contact:
    name: DashaAI Team
    email: support@dasha.ai
  version: v1
servers:
  - url: https://blackbox.dasha.ai
    description: Dasha BlackBox Agent API
security:
  - {}
  - {}
tags:
  - name: ActivityLogs
  - name: Agents
  - name: CallResults
  - name: Calls
  - name: Chats
  - name: CustomerData
  - name: Mcp
  - name: Media
  - name: Misc
  - name: PronunciationDictionaries
  - name: Providers
  - name: SipAliases
  - name: SipCredentials
  - name: SipPhoneNumbers
  - name: TextChat
  - name: TwilioProvider
  - name: Voice
  - name: WebhookTest
  - name: WebIntegrations
  - name: WebSocket
    description: WebSocket endpoints for real-time communication
paths:
  /api/v1/chats/{id}/end:
    post:
      tags:
        - Chats
      summary: End a chat session under the `user_end` reason.
      description: >-
        Runs the same lifecycle pipeline a voice call's completion does:
        post-call analysis,

        completion webhook, Postgres CallResult, Elasticsearch index, audit
        event. Idempotent —

        calling on an already-final session returns the current snapshot without
        re-running the

        pipeline.
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EndChatRequest'
              description: >-
                Request body for `POST /api/v1/chats/{id}/end`. Always finalises
                the session under

                the `user_end` reason (the TTL sweeper uses `ttl`, the agent
                uses

                `agent_finish`) and runs the same
                !:TextChatCallLifecycle.FinishAsync

                pipeline a voice call uses — completion webhook + post-call
                analysis + persistence.
          text/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EndChatRequest'
              description: >-
                Request body for `POST /api/v1/chats/{id}/end`. Always finalises
                the session under

                the `user_end` reason (the TTL sweeper uses `ttl`, the agent
                uses

                `agent_finish`) and runs the same
                !:TextChatCallLifecycle.FinishAsync

                pipeline a voice call uses — completion webhook + post-call
                analysis + persistence.
          application/*+json:
            schema:
              allOf:
                - $ref: '#/components/schemas/EndChatRequest'
              description: >-
                Request body for `POST /api/v1/chats/{id}/end`. Always finalises
                the session under

                the `user_end` reason (the TTL sweeper uses `ttl`, the agent
                uses

                `agent_finish`) and runs the same
                !:TextChatCallLifecycle.FinishAsync

                pipeline a voice call uses — completion webhook + post-call
                analysis + persistence.
      responses:
        '200':
          description: Session ended (or was already final).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatSessionDto'
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
        '404':
          description: No session with this id exists for the caller's organization.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetails'
components:
  schemas:
    EndChatRequest:
      type: object
      properties:
        note:
          type: string
          description: >-
            Optional operator-supplied free-form note appended to the activity
            log for this

            finalisation. Not used by the pipeline; purely audit metadata.
          nullable: true
      additionalProperties: false
      description: >-
        Request body for `POST /api/v1/chats/{id}/end`. Always finalises the
        session under

        the `user_end` reason (the TTL sweeper uses `ttl`, the agent uses

        `agent_finish`) and runs the same !:TextChatCallLifecycle.FinishAsync

        pipeline a voice call uses — completion webhook + post-call analysis +
        persistence.
    ChatSessionDto:
      type: object
      properties:
        id:
          type: string
          description: Session identifier.
          format: uuid
        agent_id:
          type: string
          description: Agent driving this session. Frozen at open.
          nullable: true
        channel:
          type: string
          description: Channel name (`web`, `twilio_sms`, …).
          nullable: true
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessageDto'
          description: Full conversation transcript so far, in send order.
          nullable: true
        created_time:
          type: string
          description: Session creation timestamp (UTC).
          format: date-time
        last_activity:
          type: string
          description: >-
            Most recent activity timestamp (inbound, outbound or assistant
            turn).
          format: date-time
        ttl_seconds:
          type: integer
          description: Inactivity timeout in seconds; null when no TTL applies.
          format: int32
          nullable: true
        is_final:
          type: boolean
          description: True once the session has terminated.
        status:
          type: string
          description: >-
            Status mirror of
            DashaAI.BlackBox.AgentAPI.TextChat.Dtos.Chats.ChatSessionDto.IsFinal
            for list-endpoint filtering (`active` /

            `final`).
          nullable: true
        final_reason:
          type: string
          description: Reason for finalisation (`ttl`, `user_end`, `agent_finish`, …).
          nullable: true
      additionalProperties: false
      description: >-
        Public projection of a chat session — what callers see via `GET
        /api/v1/chats/{id}`

        and the list endpoint. Deliberately omits the orchestration `State`
        blob, the

        `ExternalIdHash`, and the worker hot-flags; those are server-internal.
    ProblemDetails:
      type: object
      properties:
        type:
          type: string
          nullable: true
        title:
          type: string
          nullable: true
        status:
          type: integer
          format: int32
          nullable: true
        detail:
          type: string
          nullable: true
        instance:
          type: string
          nullable: true
      additionalProperties: {}
    ChatMessageDto:
      type: object
      properties:
        role:
          type: string
          description: One of "user", "assistant", "system".
          nullable: true
        content:
          type: string
          description: >-
            Plain-text message content. Null when the assistant message only
            contains tool calls.
          nullable: true
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ChatToolCallDto'
          description: >-
            Tool calls produced by the assistant this turn, bundled with their
            responses.
          nullable: true
        time:
          type: string
          description: >-
            Real wall-clock time of the message. The server stamps the messages
            it produces and

            echoes back any client-supplied value; it is used verbatim for the
            call transcript /

            post-call analysis instead of a synthesized clock. One timestamp per
            chat message is

            enough — chat messages are point-in-time events, unlike voice
            utterances. Optional.
          format: date-time
          nullable: true
      additionalProperties: false
      description: >-
        Wire-format text-chat message. Supports user / assistant / system roles.

        Tool invocations are bundled — a single assistant message carries the
        tool call(s)

        alongside their executed response(s) via
        DashaAI.BlackBox.AgentAPI.TextChat.Dtos.ChatMessageDto.ToolCalls.
    ChatToolCallDto:
      type: object
      properties:
        id:
          type: string
          description: >-
            Tool call identifier propagated through the OpenAI round-trip.
            Required.
          nullable: true
        name:
          type: string
          description: >-
            Tool name as registered with the agent (built-in, agent-defined
            function, or MCP).
          nullable: true
        arguments:
          description: >-
            Tool arguments emitted by the LLM, as a JSON object. May be omitted
            for tools with no parameters.
        response:
          description: >-
            Tool response. Set after the server executes the tool. Null while
            the request is still in flight

            (only happens internally — wire-format messages from the client
            always include the response).
          nullable: true
      additionalProperties: false
      description: >-
        Combined tool call: the LLM-generated request and the executed response
        in a single object.

        Wire-format choice — internally the orchestrator translates to OpenAI's
        split assistant/tool format.

````