asyncapi: 3.0.0
info:
  title: SLNG Gateway API - ElevenLabs (WebSocket)
  version: 0.2.0
  description: SLNG Gateway API
  contact:
    name: SLNG Support
    url: https://slng.ai
    email: support@slng.ai
  license:
    name: Proprietary
  tags:
    - name: STT
      description: Speech-to-Text services
servers:
  production:
    host: api.slng.ai
    protocol: wss
    description: Production
  staging:
    host: stageapi.slng.ai
    protocol: wss
    description: Staging
channels:
  /v1/tts/elevenlabs/eleven:3:
    address: /v1/tts/elevenlabs/eleven:3
    title: eleven:3 WebSocket
    summary: eleven:3 - websocket
    description: Text-to-Speech API for generating speech from text using ElevenLabs eleven. Premium TTS with industry-leading latency and voice quality. Establishes a WebSocket connection for real-time text-to-speech using the unified SLNG TTS protocol.
    tags:
      - name: Eleven v3
    servers:
      - $ref: "#/servers/production"
    messages:
      request:
        $ref: "#/components/messages/TtsWebsocketRequest"
      response:
        $ref: "#/components/messages/TtsWebsocketResponse"
    bindings:
      ws:
        method: GET
        headers:
          $ref: "#/components/schemas/WebsocketHeaders"
  /v1/tts/elevenlabs/eleven-flash:2:
    address: /v1/tts/elevenlabs/eleven-flash:2
    title: eleven-flash:2 WebSocket
    summary: eleven-flash:2 - websocket
    description: Text-to-Speech API for generating speech from text using ElevenLabs eleven-flash. Ultra-low latency TTS with industry-leading speed. Establishes a WebSocket connection for real-time text-to-speech.
    tags:
      - name: Eleven Flash v2
    servers:
      - $ref: "#/servers/production"
    messages:
      request:
        $ref: "#/components/messages/TtsWebsocketRequest"
      response:
        $ref: "#/components/messages/TtsWebsocketResponse"
    bindings:
      ws:
        method: GET
        headers:
          $ref: "#/components/schemas/WebsocketHeaders"
  /v1/tts/elevenlabs/eleven-flash:2.5:
    address: /v1/tts/elevenlabs/eleven-flash:2.5
    title: eleven-flash:2.5 WebSocket
    summary: eleven-flash:2.5 - websocket
    description: Text-to-Speech API for generating speech from text using ElevenLabs eleven-flash. Latest ultra-low latency TTS with multilingual support. Establishes a WebSocket connection for real-time text-to-speech.
    tags:
      - name: Eleven Flash v2.5
    servers:
      - $ref: "#/servers/production"
    messages:
      request:
        $ref: "#/components/messages/TtsWebsocketRequest"
      response:
        $ref: "#/components/messages/TtsWebsocketResponse"
    bindings:
      ws:
        method: GET
        headers:
          $ref: "#/components/schemas/WebsocketHeaders"
  /v1/tts/elevenlabs/eleven-multilingual:2:
    address: /v1/tts/elevenlabs/eleven-multilingual:2
    title: eleven-multilingual:2 WebSocket
    summary: eleven-multilingual:2 - websocket
    description: Text-to-Speech API for generating speech from text using ElevenLabs eleven-multilingual. Multilingual TTS with ultra-low latency. Establishes a WebSocket connection for real-time text-to-speech.
    tags:
      - name: Multilingual v2
    servers:
      - $ref: "#/servers/production"
    messages:
      request:
        $ref: "#/components/messages/TtsWebsocketRequest"
      response:
        $ref: "#/components/messages/TtsWebsocketResponse"
    bindings:
      ws:
        method: GET
        headers:
          $ref: "#/components/schemas/WebsocketHeaders"
operations:
  ttsElevenFlash2Send:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2"
    summary: Send synthesis requests to Eleven Flash v2
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2/messages/request"
    description: Send synthesis requests to Eleven Flash v2
    tags: []
  ttsElevenFlash2Receive:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2"
    summary: Receive audio chunks from Eleven Flash v2
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2/messages/response"
    description: Receive audio chunks from Eleven Flash v2
    tags: []
  ttsElevenFlash25Send:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2.5"
    summary: Send synthesis requests to Eleven Flash v2.5
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2.5/messages/request"
    description: Send synthesis requests to Eleven Flash v2.5
    tags: []
  ttsElevenFlash25Receive:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2.5"
    summary: Receive audio chunks from Eleven Flash v2.5
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-flash:2.5/messages/response"
    description: Receive audio chunks from Eleven Flash v2.5
    tags: []
  ttsElevenMultilingual2Send:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-multilingual:2"
    summary: Send synthesis requests to Eleven Multilingual v2
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-multilingual:2/messages/request"
    description: Send synthesis requests to Eleven Multilingual v2
    tags: []
  ttsElevenMultilingual2Receive:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-multilingual:2"
    summary: Receive audio chunks from Eleven Multilingual v2
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven-multilingual:2/messages/response"
    description: Receive audio chunks from Eleven Multilingual v2
    tags: []
  ttsEleven3Send:
    action: send
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven:3"
    summary: Send synthesis requests to ElevenLabs eleven:3
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven:3/messages/request"
    description: Send synthesis requests to ElevenLabs eleven:3
    tags: []
  ttsEleven3Receive:
    action: receive
    channel:
      $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven:3"
    summary: Receive audio chunks from ElevenLabs eleven:3
    messages:
      - $ref: "#/channels/~1v1~1tts~1elevenlabs~1eleven:3/messages/response"
    description: Receive audio chunks from ElevenLabs eleven:3
    tags: []
components:
  schemas:
    WebsocketHeaders:
      type: object
      properties:
        X-Region-Override:
          type: string
          description: Optional. Specify a target region for this model. If not provided, the system will automatically select an appropriate region.
        Upgrade:
          type: string
          enum:
            - websocket
        Connection:
          type: string
          enum:
            - Upgrade
    TtsWebsocketMessage:
      oneOf:
        - title: Ready Message
          type: object
          description: Indicates the session is ready to receive messages.
          required:
            - type
            - session_id
          properties:
            type:
              const: ready
            session_id:
              type: string
              description: Unique session identifier
        - title: Audio Chunk
          type: object
          description: Chunk of base64-encoded audio data.
          required:
            - type
            - data
          properties:
            type:
              const: audio_chunk
            data:
              type: string
              format: byte
              description: Base64-encoded audio data
            sequence:
              type: integer
              description: Sequence number for ordering chunks
        - title: Segment Start
          type: object
          description: Signals the start of a synthesized segment.
          required:
            - type
            - segment_id
          properties:
            type:
              const: segment_start
            segment_id:
              type: string
              description: Unique segment identifier
        - title: Segment End
          type: object
          description: Signals the end of a synthesized segment.
          required:
            - type
            - segment_id
          properties:
            type:
              const: segment_end
            segment_id:
              type: string
              description: Unique segment identifier
        - title: Flushed
          type: object
          description: Acknowledges that buffered output was flushed.
          required:
            - type
          properties:
            type:
              const: flushed
        - title: Cleared
          type: object
          description: Acknowledges that queued output was cleared.
          required:
            - type
          properties:
            type:
              const: cleared
        - title: Audio End
          type: object
          description: Signals the end of audio generation.
          required:
            - type
          properties:
            type:
              const: audio_end
            duration:
              type: number
              description: Total audio duration
        - title: Error Message
          type: object
          description: Indicates an error occurred during synthesis.
          required:
            - type
            - code
            - message
          properties:
            type:
              const: error
            code:
              type: string
              description: Error code.
              enum:
                - auth_error
                - config_error
                - rate_limit
                - provider_error
            message:
              type: string
              description: Human-readable error description
    TtsWebsocketRequestMessage:
      oneOf:
        - title: Init Message
          type: object
          description: Initialize a session with model and voice configuration before sending text.
          required:
            - type
            - model
          properties:
            type:
              const: init
              type: string
              default: init
            model:
              $ref: "#/components/schemas/TtsModel"
            voice:
              type: string
              description: Voice identifier
            config:
              type: object
              description: Synthesis configuration options
              properties:
                sample_rate:
                  $ref: "#/components/schemas/SampleRate"
                encoding:
                  type: string
                  description: Audio encoding format
                  enum:
                    - linear16
                    - mp3
                    - opus
                language:
                  $ref: "#/components/schemas/LanguageCode"
                speed:
                  type: number
                  description: Speech speed multiplier (e.g., 1.0 for normal)
        - title: Text Message
          type: object
          description: Send text to synthesize into audio output.
          required:
            - type
            - text
          properties:
            type:
              const: text
            text:
              type: string
              description: Text to synthesize
            flush:
              type: boolean
              description: Whether to flush remaining audio immediately after this text
        - title: Flush Message
          type: object
          description: Force any buffered text/audio to be finalized and delivered.
          required:
            - type
          properties:
            type:
              const: flush
        - title: Clear Message
          type: object
          description: Clear any queued text/audio from the current session.
          required:
            - type
          properties:
            type:
              const: clear
        - title: Cancel Message
          type: object
          description: Cancel the current generation and stop any further audio.
          required:
            - type
          properties:
            type:
              const: cancel
    LanguageCode:
      type: string
      description: ISO-639-1 language code.
      enum:
        - en
        - ja
        - zh
        - de
        - hi
        - fr
        - ko
        - pt
        - it
        - es
        - id
        - nl
        - tr
        - fil
        - pl
        - sv
        - bg
        - ro
        - ar
        - cs
        - el
        - fi
        - hr
        - ms
        - sk
        - da
        - ta
        - uk
        - ru
        - hu
        - no
        - vi
    SampleRate:
      type: integer
      description: Audio sample rate in Hz.
      enum:
        - 8000
        - 16000
        - 22050
        - 24000
        - 32000
        - 44100
        - 48000
    TtsModel:
      type: string
      description: TTS model identifier.
      enum:
        - aura:2
        - eleven:3
        - eleven-flash:2
        - eleven-flash:2.5
        - eleven-multilingual:2
        - canopylabs/orpheus:en
        - deepgram/aura:2
        - deepgram/aura:2-en
        - deepgram/aura:2-es
        - geneing/kokoro:v1
        - myshell/melo:v1
        - rime/arcana:3-en
        - rime/arcana:3-fr
        - rime/arcana:3-hi
        - rime/arcana:ar
        - rime/arcana:de
        - rime/arcana:en
        - rime/arcana:es
        - rime/arcana:fr
  messages:
    TtsWebsocketResponse:
      name: TtsWebsocketResponse
      title: TTS WebSocket Response
      payload:
        $ref: "#/components/schemas/TtsWebsocketMessage"
    TtsWebsocketRequest:
      name: TtsWebsocketRequest
      title: TTS WebSocket Request
      payload:
        $ref: "#/components/schemas/TtsWebsocketRequestMessage"
