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

# Peer_to_peer

> Peer to Peer WebRTC 

[Compose Session Token](/api-reference/compose-session-token) is sent as query parameter string

enableSFU is a query parameter boolean to opt into sending the traffic through cloudflare network for improved reliability

First message must be offer. Offer must be provided within 30 seconds of opening the websocket. Once offer is sent, a corresponding answer will be sent from the server which can be used as described [here](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription)




## AsyncAPI

````yaml api-reference/asyncapi.yaml peer_to_peer
id: peer_to_peer
title: Peer_to_peer
description: >
  Peer to Peer WebRTC 


  [Compose Session Token](/api-reference/compose-session-token) is sent as query
  parameter string


  enableSFU is a query parameter boolean to opt into sending the traffic through
  cloudflare network for improved reliability


  First message must be offer. Offer must be provided within 30 seconds of
  opening the websocket. Once offer is sent, a corresponding answer will be sent
  from the server which can be used as described
  [here](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription)
servers:
  - id: Simli WSS
    protocol: wss
    host: api.simli.ai
    bindings: []
    variables:
      - id: session_token
        description: Session token generated by https://api.simli.ai/compose/token
        allowedValues: []
        examples: []
address: /compose/webrtc/p2p
parameters: []
bindings: []
operations:
  - &ref_3
    id: sendOffer
    title: Send offer
    type: receive
    messages:
      - &ref_10
        id: offer
        contentType: text/plain
        payload:
          - name: offer
            description: >-
              RTC Offer as generated by
              https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer
              or compatible
            type: object
            properties:
              - name: type
                type: string
                description: offer
                required: false
              - name: sdp
                type: string
                required: false
        headers: []
        jsonPayloadSchema:
          schema:
            type: object
            properties:
              type:
                type: string
                const: offer
                x-parser-schema-id: <anonymous-schema-2>
              sdp:
                type: string
                x-parser-schema-id: <anonymous-schema-3>
            x-parser-schema-id: <anonymous-schema-1>
        title: Offer
        description: >-
          RTC Offer as generated by
          https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createOffer
          or compatible
        example: |-
          {
            "type": "<string>",
            "sdp": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: offer
          - id: x-parser-message-name
            value: rtc_offer
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: peer_to_peer
  - &ref_7
    id: recvAnswer
    title: Recv answer
    type: send
    messages:
      - &ref_14
        id: answer
        contentType: text/plain
        payload:
          - name: answer
            description: >-
              RTC Answer as generated by
              https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createAnswer
              or compatible. Will be received AFTER an offer has been sent
            type: object
            properties:
              - name: type
                type: string
                description: answer
                required: false
              - name: sdp
                type: string
                required: false
        headers: []
        jsonPayloadSchema:
          schema:
            type: object
            properties:
              type:
                type: string
                const: answer
                x-parser-schema-id: <anonymous-schema-5>
              sdp:
                type: string
                x-parser-schema-id: <anonymous-schema-6>
            x-parser-schema-id: <anonymous-schema-4>
        title: Answer
        description: >-
          RTC Answer as generated by
          https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createAnswer
          or compatible. Will be received AFTER an offer has been sent
        example: |-
          {
            "type": "<string>",
            "sdp": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: answer
          - id: x-parser-message-name
            value: rtc_answer
    bindings: []
    extensions: *ref_0
  - &ref_4
    id: sendAudioChunk_peer_to_peer
    title: Send audio chunk_peer_to_peer
    type: receive
    messages:
      - &ref_11
        id: audio_chunk
        contentType: application/octet-stream
        payload:
          - type: string
            format: bytestring
            x-parser-schema-id: <anonymous-schema-7>
            name: audio_chunk
            description: >-
              Binary stream of the audio that the Avatar will lipsync to. Sent
              as a binary stream (in JS/TS UInt8Arr)
        headers: []
        jsonPayloadSchema:
          schema:
            type: string
            format: bytestring
            x-parser-schema-id: <anonymous-schema-7>
        title: Audio_chunk
        description: >-
          Binary stream of the audio that the Avatar will lipsync to. Sent as a
          binary stream (in JS/TS UInt8Arr)
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: audio_chunk
          - id: x-parser-message-name
            value: audio_chunk
    bindings: []
    extensions: *ref_0
  - &ref_5
    id: clearBuffer_peer_to_peer
    title: Clear buffer_peer_to_peer
    type: receive
    messages:
      - &ref_12
        id: clear_buffer
        contentType: text/plain
        payload:
          - type: string
            const: SKIP
            x-parser-schema-id: <anonymous-schema-8>
            name: clear_buffer
            description: >-
              Client Signal to make the avatar stop speaking immediately and
              ignore all previously sent audio
        headers: []
        jsonPayloadSchema:
          schema:
            type: string
            const: SKIP
            x-parser-schema-id: <anonymous-schema-8>
        title: Clear_buffer
        description: >-
          Client Signal to make the avatar stop speaking immediately and ignore
          all previously sent audio
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: clear_buffer
          - id: x-parser-message-name
            value: clear_buffer
    bindings: []
    extensions: *ref_0
  - &ref_6
    id: finalMessage_peer_to_peer
    title: Final message_peer_to_peer
    type: receive
    messages:
      - &ref_13
        id: final_message
        contentType: text/plain
        payload:
          - type: string
            const: DONE
            x-parser-schema-id: <anonymous-schema-9>
            name: final_message
            description: >-
              Client Signal to tell the server that the final segment of audio
              has been already sent and that it should close after playing it
              back
        headers: []
        jsonPayloadSchema:
          schema:
            type: string
            const: DONE
            x-parser-schema-id: <anonymous-schema-9>
        title: Final_message
        description: >-
          Client Signal to tell the server that the final segment of audio has
          been already sent and that it should close after playing it back
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: final_message
          - id: x-parser-message-name
            value: final_message
    bindings: []
    extensions: *ref_0
  - &ref_8
    id: event_peer_to_peer
    title: Event_peer_to_peer
    type: send
    messages:
      - &ref_15
        id: event
        contentType: text/plain
        payload:
          - type: string
            enum: &ref_1
              - START
              - ACK
              - STOP
              - SPEAK
              - SILENT
            x-parser-schema-id: <anonymous-schema-10>
            name: event
            description: Server sent signals
        headers: []
        jsonPayloadSchema:
          schema:
            type: string
            enum: *ref_1
            x-parser-schema-id: <anonymous-schema-10>
        title: Event
        description: Server sent signals
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
          - id: x-parser-message-name
            value: event
    bindings: []
    extensions: *ref_0
  - &ref_9
    id: error_peer_to_peer
    title: Error_peer_to_peer
    type: send
    messages:
      - &ref_16
        id: error
        contentType: text/plain
        payload:
          - type: string
            oneOf: &ref_2
              - pattern: ^(?i)ERROR\s+.+$
                description: Matches 'ERROR' regardless of casing.
                x-parser-schema-id: <anonymous-schema-12>
              - pattern: ^(?i)RATE\s+.+$
                description: Matches 'RATE' followed by a space.
                x-parser-schema-id: <anonymous-schema-13>
              - pattern: ^(?i)CLOSING\s+.+$
                description: Matches 'CLOSING' followed by a space.
                x-parser-schema-id: <anonymous-schema-14>
            x-parser-schema-id: <anonymous-schema-11>
            name: error
            description: >-
              Termination messages that specify the reason for immediate
              termination
        headers: []
        jsonPayloadSchema:
          schema:
            type: string
            oneOf: *ref_2
            x-parser-schema-id: <anonymous-schema-11>
          example: 'ERROR: INVALID_API_KEY'
        title: Error
        description: Termination messages that specify the reason for immediate termination
        example: '{}'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: error
          - id: x-parser-message-name
            value: error
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_3
  - *ref_4
  - *ref_5
  - *ref_6
receiveOperations:
  - *ref_7
  - *ref_8
  - *ref_9
sendMessages:
  - *ref_10
  - *ref_11
  - *ref_12
  - *ref_13
receiveMessages:
  - *ref_14
  - *ref_15
  - *ref_16
extensions:
  - id: x-parser-unique-object-id
    value: peer_to_peer
securitySchemes: []

````