|
| 1 | +--- |
| 2 | +sidebar_position: 2 |
| 3 | +title: VAPI Integration |
| 4 | +description: Add a VAPI voice AI agent to a Fishjam room with a single API call. |
| 5 | +--- |
| 6 | + |
| 7 | +import Tabs from "@theme/Tabs"; |
| 8 | +import TabItem from "@theme/TabItem"; |
| 9 | + |
| 10 | +# VAPI Integration |
| 11 | + |
| 12 | +:::info |
| 13 | +This tutorial requires a working Fishjam backend. If you haven't set one up yet, please check the [Backend Quick Start](../tutorials/backend-quick-start). |
| 14 | +::: |
| 15 | + |
| 16 | +This guide shows how to add a [VAPI](https://vapi.ai/) voice AI agent to a Fishjam room. |
| 17 | +Unlike custom agent integrations (such as [Gemini](./gemini-live-integration)), there is no need to build a WebSocket bridge yourself — |
| 18 | +Fishjam connects to VAPI internally. You only need to create a VAPI call and pass its ID to Fishjam. |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +The workflow has two steps: |
| 23 | + |
| 24 | +1. **Create a VAPI call** using the VAPI SDK. This gives you a `callId`. |
| 25 | +2. **Pass the call ID to Fishjam** via `createVapiAgent()` / `create_vapi_agent()`. Fishjam joins the call and streams audio to and from the room. |
| 26 | + |
| 27 | +:::note |
| 28 | +The VAPI peer receives audio from only one peer at a time, so this integration works best in 1-on-1 calls. All peers in the room hear VAPI's responses. |
| 29 | +::: |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +You will need: |
| 34 | + |
| 35 | +- **Fishjam Server Credentials:** `fishjamId` and `managementToken`. You can get them at [fishjam.io/app](https://fishjam.io/app). |
| 36 | +- **VAPI Private API Key:** Obtainable from the [VAPI Dashboard](https://dashboard.vapi.ai/). |
| 37 | +- **VAPI Assistant ID** _(optional)_**:** Create an assistant in the [VAPI Dashboard](https://dashboard.vapi.ai/), or provide a transient assistant configuration inline. |
| 38 | + |
| 39 | +### Installation |
| 40 | + |
| 41 | +<Tabs groupId="language"> |
| 42 | + <TabItem value="ts" label="TypeScript"> |
| 43 | + |
| 44 | + ```bash |
| 45 | + npm install @fishjam-cloud/js-server-sdk @vapi-ai/server-sdk |
| 46 | + ``` |
| 47 | + |
| 48 | + </TabItem> |
| 49 | + |
| 50 | + <TabItem value="python" label="Python"> |
| 51 | + |
| 52 | + ```bash |
| 53 | + pip install fishjam-server-sdk vapi |
| 54 | + ``` |
| 55 | + |
| 56 | + </TabItem> |
| 57 | +</Tabs> |
| 58 | + |
| 59 | +## Implementation |
| 60 | + |
| 61 | +### Step 1: Create a VAPI Call |
| 62 | + |
| 63 | +Use the VAPI SDK to create a call with `vapi.websocket` transport and `pcm_s16le` audio at `16000` Hz. |
| 64 | +You can reference an existing assistant by its ID, or create a transient assistant inline by providing the full configuration via the `assistant` field instead of `assistantId`. |
| 65 | + |
| 66 | +<Tabs groupId="language"> |
| 67 | + <TabItem value="ts" label="TypeScript"> |
| 68 | + |
| 69 | + ```ts |
| 70 | + import { VapiClient, Vapi } from '@vapi-ai/server-sdk'; |
| 71 | + |
| 72 | + const vapiClient = new VapiClient({ |
| 73 | + token: process.env.VAPI_API_KEY!, |
| 74 | + }); |
| 75 | + |
| 76 | + // [!code highlight:11] |
| 77 | + const call = await vapiClient.calls.create({ |
| 78 | + assistantId: process.env.VAPI_ASSISTANT_ID!, |
| 79 | + transport: { |
| 80 | + provider: 'vapi.websocket', |
| 81 | + audioFormat: { |
| 82 | + format: 'pcm_s16le', |
| 83 | + container: 'raw', |
| 84 | + sampleRate: 16000, |
| 85 | + }, |
| 86 | + }, |
| 87 | + }) as Vapi.Call; |
| 88 | + ``` |
| 89 | + |
| 90 | + </TabItem> |
| 91 | + |
| 92 | + <TabItem value="python" label="Python"> |
| 93 | + |
| 94 | + ```python |
| 95 | + import os |
| 96 | + from vapi import Vapi |
| 97 | + |
| 98 | + vapi_client = Vapi(token=os.environ["VAPI_API_KEY"]) |
| 99 | + |
| 100 | + # [!code highlight:11] |
| 101 | + call = vapi_client.calls.create( |
| 102 | + assistant_id=os.environ["VAPI_ASSISTANT_ID"], |
| 103 | + transport={ |
| 104 | + "provider": "vapi.websocket", |
| 105 | + "audioFormat": { |
| 106 | + "format": "pcm_s16le", |
| 107 | + "container": "raw", |
| 108 | + "sampleRate": 16000, |
| 109 | + }, |
| 110 | + }, |
| 111 | + ) |
| 112 | + ``` |
| 113 | + |
| 114 | + </TabItem> |
| 115 | +</Tabs> |
| 116 | + |
| 117 | +### Step 2: Add the VAPI Peer to Fishjam |
| 118 | + |
| 119 | +Pass the call ID and your VAPI API key to Fishjam. Fishjam handles the rest. |
| 120 | + |
| 121 | +<Tabs groupId="language"> |
| 122 | + <TabItem value="ts" label="TypeScript"> |
| 123 | + |
| 124 | + ```ts |
| 125 | + import { VapiClient, Vapi } from '@vapi-ai/server-sdk'; |
| 126 | + |
| 127 | + const vapiClient = new VapiClient({ |
| 128 | + token: process.env.VAPI_API_KEY!, |
| 129 | + }); |
| 130 | + |
| 131 | + const call = await vapiClient.calls.create({ |
| 132 | + assistantId: process.env.VAPI_ASSISTANT_ID!, |
| 133 | + transport: { |
| 134 | + provider: 'vapi.websocket', |
| 135 | + audioFormat: { |
| 136 | + format: 'pcm_s16le', |
| 137 | + container: 'raw', |
| 138 | + sampleRate: 16000, |
| 139 | + }, |
| 140 | + }, |
| 141 | + }) as Vapi.Call; |
| 142 | + |
| 143 | + // ---cut--- |
| 144 | + import { FishjamClient } from '@fishjam-cloud/js-server-sdk'; |
| 145 | + |
| 146 | + const fishjamClient = new FishjamClient({ |
| 147 | + fishjamId: process.env.FISHJAM_ID!, |
| 148 | + managementToken: process.env.FISHJAM_TOKEN!, |
| 149 | + }); |
| 150 | + |
| 151 | + const room = await fishjamClient.createRoom(); |
| 152 | + |
| 153 | + // [!code highlight:4] |
| 154 | + await fishjamClient.createVapiAgent(room.id, { |
| 155 | + callId: call.id, |
| 156 | + apiKey: process.env.VAPI_API_KEY!, |
| 157 | + }); |
| 158 | + ``` |
| 159 | + |
| 160 | + </TabItem> |
| 161 | + |
| 162 | + <TabItem value="python" label="Python"> |
| 163 | + |
| 164 | + ```python |
| 165 | + import os |
| 166 | + from fishjam import FishjamClient, PeerOptionsVapi |
| 167 | + |
| 168 | + fishjam_client = FishjamClient( |
| 169 | + fishjam_id=os.environ["FISHJAM_ID"], |
| 170 | + management_token=os.environ["FISHJAM_TOKEN"], |
| 171 | + ) |
| 172 | + |
| 173 | + room = fishjam_client.create_room() |
| 174 | + |
| 175 | + # [!code highlight:2] |
| 176 | + options = PeerOptionsVapi(api_key=os.environ["VAPI_API_KEY"], call_id=call.id) |
| 177 | + peer = fishjam_client.create_vapi_agent(room.id, options) |
| 178 | + ``` |
| 179 | + |
| 180 | + </TabItem> |
| 181 | +</Tabs> |
| 182 | + |
| 183 | +## That's it |
| 184 | + |
| 185 | +Once both steps are complete, the VAPI assistant is live in the room — peers can speak to it and hear its responses. |
| 186 | + |
| 187 | +The VAPI peer's lifetime is tied to the underlying WebSocket connection. If there is a prolonged period of silence or the call ends for any other reason, the peer will disconnect and be removed from the room. You can detect this by listening for `PeerDisconnected` and `PeerDeleted` server notifications. If the peer crashes (e.g. due to an invalid transport configuration or call ID), a `PeerCrashed` notification is sent instead. See [Listening to events](../how-to/backend/server-setup#listening-to-events) for how to subscribe to these notifications. |
| 188 | + |
| 189 | +## Billing |
| 190 | + |
| 191 | +The VAPI peer is billed as a single Fishjam peer. VAPI's own usage pricing applies separately — see [VAPI pricing](https://vapi.ai/pricing) for details. |
0 commit comments