Docs API
Recipes
Complete scripts for common tasks. Set RELAYDOCK_API_KEY, copy a script and run it. The curl versions need bash, jq and curl 7.76 or later, and stop at the first error.
Change an endpoint's agent
Send only the field you change. The response is the endpoint with provision_statepending while RelayDock updates the dispatch rule in LiveKit; once it is ready again, new calls go to the new agent.
curl -X PATCH "https://api.relaydock.io/api/v1/endpoints/3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13" \
-H "Authorization: Bearer $RELAYDOCK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_name": "support-agent"
}'import os
import requests
response = requests.patch(
"https://api.relaydock.io/api/v1/endpoints/3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13",
headers={"Authorization": f"Bearer {os.environ['RELAYDOCK_API_KEY']}"},
json={"agent_name": "support-agent"},
timeout=30,
)
response.raise_for_status()
print(response.json())const response = await fetch('https://api.relaydock.io/api/v1/endpoints/3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13', {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${process.env.RELAYDOCK_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"agent_name": "support-agent"
}),
})
if (!response.ok)
throw new Error(`${response.status} ${await response.text()}`)
console.log(await response.json()) The same request changes mode, outbound_numbers or enabled. See Update an endpoint for every field and how null resets a value.
Create an endpoint and wait until it is ready
Creating an endpoint returns right away with provision_state pending, or waiting_target if no LiveKit project is connected. This script creates a registration endpoint and reads it every 3 seconds until LiveKit setup has a result and, for a registration, the first registration attempt has one too.
set -euo pipefail
API=https://api.relaydock.io/api/v1
AUTH="Authorization: Bearer $RELAYDOCK_API_KEY"
ID=$(curl -sS --fail-with-body -X POST "$API/endpoints" -H "$AUTH" -H "Content-Type: application/json" \
-d '{"kind":"registration","provider":"telnyx","agent_name":"my-agent","registration":{"transport":"tcp","username":"SIP_USERNAME","password":"SIP_PASSWORD","number":"+12025550123"}}' | jq -r .id)
for attempt in $(seq 40); do
ENDPOINT=$(curl -sS --fail-with-body "$API/endpoints/$ID" -H "$AUTH")
echo "$ENDPOINT" | jq -c '{provision_state, provision_error, registration: .registration.state}'
# Done when LiveKit setup is no longer pending and a registration has a result.
if echo "$ENDPOINT" | jq -e '.provision_state != "pending"
and ((.registration.state // "done") | . != "unknown" and . != "registering")' > /dev/null; then
break
fi
sleep 3
doneimport os
import time
import requests
API = "https://api.relaydock.io/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['RELAYDOCK_API_KEY']}"}
response = requests.post(
f"{API}/endpoints",
headers=HEADERS,
json={
"kind": "registration",
"provider": "telnyx",
"agent_name": "my-agent",
"registration": {
"transport": "tcp",
"username": "SIP_USERNAME",
"password": "SIP_PASSWORD",
"number": "+12025550123",
},
},
timeout=30,
)
response.raise_for_status()
endpoint = response.json()
def settled(endpoint: dict) -> bool:
"""LiveKit setup is no longer pending and a registration has a result."""
registration = endpoint["registration"]
waiting = registration is not None and registration["state"] in ("unknown", "registering")
return endpoint["provision_state"] != "pending" and not waiting
deadline = time.monotonic() + 120
while not settled(endpoint) and time.monotonic() < deadline:
time.sleep(3)
response = requests.get(f"{API}/endpoints/{endpoint['id']}", headers=HEADERS, timeout=30)
response.raise_for_status()
endpoint = response.json()
print("LiveKit:", endpoint["provision_state"], endpoint["provision_error"] or "")
if endpoint["registration"]:
print("Registration:", endpoint["registration"]["state"], endpoint["registration"]["last_code"] or "")
if endpoint["diagnosis"]:
print("Diagnosis:", endpoint["diagnosis"]["key"])const API = 'https://api.relaydock.io/api/v1'
const headers = { Authorization: `Bearer ${process.env.RELAYDOCK_API_KEY}` }
async function request(path, options = {}) {
const response = await fetch(`${API}${path}`, { ...options, headers: { ...headers, ...options.headers } })
if (!response.ok)
throw new Error(`${response.status} ${await response.text()}`)
return response.json()
}
// LiveKit setup is no longer pending and a registration has a result.
function settled(endpoint) {
const waiting = endpoint.registration && ['unknown', 'registering'].includes(endpoint.registration.state)
return endpoint.provision_state !== 'pending' && !waiting
}
let endpoint = await request('/endpoints', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
kind: 'registration',
provider: 'telnyx',
agent_name: 'my-agent',
registration: { transport: 'tcp', username: 'SIP_USERNAME', password: 'SIP_PASSWORD', number: '+12025550123' },
}),
})
const deadline = Date.now() + 120_000
while (!settled(endpoint) && Date.now() < deadline) {
await new Promise(resolve => setTimeout(resolve, 3000))
endpoint = await request(`/endpoints/${endpoint.id}`)
}
console.log('LiveKit:', endpoint.provision_state, endpoint.provision_error ?? '')
if (endpoint.registration)
console.log('Registration:', endpoint.registration.state, endpoint.registration.last_code ?? '')
if (endpoint.diagnosis)
console.log('Diagnosis:', endpoint.diagnosis.key) A healthy endpoint ends with ready and registered. If not, diagnosis.key names the problem: see Troubleshooting.
Export calls as CSV
Export up to 31 days at a time; without from and to you get the last 30 days. A team can export 10 times an hour.
curl "https://api.relaydock.io/api/v1/calls/export?from=2026-11-01T00%3A00%3A00Z&to=2026-11-16T00%3A00%3A00Z" \
-H "Authorization: Bearer $RELAYDOCK_API_KEY" \
-o calls.csvimport os
import requests
response = requests.get(
"https://api.relaydock.io/api/v1/calls/export",
headers={"Authorization": f"Bearer {os.environ['RELAYDOCK_API_KEY']}"},
params={
"from": "2026-11-01T00:00:00Z",
"to": "2026-11-16T00:00:00Z",
},
timeout=30,
)
response.raise_for_status()
with open("calls.csv", "w", encoding="utf-8") as file:
file.write(response.text)import { writeFile } from 'node:fs/promises'
const response = await fetch('https://api.relaydock.io/api/v1/calls/export?from=2026-11-01T00%3A00%3A00Z&to=2026-11-16T00%3A00%3A00Z', {
headers: {
'Authorization': `Bearer ${process.env.RELAYDOCK_API_KEY}`,
},
})
if (!response.ok)
throw new Error(`${response.status} ${await response.text()}`)
await writeFile('calls.csv', await response.text())The file has one row per call, ordered by time, with the columns described in Export calls.
Run a test call and wait for the result
Starts an outbound test call through an endpoint and reads it every 2 seconds until it is completed or failed, then prints each step.
set -euo pipefail
API=https://api.relaydock.io/api/v1
AUTH="Authorization: Bearer $RELAYDOCK_API_KEY"
ENDPOINT_ID=3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13
TEST_ID=$(curl -sS --fail-with-body -X POST "$API/endpoints/$ENDPOINT_ID/test-calls" -H "$AUTH" \
-H "Content-Type: application/json" -d '{"to": "+12025550147"}' | jq -r .id)
for attempt in $(seq 100); do
CALL=$(curl -sS --fail-with-body "$API/test-calls/$TEST_ID" -H "$AUTH")
STATE=$(echo "$CALL" | jq -r .state)
if [ "$STATE" = completed ] || [ "$STATE" = failed ]; then
break
fi
sleep 2
done
echo "$CALL" | jq -r '.steps[] | [.key, .status, (.code // ""), (.detail // "")] | @tsv'
echo "$CALL" | jq -c '{state, result_code, error}'import os
import time
import requests
API = "https://api.relaydock.io/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['RELAYDOCK_API_KEY']}"}
ENDPOINT_ID = "3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13"
response = requests.post(
f"{API}/endpoints/{ENDPOINT_ID}/test-calls",
headers=HEADERS,
json={"to": "+12025550147"},
timeout=30,
)
response.raise_for_status()
call = response.json()
# The phone rings for up to 30 seconds and a test call lasts 2 minutes at most.
deadline = time.monotonic() + 300
while call["state"] not in ("completed", "failed") and time.monotonic() < deadline:
time.sleep(2)
response = requests.get(f"{API}/test-calls/{call['id']}", headers=HEADERS, timeout=30)
response.raise_for_status()
call = response.json()
for step in call["steps"]:
print(step["key"], step["status"], step["code"] or "", step["detail"] or "")
print(call["state"], call["result_code"], call["error"] or "")const API = 'https://api.relaydock.io/api/v1'
const headers = { Authorization: `Bearer ${process.env.RELAYDOCK_API_KEY}` }
const ENDPOINT_ID = '3f6c2a1e-8b4d-4c7a-9e21-5d0b7f9a6c13'
async function request(path, options = {}) {
const response = await fetch(`${API}${path}`, { ...options, headers: { ...headers, ...options.headers } })
if (!response.ok)
throw new Error(`${response.status} ${await response.text()}`)
return response.json()
}
let call = await request(`/endpoints/${ENDPOINT_ID}/test-calls`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ to: '+12025550147' }),
})
// The phone rings for up to 30 seconds and a test call lasts 2 minutes at most.
const deadline = Date.now() + 300_000
while (!['completed', 'failed'].includes(call.state) && Date.now() < deadline) {
await new Promise(resolve => setTimeout(resolve, 2000))
call = await request(`/test-calls/${call.id}`)
}
for (const step of call.steps)
console.log(step.key, step.status, step.code ?? '', step.detail ?? '')
console.log(call.state, call.result_code, call.error ?? '')What each step means is in Test calls.
Read every call in a time range
The call list returns up to 200 calls per page, newest first. Pass next_cursor back as cursor until it is null.
set -euo pipefail
API=https://api.relaydock.io/api/v1
AUTH="Authorization: Bearer $RELAYDOCK_API_KEY"
URL="$API/calls?since=2026-11-01T00:00:00Z&limit=200"
CURSOR=""
while : ; do
PAGE=$(curl -sS --fail-with-body "$URL${CURSOR:+&cursor=$CURSOR}" -H "$AUTH")
echo "$PAGE" | jq -c '.items[] | {invited_at, direction, caller, callee, duration_s, sip_code, reason}'
CURSOR=$(echo "$PAGE" | jq -r '.next_cursor // empty')
[ -n "$CURSOR" ] || break
doneimport os
import requests
API = "https://api.relaydock.io/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['RELAYDOCK_API_KEY']}"}
params = {"since": "2026-11-01T00:00:00Z", "limit": 200}
calls = []
while True:
response = requests.get(f"{API}/calls", headers=HEADERS, params=params, timeout=30)
response.raise_for_status()
page = response.json()
calls.extend(page["items"])
if not page["next_cursor"]:
break
params["cursor"] = page["next_cursor"]
print(len(calls), "calls")const API = 'https://api.relaydock.io/api/v1'
const headers = { Authorization: `Bearer ${process.env.RELAYDOCK_API_KEY}` }
const calls = []
let cursor = null
do {
const query = new URLSearchParams({ since: '2026-11-01T00:00:00Z', limit: '200' })
if (cursor)
query.set('cursor', cursor)
const response = await fetch(`${API}/calls?${query}`, { headers })
if (!response.ok)
throw new Error(`${response.status} ${await response.text()}`)
const page = await response.json()
calls.push(...page.items)
cursor = page.next_cursor
} while (cursor)
console.log(calls.length, 'calls')