> ## Documentation Index
> Fetch the complete documentation index at: https://daily-hush-pcc-session-recordings-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Realtime WebRTC Transport

> WebRTC implementation for Android using OpenAI

The OpenAI Realtime WebRTC transport implementation enables real-time audio communication with the OpenAI Realtime service, using a direct WebRTC connection.

<Note>
  Transports of this type connect directly to OpenAI's API from the client,
  which exposes your API key. This is designed primarily for development and
  testing. For production applications, proxy through a server component to
  keep credentials secure.
</Note>

## Installation

Add the transport dependency to your `app/build.gradle.kts`:

```kotlin theme={null}
dependencies {
    implementation("ai.pipecat:openai-realtime-webrtc-transport:1.2.0")
}
```

Add the microphone permission to `AndroidManifest.xml`:

```xml theme={null}
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```

## Usage

```kotlin theme={null}
import ai.pipecat.client.PipecatClientOptions
import ai.pipecat.client.PipecatEventCallbacks
import ai.pipecat.client.openai_realtime_webrtc.OpenAIRealtimeSessionConfig
import ai.pipecat.client.openai_realtime_webrtc.OpenAIServiceOptions
import ai.pipecat.client.openai_realtime_webrtc.PipecatClientOpenAIRealtimeWebRTC
import ai.pipecat.client.openai_realtime_webrtc.OpenAIRealtimeWebRTCTransport
import ai.pipecat.client.types.BotReadyData
import ai.pipecat.client.types.Value

val callbacks = object : PipecatEventCallbacks() {
    override fun onBackendError(message: String) {
        Log.e(TAG, "Backend error: $message")
    }

    override fun onBotReady(data: BotReadyData) {
        Log.d(TAG, "Bot is ready")
    }
}

val options = PipecatClientOptions(callbacks = callbacks, enableMic = true)
val client = PipecatClientOpenAIRealtimeWebRTC(OpenAIRealtimeWebRTCTransport(context), options)

client.connect(
    OpenAIServiceOptions(
        apiKey = "your-openai-api-key",
        model = "gpt-realtime",
        sessionConfig = OpenAIRealtimeSessionConfig(
            voice = "alloy",
            instructions = "You are a helpful assistant.",
            turnDetection = Value.Object("type" to Value.Str("semantic_vad")),
            inputAudioTranscription = Value.Object("model" to Value.Str("gpt-4o-transcribe"))
        )
    )
).withCallback { result ->
    result.errorOrNull?.let { Log.e(TAG, "Connection failed: $it") }
}
```

## Configuration

### OpenAIServiceOptions

| Parameter         | Type                          | Description                            |
| ----------------- | ----------------------------- | -------------------------------------- |
| `apiKey`          | `String`                      | Your OpenAI API key                    |
| `sessionConfig`   | `OpenAIRealtimeSessionConfig` | Session configuration                  |
| `model`           | `String?`                     | Model name (default: `"gpt-realtime"`) |
| `initialMessages` | `List<LLMContextMessage>`     | Messages to inject at session start    |

### OpenAIRealtimeSessionConfig

| Parameter                  | Type            | Description                                                                          |
| -------------------------- | --------------- | ------------------------------------------------------------------------------------ |
| `modalities`               | `List<String>?` | Output modalities (e.g. `["audio", "text"]`), sent to the API as `output_modalities` |
| `instructions`             | `String?`       | System instructions for the model                                                    |
| `voice`                    | `String?`       | Voice name (e.g. `"alloy"`, `"ballad"`)                                              |
| `turnDetection`            | `Value?`        | Turn detection config                                                                |
| `inputAudioNoiseReduction` | `Value?`        | Noise reduction config                                                               |
| `inputAudioTranscription`  | `Value?`        | Transcription model config                                                           |
| `tools`                    | `Value?`        | Tool/function definitions                                                            |
| `toolChoice`               | `String?`       | Tool choice strategy                                                                 |
| `temperature`              | `Float?`        | Deprecated — not supported by the GA Realtime API, this value is ignored             |

### Audio devices

The transport exposes static constants for audio routing:

```kotlin theme={null}
// Route audio to speakerphone (default) or earpiece
client.updateMic(OpenAIRealtimeWebRTCTransport.AudioDevices.Speakerphone.id)
client.updateMic(OpenAIRealtimeWebRTCTransport.AudioDevices.Earpiece.id)
```

## Resources

<CardGroup cols={2}>
  <Card horizontal title="Demo" icon="play" href="https://github.com/pipecat-ai/pipecat-client-android-openai-realtime-webrtc-demo">
    Simple Chatbot Demo
  </Card>

  <Card horizontal title="Source" icon="github" href="https://github.com/pipecat-ai/pipecat-client-android-transports/">
    Client Transports
  </Card>
</CardGroup>

<Card title="Pipecat Android Client Reference" icon="book-open" href="https://docs-android.rtvi.ai/">
  Complete API documentation for the Pipecat Android client.
</Card>
