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

# Create Realtime Ws Token

> Mint a short-lived realtime token for WebSocket or SSE authentication.

Connection flow:

1. Call `POST /ws/token` with your `capout-api-key`.
2. Read `token`, `ws_url`, and `sse_url` from the response.
3. Connect to `wss://api.capout.ai/ws/status?token=<token>` for WebSocket updates,
   or `https://api.capout.ai/sse/status?token=<token>` for Server-Sent Events.
4. Optionally scope the initial subscription with either:
   - `&document_id=<document_id>` repeated one or more times
   - `&recent=10` to subscribe to the most recent organization-owned documents

WebSocket example:

`wss://api.capout.ai/ws/status?token=<token>&document_id=doc_123`

SSE example:

`https://api.capout.ai/sse/status?token=<token>&recent=10`

After a WebSocket connection is established, clients can send JSON commands such as:

`{"action":"subscribe","document_ids":["doc_123"]}`



## OpenAPI

````yaml /openapi.json post /ws/token
openapi: 3.1.0
info:
  title: Capout API
  description: >-
    Programmatic REST, WebSocket, and SSE API for uploading documents, tracking
    processing status, and reading claim balances.
  version: 1.0.0
servers:
  - url: https://api.capout.ai
    description: Public API
security: []
paths:
  /ws/token:
    post:
      tags:
        - WebSocket
      summary: Create Realtime Ws Token
      description: >-
        Mint a short-lived realtime token for WebSocket or SSE authentication.


        Connection flow:


        1. Call `POST /ws/token` with your `capout-api-key`.

        2. Read `token`, `ws_url`, and `sse_url` from the response.

        3. Connect to `wss://api.capout.ai/ws/status?token=<token>` for
        WebSocket updates,
           or `https://api.capout.ai/sse/status?token=<token>` for Server-Sent Events.
        4. Optionally scope the initial subscription with either:
           - `&document_id=<document_id>` repeated one or more times
           - `&recent=10` to subscribe to the most recent organization-owned documents

        WebSocket example:


        `wss://api.capout.ai/ws/status?token=<token>&document_id=doc_123`


        SSE example:


        `https://api.capout.ai/sse/status?token=<token>&recent=10`


        After a WebSocket connection is established, clients can send JSON
        commands such as:


        `{"action":"subscribe","document_ids":["doc_123"]}`
      operationId: create_realtime_ws_token_ws_token_post
      parameters:
        - name: capout-api-key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Capout-Api-Key
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RealtimeTokenResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    RealtimeTokenResponse:
      properties:
        token:
          type: string
          title: Token
          description: Short-lived realtime token for query-param auth
        organization_id:
          type: string
          title: Organization Id
          description: Organization bound to this realtime token
        expires_at:
          type: string
          format: date-time
          title: Expires At
          description: UTC expiration time for the realtime token
        ws_url:
          type: string
          title: Ws Url
          description: WebSocket path to connect to with `?token=<token>`
          default: /ws/status
        sse_url:
          type: string
          title: Sse Url
          description: SSE path to connect to with `?token=<token>`
          default: /sse/status
      type: object
      required:
        - token
        - organization_id
        - expires_at
      title: RealtimeTokenResponse
      description: Response body for POST /ws/token.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````