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

# Open a session

> Creates a new conversation session for the authenticated kiosk. Returns a
`session_id` and an `agent_url` — every subsequent real-time call for this session
(WebSocket text, WebRTC voice, session end) goes to `agent_url`, not necessarily the
host that served this request.

The `mode` field determines which interaction pattern is available:
- `text` — WebSocket messaging (see [WebSocket streaming](/connections/websocket-streaming))
- `voice` — WebRTC real-time audio
- `voip` — SIP / VoIP telephony bridge




## OpenAPI

````yaml /openapi.yaml post /v1/sessions
openapi: 3.1.0
info:
  title: Humain Kiosk — Device API
  version: '1.0'
  description: >
    The Device API is consumed by physical kiosk terminals, VoIP adapters, and
    website

    widgets. All requests require a device credential issued from the Humain
    admin panel.


    **Base URL:** `https://api.humain.ai` — there is no separate sandbox host.
    Sandbox is a

    property of the credential, not the URL: issue an `hk_test_…` credential
    from the admin

    panel and call the exact same endpoints. In sandbox mode, text sessions echo
    the input back

    verbatim and voice sessions run a record → beep → echo loop — no LLM call is
    made, per-turn

    guardrail/FraudGuard checks do not run, and no usage is billed. See

    [Sandbox mode](/concepts/sandbox-mode).


    Opening a session returns an `agent_url` — use it as the base URL for every
    subsequent

    real-time call (WebSocket, WebRTC, session end) instead of assuming the same
    host that

    served `POST /v1/sessions`. In most deployments `agent_url` is the same
    public API host

    behind a reverse proxy; treat it as opaque and always use the value
    returned.


    Browser-side integrations that cannot hold a device credential — a website
    widget, a

    single-page app — should use the [Public Gateway](/concepts/public-gateway)
    instead of

    calling these endpoints directly. It runs on a separate host and isn't
    documented in this

    reference; see the linked page for its own request/response shapes.
servers:
  - url: https://api.humain.ai
    description: >-
      Production and sandbox — sandbox behavior is selected by using an hk_test_
      credential, not a different URL
security:
  - DeviceToken: []
tags:
  - name: Sessions
    description: Open, interact with, and close conversation sessions.
  - name: Voice (WebRTC)
    description: Establish real-time voice sessions over WebRTC.
  - name: Webhooks
    description: >
      Manage webhook endpoints and inspect delivery history. Part of the Admin
      API —

      authenticated with the admin session cookie, not a device credential.
  - name: Analytics
    description: |
      Query session and usage analytics for a workspace. Part of the Admin API —
      authenticated with the admin session cookie, not a device credential.
paths:
  /v1/sessions:
    post:
      tags:
        - Sessions
      summary: Open a session
      description: >
        Creates a new conversation session for the authenticated kiosk. Returns
        a

        `session_id` and an `agent_url` — every subsequent real-time call for
        this session

        (WebSocket text, WebRTC voice, session end) goes to `agent_url`, not
        necessarily the

        host that served this request.


        The `mode` field determines which interaction pattern is available:

        - `text` — WebSocket messaging (see [WebSocket
        streaming](/connections/websocket-streaming))

        - `voice` — WebRTC real-time audio

        - `voip` — SIP / VoIP telephony bridge
      operationId: openSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenSessionRequest'
            examples:
              text:
                summary: Open a text session
                value:
                  mode: text
              voice:
                summary: Open a voice session
                value:
                  mode: voice
              textWithLanguage:
                summary: Open a text session with language preference
                value:
                  mode: text
                  preferred_language: tr
              textWithVariables:
                summary: Open a text session with dynamic variables
                value:
                  mode: text
                  conversation_initiation_data:
                    variables:
                      customer_name: Alice
                      booking_ref: TK-9021
      responses:
        '201':
          description: Session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenSessionResponse'
              example:
                session_id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
                agent_url: https://api.humain.ai
                detected_language: tr
        '400':
          description: A variable referenced by the persona was not provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: MISSING_REQUIRED_VARIABLE
                message: 'Required variable not provided: booking_ref'
                details:
                  variable: booking_ref
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '402':
          $ref: '#/components/responses/PlanLimitReached'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          $ref: '#/components/responses/ProviderError'
components:
  schemas:
    OpenSessionRequest:
      type: object
      required:
        - mode
      properties:
        mode:
          type: string
          enum:
            - text
            - voice
            - voip
          description: |
            The session interaction mode.
            - `text` — REST + WebSocket messaging
            - `voice` — WebRTC real-time audio
            - `voip` — SIP telephony bridge
        preferred_language:
          type: string
          description: >
            BCP-47 language code for this session (e.g. `"tr"`, `"ar"`, `"de"`).

            The server uses the matching language persona if one is configured
            on the kiosk.

            Falls back to the kiosk's default language if no match is found.

            Omit to use the kiosk's default.
          example: tr
        conversation_initiation_data:
          type: object
          description: Optional structured data attached to the session at open time.
          properties:
            variables:
              type: object
              additionalProperties:
                type: string
              description: >
                Key-value pairs injected into the persona prompt as template
                variables.

                Keys must match a variable declared on the kiosk (**Kiosk →
                Persona → Variables**)

                or they are silently ignored. See [Dynamic
                variables](/guides/dynamic-variables).
              example:
                customer_name: Alice
                booking_ref: TK-9021
    OpenSessionResponse:
      type: object
      properties:
        session_id:
          type: string
          format: uuid
          description: Unique session identifier — pass this to all subsequent calls.
        agent_url:
          type: string
          format: uri
          description: >
            Base URL for every real-time call on this session — the WebSocket

            (`GET {agent_url}/v1/sessions/{sid}/ws`), WebRTC signalling

            (`POST {agent_url}/v1/sessions/{sid}/webrtc/offer` and `.../ice`),
            and

            `POST {agent_url}/v1/sessions/{sid}/end`. Do not assume it equals
            the host that

            served this request. Treat it as opaque — in most deployments it is
            the same

            public API host behind a reverse proxy.
          example: https://api.humain.ai
        detected_language:
          type: string
          description: >
            Currently just echoes the `preferred_language` you sent — the server
            does not yet

            perform real language detection. Omitted if `preferred_language` was
            not sent.
          example: tr
        disclosure_text:
          type: string
          description: >
            Reserved for a forthcoming EU AI Act disclosure feature. **Not yet
            populated by

            the server** — always omitted from the response today. Do not build
            a UI that

            depends on this field appearing.
        ice_servers:
          type: array
          description: >
            TURN/STUN server credentials, present only when TURN relay is
            configured for

            this workspace. Pass directly to `RTCPeerConnection`'s `iceServers`
            config.
          items:
            $ref: '#/components/schemas/ICEServerConfig'
    Error:
      type: object
      properties:
        error:
          type: string
          description: Machine-readable error code in SCREAMING_SNAKE_CASE.
          example: UNAUTHENTICATED
        message:
          type: string
          description: Human-readable description of the error.
          example: Missing or invalid device token.
        details:
          type: object
          description: >-
            Additional error-specific fields (see individual error
            descriptions).
    ICEServerConfig:
      type: object
      properties:
        urls:
          type: array
          items:
            type: string
          example:
            - turn:turn.humain.ai:3478
            - stun:turn.humain.ai
        username:
          type: string
        credential:
          type: string
  responses:
    Unauthenticated:
      description: Missing or invalid device token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: UNAUTHENTICATED
            message: Missing or invalid device token.
            details: {}
    PlanLimitReached:
      description: The workspace has reached its plan's session limit.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: PLAN_LIMIT_REACHED
            message: Monthly session limit reached. Upgrade your plan to continue.
            details: {}
    Forbidden:
      description: >
        Valid token but the request is not permitted. One of:

        - `KIOSK_INACTIVE` — the kiosk's status is not *active*

        - `CREDENTIAL_BLOCKED` — FraudGuard blocked this credential. When
        returned, the response
          includes a `Retry-After` header with the number of seconds until the block expires.
      headers:
        Retry-After:
          description: >
            Seconds until the credential block expires. Only present when
            `error` is

            `CREDENTIAL_BLOCKED`. Do not retry before this time has elapsed.
          schema:
            type: integer
            example: 3600
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            kioskInactive:
              summary: Kiosk not active
              value:
                error: KIOSK_INACTIVE
                message: This kiosk is not currently active.
                details: {}
            credentialBlocked:
              summary: Credential blocked by FraudGuard
              value:
                error: CREDENTIAL_BLOCKED
                message: This credential has been blocked due to suspicious activity.
                details:
                  blocked_until: '2026-05-24T15:30:00Z'
                  reason: Excessive rate-limit violations
    RateLimited:
      description: >
        Too many requests. Slow down and retry after
        `details.retry_after_seconds`.

        A `Retry-After` header is also included with the same value for
        HTTP-standard clients.
      headers:
        Retry-After:
          description: >-
            Seconds to wait before retrying. Mirrors
            `details.retry_after_seconds`.
          schema:
            type: integer
            example: 60
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: RATE_LIMITED
            message: Rate limit exceeded.
            details:
              retry_after_seconds: 30
    InternalError:
      description: Unexpected server-side error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: INTERNAL_ERROR
            message: An unexpected error occurred.
            details: {}
    ProviderError:
      description: >
        The LLM, STT, or TTS provider returned an error or is temporarily
        unavailable.

        Retry with exponential back-off.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: PROVIDER_ERROR
            message: AI provider is temporarily unavailable. Please retry.
            details: {}
  securitySchemes:
    DeviceToken:
      type: http
      scheme: bearer
      bearerFormat: hk_live_{43-char-base64url} | hk_test_{43-char-base64url}
      description: >
        Device credential issued from the Humain admin panel under

        **Kiosk → Credentials → Issue new credential**.


        Format: `hk_live_` (production) or `hk_test_` (sandbox) followed by 43
        base64url

        characters (32 random bytes). The raw token is shown only once at
        creation time and

        is never stored in plain text.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.