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

# Get WebSocket Token

> Mints a short-lived token scoped to this session, and the `wss://` URL to connect with it. Use this to open a live, bidirectional connection for a session instead of polling `POST /v1/chat/inbound` — see the [WebSocket integration guide](/api-reference/chat-websocket).

Only the `user` stream can be minted with an API token; it carries the same customer conversation as the REST endpoints. The token expires 5 minutes after it's issued — mint a fresh one to reconnect after that, or ahead of expiry to avoid a drop.

See the [WebSocket integration guide](/api-reference/chat-websocket) for how to use the token and URL this returns.


## OpenAPI

````yaml POST /v1/chat/session/{id}/ws_token
openapi: 3.1.0
info:
  title: OSVI AI API
  description: REST API for the OSVI AI voice and chat platform
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.osvi.ai
security:
  - ApiToken: []
paths:
  /v1/chat/session/{id}/ws_token:
    post:
      summary: Mint a WebSocket token
      description: >-
        Mints a short-lived token scoped to this session, and the `wss://` URL
        to connect with it. Use this to open a live, bidirectional connection
        for a session instead of polling `POST /v1/chat/inbound` — see the
        [WebSocket integration guide](/api-reference/chat-websocket).


        Only the `user` stream can be minted with an API token; it carries the
        same customer conversation as the REST endpoints. The token expires 5
        minutes after it's issued — mint a fresh one to reconnect after that, or
        ahead of expiry to avoid a drop.
      parameters:
        - name: id
          in: path
          required: true
          description: The session UUID (from Create Session or Get Active Session).
          schema:
            type: string
            example: 4718a326-417b-4dda-90d0-21fd65a11cb8
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - stream
              properties:
                stream:
                  type: string
                  enum:
                    - user
                  description: >-
                    Which stream to mint a token for. Only `user` is available
                    with an API token.
                  example: user
      responses:
        '200':
          description: Token minted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      token:
                        type: string
                        description: >-
                          Opaque token — pass it as the `token` query parameter
                          when opening the WebSocket connection.
                        example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
                      ws_url:
                        type: string
                        format: uri
                        description: >-
                          The `wss://` URL to connect to; use it as returned.
                          `token` is not included — append it (and your own
                          `client_id`) as query parameters.
                        example: >-
                          wss://<host>/v1/chat/session/4718a326-417b-4dda-90d0-21fd65a11cb8/user-stream
                      expires_at:
                        type: integer
                        description: Unix timestamp (seconds) when `token` expires.
                        example: 1789191300
                      stream:
                        type: string
                        enum:
                          - user
                        example: user
        '400':
          description: '`stream` is missing or not a recognized value.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatV1Error'
        '401':
          description: Invalid or missing API token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatV1Error'
        '403':
          description: >-
            An API token requested a stream other than `user`
            (`stream_not_allowed`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatV1Error'
        '404':
          description: No session with that id exists on your account.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatV1Error'
        '409':
          description: >-
            The session is closed (`session_closed`) — an API token cannot mint
            a token for a closed session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatV1Error'
components:
  schemas:
    ChatV1Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
          description: Machine-readable error code or message.
          example: agent_not_found
  securitySchemes:
    ApiToken:
      type: apiKey
      in: header
      name: API-Token
      description: >-
        16-character API token associated with your OSVI account. Find it in
        your dashboard under Settings → API.

````