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

# End Session

> Finalize the session and start asynchronous processing. After this call no further audio uploads are accepted. The server collects and orders all uploaded chunks, commits the session, and queues it for transcription and template extraction. Poll `GET /voice/v1/sessions/{session_id}` (or use a webhook) to retrieve results once processing completes.


Finalize the session and start asynchronous processing. After this call, **no further audio uploads are accepted** for the session.

## What happens server-side

<Steps>
  <Step title="Collect & order chunks">
    The server lists every audio file uploaded to the session and sorts them by sequence number (`0.webm`, `1.webm`, …).
  </Step>

  <Step title="Commit the session">
    The session is committed (`user_status: commit`) so it can no longer receive uploads.
  </Step>

  <Step title="Queue for processing">
    A processing event is queued; transcription and template extraction run asynchronously.
  </Step>

  <Step title="Return 202 Accepted">
    The response confirms how many audio files were received and lists them.
  </Step>
</Steps>

## Path parameters

| Parameter    | Description                                                                                                |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
| `session_id` | The `session_id` returned by [Create Session](/api-reference/health-ai/ekascribe/protocol/create-session). |

## Request fields

| Field              | Type    | Required | Description                                                                                         |
| ------------------ | ------- | -------- | --------------------------------------------------------------------------------------------------- |
| `audio_files_sent` | integer | **Yes**  | Number of audio chunks/files the client sent. Used for validation against what the server received. |

## Response fields

| Field                  | Type      | Description                                           |
| ---------------------- | --------- | ----------------------------------------------------- |
| `session_id`           | string    | The session identifier.                               |
| `status`               | string    | Session status after ending — typically `processing`. |
| `message`              | string    | Human-readable status message.                        |
| `audio_files_received` | integer   | Count of audio files the server received and stored.  |
| `audio_files`          | string\[] | Ordered list of stored audio files.                   |

## Retrieving results

Processing is asynchronous. After receiving `202 Accepted`:

* **Poll** `GET /voice/v1/sessions/{session_id}` until `status` is `completed`. Status codes mirror processing state — `202` (in progress), `200` (completed), `206` (partial), `410` (expired).
* Or **register a webhook** to be notified automatically when processing completes.

The completed response includes the full `transcript` and the structured `templates` results for the template IDs requested at session creation.


## OpenAPI

````yaml POST /voice/v1/sessions/{session_id}/end
openapi: 3.0.1
info:
  title: EkaScribe Protocol API (MedScribeAlliance v0.1)
  version: '0.1'
  description: >
    Session-based medical voice capture API implementing the MedScribeAlliance
    Protocol v0.1. Discover service capabilities, create a session, stream audio
    chunks, then end the session to trigger asynchronous transcription and
    structured-template extraction.
servers:
  - url: https://api.eka.care
    description: Production server
  - url: https://api.dev.eka.care
    description: Development server
security: []
paths:
  /voice/v1/sessions/{session_id}/end:
    post:
      tags:
        - protocol
      summary: End Session
      description: >
        Finalize the session and start asynchronous processing. After this call
        no further audio uploads are accepted. The server collects and orders
        all uploaded chunks, commits the session, and queues it for
        transcription and template extraction. Poll `GET
        /voice/v1/sessions/{session_id}` (or use a webhook) to retrieve results
        once processing completes.
      parameters:
        - name: session_id
          in: path
          required: true
          description: Session ID returned by Create Session
          schema:
            type: string
            example: ses_abc123def456
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EndSessionRequest'
            example:
              audio_files_sent: 3
      responses:
        '202':
          description: Session ended, processing started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EndSessionResponse'
              example:
                session_id: ses_abc123def456
                status: processing
                message: Session ended. Processing started.
                audio_files_received: 3
                audio_files:
                  - 0.webm
                  - 1.webm
                  - 2.webm
        '400':
          description: Session already ended
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Session not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - auth: []
components:
  schemas:
    EndSessionRequest:
      type: object
      required:
        - audio_files_sent
      properties:
        audio_files_sent:
          type: integer
          minimum: 0
          description: Number of audio chunks/files the client sent, used for validation.
          example: 3
    EndSessionResponse:
      type: object
      properties:
        session_id:
          type: string
        status:
          type: string
          example: processing
        message:
          type: string
          example: Session ended. Processing started.
        audio_files_received:
          type: integer
          minimum: 0
        audio_files:
          type: array
          items:
            type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code.
              example: invalid_audio_format
            message:
              type: string
              description: Human-readable error message.
              example: Audio format 'audio/mp3' is not supported
            details:
              type: object
              additionalProperties: true
              description: Additional error context.
  securitySchemes:
    auth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your auth token.

````