Let us place the call instead
If you have no LiveKit at all, POST /v1/calls with a target and an agent id: a phone number in E.164, a Telegram or WhatsApp target, a Google Meet link. Same transcripts, same webhooks, same per-customer workspaces.
One POST puts an AI agent into a LiveKit room you already run: it greets the caller, holds the conversation, and leaves a transcript. No SDK, no media re-routing.
Everything below is a real request against api.dialogbrain.com. One API key authenticates you; the X-Workspace-Id header says which of your customers a call belongs to.
Done once per end customer. Their agents, conversations and balance stay theirs — a request carrying somebody else’s workspace id gets a 404, not a peek at their data.
# 1. a workspace for your end customer
curl -X POST https://api.dialogbrain.com/v1/workspaces \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "Idempotency-Key: ws-5512" \
-d '{"name": "Acme Coffee", "external_id": "acme-5512"}'
# -> {"id": 4821, ...}
# 2. move credits from your balance into theirs
curl -X POST https://api.dialogbrain.com/v1/workspaces/4821/credits \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "Idempotency-Key: top-5512" \
-d '{"amount_usd": "25.00"}'
# 3. their agent, created inside their workspace
curl -X POST https://api.dialogbrain.com/v1/agents \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "X-Workspace-Id: 4821" \
-H "Idempotency-Key: ag-5512" \
-d '{"name": "Front desk", "prompt_text": "You answer calls for Acme Coffee."}'
# -> {"id": 118, ...}Your LiveKit keys never leave your side. The token is scoped to the one room and is the only access we get.
from livekit import api # pip install livekit-api
# A guest token for OUR participant, scoped to the one room.
token = (
api.AccessToken(LIVEKIT_KEY, LIVEKIT_SECRET)
.with_identity("dialogbrain-agent")
.with_grants(api.VideoGrants(
room_join=True,
room="call-9f21c7",
can_publish=True,
can_subscribe=True,
))
.to_jwt()
)Send the room, the token, and which agent should take it. You get a call_id back immediately and the agent is in the room within a second or two.
curl -X POST https://api.dialogbrain.com/v1/voice/bridge \
-H "X-API-Key: $DIALOGBRAIN_KEY" \
-H "X-Workspace-Id: 4821" \
-H "Idempotency-Key: call-9f21c7" \
-H "Content-Type: application/json" \
-d '{
"livekit_url": "wss://livekit.your-app.com",
"room": "call-9f21c7",
"token": "<guest token you minted for our participant>",
"agent_id": 118,
"caller_external_identity": "user-5512",
"answer_delay_s": 0
}'{
"call_id": "7a6daec1b3cc4585ba0280cc50de5e23",
"room": "voice-7a6daec1b3cc4585ba0280cc50de5e23",
"status": "active"
}# Ring for 20 seconds. The agent picks up only if the owner did not,
# and stands down silently the moment they join themselves.
-d '{
"livekit_url": "wss://livekit.your-app.com",
"room": "call-9f21c7",
"token": "<guest token>",
"agent_id": 118,
"caller_external_identity": "user-5512",
"owner_identity": "user-118",
"answer_delay_s": 20
}'The whole integration in one file: mint the token, bridge the call, handle the events. Swap the environment variables for yours.
// npm i express livekit-server-sdk
import express from 'express'
import { AccessToken } from 'livekit-server-sdk'
const app = express()
app.use(express.json())
/** Call this when a call starts in your app. */
async function sendAgentIn({ room, caller, workspaceId, agentId,
delaySeconds = 0, owner }) {
const at = new AccessToken(process.env.LIVEKIT_KEY,
process.env.LIVEKIT_SECRET,
{ identity: 'dialogbrain-agent', ttl: '10m' })
at.addGrant({ roomJoin: true, room, canPublish: true, canSubscribe: true })
const res = await fetch('https://api.dialogbrain.com/v1/voice/bridge', {
method: 'POST',
headers: {
'X-API-Key': process.env.DIALOGBRAIN_KEY,
'X-Workspace-Id': String(workspaceId),
'Idempotency-Key': room, // retries never double-book the room
'Content-Type': 'application/json',
},
body: JSON.stringify({
livekit_url: process.env.LIVEKIT_URL,
room,
token: await at.toJwt(),
agent_id: agentId,
caller_external_identity: caller,
owner_identity: owner, // omit for a pure concierge
answer_delay_s: delaySeconds, // 0 = answer now, 20 = ring first
}),
})
if (!res.ok) throw new Error(`bridge failed: ${res.status} ${await res.text()}`)
return res.json() // { call_id, room, status }
}
app.post('/hooks/dialogbrain', (req, res) => {
const { event, data } = req.body
if (event === 'transcript.turn') saveTurn(data)
if (event === 'call.ended') closeCall(data.call_id, data.outcome,
data.duration_seconds)
res.sendStatus(200)
})# pip install fastapi httpx livekit-api
import os
import httpx
from fastapi import FastAPI, Request
from livekit import api
app = FastAPI()
db = httpx.AsyncClient(
base_url="https://api.dialogbrain.com/v1",
headers={"X-API-Key": os.environ["DIALOGBRAIN_KEY"]},
timeout=30,
)
async def send_agent_in(*, room: str, caller: str, workspace_id: int,
agent_id: int, delay_s: int = 0,
owner: str | None = None) -> dict:
token = (
api.AccessToken(os.environ["LIVEKIT_KEY"], os.environ["LIVEKIT_SECRET"])
.with_identity("dialogbrain-agent")
.with_grants(api.VideoGrants(room_join=True, room=room,
can_publish=True, can_subscribe=True))
.to_jwt()
)
r = await db.post(
"/voice/bridge",
headers={"X-Workspace-Id": str(workspace_id), "Idempotency-Key": room},
json={
"livekit_url": os.environ["LIVEKIT_URL"],
"room": room,
"token": token,
"agent_id": agent_id,
"caller_external_identity": caller,
"owner_identity": owner, # omit for a pure concierge
"answer_delay_s": delay_s, # 0 = answer now, 20 = ring first
},
)
r.raise_for_status()
return r.json() # {"call_id": ..., "status": "active"}
@app.post("/hooks/dialogbrain")
async def dialogbrain_hook(req: Request):
body = await req.json()
if body["event"] == "transcript.turn":
save_turn(body["data"])
elif body["event"] == "call.ended":
close_call(body["data"]["call_id"], body["data"]["outcome"])
return {"ok": True}Register one URL per customer workspace. Deliveries are signed with a secret returned once at creation.
curl -X POST https://api.dialogbrain.com/v1/webhooks \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "X-Workspace-Id: 4821" \
-H "Idempotency-Key: wh-5512" \
-d '{
"url": "https://your-app.com/hooks/dialogbrain",
"event_types": ["call.started", "transcript.turn",
"call.ended", "transcript.ready"]
}'
# The signing secret is in the response. It is shown once.{
"event": "call.ended",
"data": {
"call_id": "7a6daec1b3cc4585ba0280cc50de5e23",
"workspace_id": 4821,
"source": "external_livekit",
"duration_seconds": 96,
"outcome": "caller_left",
"metadata": { "your": "opaque object, echoed back" }
}
}curl "https://api.dialogbrain.com/v1/conversations?limit=20" \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "X-Workspace-Id: 4821"
curl "https://api.dialogbrain.com/v1/conversations/6808472/messages" \
-H "X-API-Key: $DIALOGBRAIN_KEY" -H "X-Workspace-Id: 4821"
# -> both sides of the call, turn by turnEvery POST takes an Idempotency-Key. A retry with the same key returns the original call instead of putting a second agent in the room.
If you have no LiveKit at all, POST /v1/calls with a target and an agent id: a phone number in E.164, a Telegram or WhatsApp target, a Google Meet link. Same transcripts, same webhooks, same per-customer workspaces.
You hold a single API key. The workspace header decides whose data a request touches, and the boundary is enforced on reads too: conversations, calls and balances are scoped to that workspace.
The agent joins your room directly, so media does not take a detour through a third hop. Speech recognition, the model and speech synthesis run behind that one participant.
Create a workspace and an agent for the customer, mint a LiveKit guest token for our participant, then POST /v1/voice/bridge with your LiveKit URL, the room name, that token and the agent id. The agent joins the room and starts talking. No widget or SDK is required.
Yes. That is what the bridge is for: the agent connects to your own LiveKit server as an ordinary participant, using a token you mint and scope to a single room. Your media path is unchanged.
Use POST /v1/calls instead. Pass a target — a phone number, a Telegram or WhatsApp target, or a Google Meet link — and the agent places or answers the call on our side, with the same transcripts and webhooks.
Yes. Set answer_delay_s to the seconds to wait, up to 120, and pass owner_identity. If the owner joins within that window the agent stands down silently and the call is not billed.
Read the conversation the call created through GET /v1/conversations and /v1/conversations/{id}/messages, or subscribe to transcript.turn for live turns and transcript.ready for the finished transcript.
Yes. Every customer gets a workspace with its own balance, funded from yours with POST /v1/workspaces/{id}/credits, and their usage is drawn from it. You keep one API key and one integration.