Check a phone call while it happens. One WebSocket per call checks the caller for AI-generated speech and, in the same stream, verifies them against an enrolled speaker or enrolls them. Works with Twilio, Plivo, Telnyx, Exotel, Vonage, FreeSWITCH, any other platform through a relay, and your own code.

Check a phone call while it happens. Your telephony platform streams the caller's audio to one WebSocket. One stream runs deepfake detection and, on the same audio, speaker verification or enrollment:

checks What one stream does You get
deepfake Checks the caller for AI-generated speech An early verdict when the start of the call is clear, live verdicts while it runs, a final verdict when it ends
deepfake,verify with a speaker_id The same, and verifies the caller against an enrolled speaker The verdicts, and match or no_match, usually within 3 to 5 seconds of speech
deepfake,enroll with a speaker_id The same, and enrolls the caller's voice The verdicts, and the caller enrolled when the call ends (from 15 seconds of speech)
Example
wss://platform.detectif.ai/v1/stream?checks=deepfake,verify&speaker_id=customer-4711

Every result arrives on the socket and as a webhook, so your backend does not have to read the socket.

Works with your telephony platform

Platform How the call's audio reaches the stream Setup
Twilio <Start><Stream> in your TwiML Twilio
Plivo The <Stream> element Plivo
Telnyx TeXML <Stream> or Call Control streaming Telnyx
Exotel The Stream or Voicebot applet Exotel
Vonage A WebSocket endpoint in your NCCO Vonage
FreeSWITCH An audio-fork module such as mod_audio_fork FreeSWITCH
Asterisk, your own media server, any other platform A small relay on your server Relay
Your own code Raw audio frames from any WebSocket client Your own code

Only speech is checked. The stream finds the speech as the audio arrives and leaves out silence, hold time, ringing and music; short pauses between words are kept. Every check works on the caller's speech alone, and the deepfake check is billed by the speech it checked, not by the length of the call. Send the audio as it happens, silences included: nothing has to be cut on your side.

Connect

One stream per call. Authenticate in one of two ways:

  • API key header, when your client can set headers (your own code, a relay): Authorization: Bearer <your API key> on the upgrade request.
  • Stream token, when it cannot (Twilio, Plivo, Telnyx, Vonage, FreeSWITCH). From your server, just before the call, create a single-use token with your API key, then pass it as ?token=stk_... in the stream URL or as the token custom parameter of the start message. A token works once and expires after 10 minutes. Never put the API key itself in a URL or a stream parameter: such a stream is refused.
Shell
curl -X POST https://platform.detectif.ai/v1/stream/tokens \
  -H "Authorization: Bearer $DETECTIF_API_KEY"
# {"object": "stream_token", "token": "stk_...", "expires_at": "..."}

Create a stream token

POST /v1/stream/tokens

For telephony platforms that cannot send an Authorization header when they open the stream: returns a single-use token, valid for 10 minutes, to pass as ?token= on wss://platform.detectif.ai/v1/stream or as the token custom parameter of the stream's start message. Never put an API key itself in a URL. Requires one of the scopes deepfake:detect, speakers:verify or speakers:enroll; the stream gets the same scopes as this key.

Full URL: https://platform.detectif.ai/v1/stream/tokens. Send your API key as Authorization: Bearer <your API key>.

Request

Headers:

Name Type Required Description
Authorization string yes Bearer <your API key>. Keys are created in the dashboard; see Authentication.

Response

200: Success.

Field Type Always there Description
request_id string yes
object string yes (always "stream_token")
token string yes
expires_at string yes

Example response:

JSON
{
  "request_id": "req_8f14e45fceea167a5a36dedd",
  "object": "stream_token",
  "token": "stk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "expires_at": "2026-11-11T10:10:00Z"
}

Errors

Status Meaning
401 The API key is missing, invalid or revoked.
403 The key lacks the required scope, the email address is not verified, or the account is suspended.
429 Too many requests or too many operations at the same time. Wait for the number of seconds in Retry-After.
500 Something went wrong on our side. No credits were used.

Every error body has the shape described in Errors, with a stable error.code.

Example

cURL
curl -X POST "https://platform.detectif.ai/v1/stream/tokens" \
  -H "Authorization: Bearer $DETECTIF_API_KEY"

Telephony platforms

Twilio

Fork the call's audio with <Start><Stream>; the call goes on as usual. Twilio sends μ-law at 8 kHz, which the stream reads as it is. Create the token in your voice webhook, right before you return the TwiML:

XML
<Response>
  <Start>
    <Stream url="wss://platform.detectif.ai/v1/stream" track="inbound_track">
      <Parameter name="token" value="stk_..." />
      <Parameter name="checks" value="deepfake" />
      <Parameter name="reference" value="your-call-id" />
    </Stream>
  </Start>
  <Dial>+15551234567</Dial>
</Response>
Python
# voice.py: Twilio voice webhook that checks each caller for AI-generated speech
import os

import requests
from flask import Flask
from twilio.twiml.voice_response import Dial, Start, Stream, VoiceResponse

app = Flask(__name__)

@app.post("/voice")
def voice():
    token = requests.post(
        "https://platform.detectif.ai/v1/stream/tokens",
        headers={"Authorization": f"Bearer {os.environ['DETECTIF_API_KEY']}"},
        timeout=10,
    ).json()["token"]
    response = VoiceResponse()
    start = Start()
    stream = Stream(url="wss://platform.detectif.ai/v1/stream", track="inbound_track")
    stream.parameter(name="token", value=token)
    stream.parameter(name="checks", value="deepfake")
    start.append(stream)
    response.append(start)
    response.append(Dial("+15551234567"))
    return str(response), 200, {"Content-Type": "text/xml"}

The call's CallSid becomes the stream's reference unless you set one. Twilio does not pass messages from the stream back to you: read the results from your webhooks.

Plivo

Plivo's <Stream> element sends the call's audio to a WebSocket. Put the token and the parameters in the URL, and write each & in XML as &amp;:

XML
<Response>
  <Stream bidirectional="false" audioTrack="inbound" contentType="audio/x-mulaw;rate=8000">wss://platform.detectif.ai/v1/stream?token=stk_...&amp;checks=deepfake&amp;encoding=mulaw&amp;sample_rate=8000</Stream>
  <!-- your existing call flow continues here -->
</Response>

Create the token in your answer webhook, right before you return the XML, as in the Twilio example.

Telnyx

With TeXML, add a <Stream> inside <Start> so the call carries on. Telnyx sends PCMU (μ-law) at 8 kHz by default:

XML
<Response>
  <Start>
    <Stream url="wss://platform.detectif.ai/v1/stream?token=stk_...&amp;checks=deepfake" track="inbound_track"/>
  </Start>
  <!-- your existing call flow continues here -->
</Response>

With Call Control, start streaming on the answered call with stream_url set to the same URL (with a fresh token) and stream_track set to inbound_track.

Exotel

Exotel's Stream and Voicebot applets send 16-bit PCM at 8 kHz, in base64 inside JSON messages. Set the applet's URL to:

Example
wss://platform.detectif.ai/v1/stream?token=stk_...&checks=deepfake&encoding=pcm_s16le&sample_rate=8000

A token works once, so the URL must be made for each call. If your Exotel flow uses a fixed URL, point it at a relay on your server instead.

Vonage

In your NCCO, connect the call to the stream. Vonage sends 16-bit PCM as binary frames; the first text message it sends is ignored:

JSON
[
  {
    "action": "connect",
    "endpoint": [
      {
        "type": "websocket",
        "uri": "wss://platform.detectif.ai/v1/stream?token=stk_...&checks=deepfake&encoding=pcm_s16le&sample_rate=16000",
        "content-type": "audio/l16;rate=16000"
      }
    ]
  }
]

Build the NCCO in your answer webhook with a fresh token. The WebSocket becomes a leg of the call and hears the conversation; the stream sends no audio back.

FreeSWITCH

Fork the caller's channel with an audio-fork module such as mod_audio_fork, once the call is answered. It sends 16-bit PCM as binary frames:

Example
uuid_audio_fork <uuid> start wss://platform.detectif.ai/v1/stream?token=stk_...&checks=deepfake&encoding=pcm_s16le&sample_rate=16000 mono 16k

mono sends that channel's audio only and 16k sets 16 kHz. Check your module's documentation for its exact options.

Relay (any other platform)

When a platform cannot open the stream itself (Asterisk AudioSocket, a fixed Exotel URL, your own media server), run a small relay: it accepts the platform's connection, opens the stream with your API key in a header, and forwards the audio. This relay forwards Twilio-, Plivo-, Telnyx- and Exotel-style JSON messages and binary audio unchanged (pip install websockets):

Python
# relay.py: your platform -> this relay -> DetectifAI live call stream
import asyncio, json, os

import websockets

STREAM = "wss://platform.detectif.ai/v1/stream?checks=deepfake"

async def relay(platform):
    headers = {"Authorization": f"Bearer {os.environ['DETECTIF_API_KEY']}"}
    async with websockets.connect(STREAM, additional_headers=headers) as detectif:
        async def results():
            async for message in detectif:
                print(json.loads(message))  # ready, early verdict, live updates, completed
        reader = asyncio.create_task(results())
        async for message in platform:  # text (JSON) and binary frames, as they come
            await detectif.send(message)
        await detectif.send(json.dumps({"type": "stop"}))
        await reader

async def main():
    async with websockets.serve(relay, "0.0.0.0", 8080):
        await asyncio.Future()

asyncio.run(main())

Add &encoding=...&sample_rate=... to STREAM when the platform sends raw audio without describing it.

Your own code

Send raw audio frames from any WebSocket client:

Python
import asyncio, json, os

import websockets

async def main():
    url = ("wss://platform.detectif.ai/v1/stream?checks=deepfake&encoding=pcm_s16le"
           "&sample_rate=16000&reference=call-123")
    headers = {"Authorization": f"Bearer {os.environ['DETECTIF_API_KEY']}"}
    async with websockets.connect(url, additional_headers=headers) as ws:
        print(json.loads(await ws.recv()))           # {"type": "ready", "stream_id": "str_...", ...}
        with open("call.raw", "rb") as audio:        # 16-bit PCM, 16 kHz, mono
            while chunk := audio.read(3200):         # 100 ms
                await ws.send(chunk)
                await asyncio.sleep(0.1)
        await ws.send(json.dumps({"type": "stop"}))
        async for message in ws:                     # early verdict, live updates, then "completed"
            print(json.loads(message))

asyncio.run(main())

Verify or enroll the caller

Add verify or enroll to checks, with a speaker_id, and the same stream that checks the call for AI-generated speech also verifies the caller against a speaker you enrolled earlier, or enrolls the caller from the call. One stream either verifies or enrolls. Enroll a speaker from recordings on the Speaker verification page, or from a call as below.

Example
wss://platform.detectif.ai/v1/stream?checks=deepfake,verify&speaker_id=customer-4711
Parameter With Meaning
checks verify or enroll (each combines with deepfake) One verification against the enrolled speaker, or one enrollment of the caller.
speaker_id Both The enrolled speaker to verify against, or the speaker to create or add a sample to.
display_name enroll The speaker's name, up to 100 characters.

Twilio example: verify the caller and check for AI-generated speech.

XML
<Response>
  <Start>
    <Stream url="wss://platform.detectif.ai/v1/stream" track="inbound_track">
      <Parameter name="token" value="stk_..." />
      <Parameter name="checks" value="deepfake,verify" />
      <Parameter name="speaker_id" value="customer-4711" />
    </Stream>
  </Start>
  <Dial>+15551234567</Dial>
</Response>

Verification during a call

  • The stream reads the caller's speech from 3 seconds on, then every 2 seconds. As soon as the voice clearly matches the enrolled speaker, or clearly does not, it makes the verification on that speech and sends the answer (early: true). On our test calls, most callers were decided within 3 to 5 seconds of speech, and an early answer agreed with the answer at 15 seconds of speech more than 99.9% of the time.
  • When the voice is not clearly one or the other, the verification is made at 15 seconds of speech (early: false), or at the end of a call with less speech (at least 3 seconds).
  • There is one verification per stream, charged once; the readings before it are free.
JSON
{"type": "verification", "final": true, "early": true, "operation_id": "op_0b1c...", "object": "speaker.verification",
 "speaker_id": "customer-4711", "result": {"decision": "match", "similarity": 0.83, "duration_seconds": 5.0},
 "stream_id": "str_3f2b...", "reference": "CA1234"}

The body is the same as from Verify a speaker; result.duration_seconds is the speech it used. It is repeated under results.verification in the stream's completed message, and sent as the speaker.verified webhook (with stream_id, reference and early).

Enrollment from a call

With checks=deepfake,enroll, the caller is enrolled as speaker_id when the call ends, from the first 60 seconds of their speech. It needs at least 15 seconds of speech; with less, results.enrollment has an insufficient_speech error and nothing is charged.

JSON
{"type": "enrollment", "final": true, "operation_id": "op_ac99...", "object": "speaker.enrollment",
 "speaker": {"speaker_id": "customer-4711", "display_name": "Alice", "samples": 1},
 "quality": {"speech_seconds": 18.6, "duration_seconds": 24.3},
 "stream_id": "str_3f2b...", "reference": "CA1234"}

The speech used for a verification or an enrollment is kept like an uploaded recording (see Privacy).

Parameters

Send them in the query string, or as custom parameters of the start message (the query string wins).

Parameter Values Default
checks deepfake, verify, enroll, comma-separated. deepfake combines with verify or with enroll; one stream cannot verify and enroll at once. deepfake
speaker_id Required with verify and enroll. 1-64 of A-Z a-z 0-9 _ . : -
display_name With enroll: the speaker's name, up to 100 characters
reference Your own id for the call, up to 128 characters, returned in every message and webhook the call id of the start message (callSid, callId, ...)
track Which side of the call to check in media messages: inbound (the caller) or outbound inbound
encoding Raw audio: pcm_s16le, mulaw or alaw from start, else pcm_s16le (mulaw for media messages)
sample_rate 8000 or 16000 from start, else 16000 (8000 for μ-law and A-law)
update_seconds Seconds of new speech between live deepfake updates, 5-60 10
token A stream token, when you cannot send the Authorization header

Audio you send

  • Binary frames: raw mono audio in encoding and sample_rate, up to 64 KB each.
  • Media messages (Twilio, Plivo, Telnyx, Exotel style): JSON text frames connected, start, media (media.payload is base64 audio, media.track the side of the call), stop. The audio format is read from the start message (mediaFormat or media_format: μ-law, A-law or 16-bit PCM at 8 or 16 kHz). mark, dtmf and other messages are ignored; so is audio of the other track.
  • End the stream with {"event": "stop"}, {"type": "stop"}, or by closing the socket. A stream also ends after 60 seconds without audio and after 2 hours.

Messages you receive

Every message is a JSON text frame with a type, the stream_id and your reference.

ready, when the stream is open:

JSON
{"type": "ready", "stream_id": "str_3f2b9c0d4e5f4a6b8c7d9e0f1a2b3c4d", "checks": ["deepfake", "verify"], "reference": "CA1234", "request_id": "req_0f1cd73f489f58cc3ebc40f0"}

The early verdict, when the first seconds of speech are already clearly real or clearly fake (early is true; at most one per stream, none when the start of the call is not clear):

JSON
{"type": "deepfake", "early": true, "final": false, "sequence": 1, "seconds": 6.2, "speech_seconds": 4.5, "window_seconds": 4.5,
 "verdict": "real", "score": 0.012, "stream_id": "str_3f2b...", "reference": "CA1234"}

A live update about the latest speech (early and final are false). seconds is all the audio received so far, speech_seconds the speech checked:

JSON
{"type": "deepfake", "early": false, "final": false, "sequence": 3, "seconds": 42.5, "speech_seconds": 30.1, "window_seconds": 20.0,
 "verdict": "real", "score": 0.041, "stream_id": "str_3f2b...", "reference": "CA1234"}

verification and enrollment, when the stream checks a speaker: see Verify or enroll the caller.

completed, when the stream ends: the final result of every check.

JSON
{
  "type": "completed",
  "stream_id": "str_3f2b9c0d4e5f4a6b8c7d9e0f1a2b3c4d",
  "reference": "CA1234",
  "status": "completed",
  "checks": ["deepfake"],
  "seconds": 89.3,
  "speech_seconds": 61.0,
  "ended_by": "client_stop",
  "results": {
    "deepfake": {
      "object": "deepfake.detection",
      "operation_id": "op_6f1e...",
      "final": true,
      "updates": 6,
      "early": {"verdict": "real", "score": 0.012, "speech_seconds": 4.5, "seconds": 6.2},
      "result": {"verdict": "real", "score": 0.046, "duration_seconds": 61.0, "scored_seconds": 61.0,
                 "segments": [{"start": 6.0, "end": 10.0, "score": 0.019, "verdict": "real"}]}
    }
  }
}

Then the socket closes with code 1000.

  • The final verdict judges all the speech of the call (the last 5 minutes of speech in a longer one); it is the answer to act on. The early verdict and the live updates help you react during the call.
  • In the final result, each segment's start and end are seconds of the call, like seconds everywhere else, so you can find the moment in your own recording. A segment can stretch over a silence that was left out. duration_seconds and scored_seconds count the speech checked.
  • A check that could not run (for example insufficient_speech: a call with almost no speech) has an error instead of a result, and is not charged.
  • ended_by says why the stream ended: client_stop, client_closed, idle, max_duration, insufficient_credits or server_shutdown.

Early answers

The stream gives an answer as soon as it is clear, instead of waiting a fixed time:

  • Deepfake: the first 4.5, 6 and 8 seconds of speech are checked; the first of them that is clearly real or clearly fake is sent as the early verdict. When none is clear, there is no early verdict and the live updates start at 10 seconds of speech.
  • Speaker verification: see Verification during a call.

On our test calls, an early verdict agreed with the verdict over the whole call 99% of the time, and two calls in three got one. Act on the final verdict when the decision matters.

Errors and close codes

Before closing, the stream sends {"type": "error", "code": "...", "message": "...", "request_id": "..."}.

Close code Meaning
1000 The stream ended normally.
1003 A parameter or message was not valid (invalid_checks, missing_speaker_id, api_key_in_url, frame_too_large, ...).
1011 Something went wrong on our side. Please try again after some time.
1012 The service restarted; open a new stream.
1013 Too many live streams right now; try again shortly.
4401 Missing or invalid credentials, or a used or expired stream token.
4402 Not enough credits to start, or credits ran out during the call.
4403 The API key lacks a permission the checks need (deepfake:detect, speakers:verify, speakers:enroll), or the account cannot be used.
4429 Your account already has as many live streams as it may (too_many_streams).

A plain HTTP request to /v1/stream (without the WebSocket upgrade) gets 426.

After the call

Read a stream's record (its parameters, the results and why it ended) for 30 days:

Get a stream's results

GET /v1/streams/{stream_id}

The record of one live call stream of your account (kept 30 days): its status, how much audio arrived, why it ended, the final result of each check and the operations they created. The same results arrive on the stream itself and as webhook events. Requires one of the scopes deepfake:detect, speakers:verify or speakers:enroll.

Full URL: https://platform.detectif.ai/v1/streams/{stream_id}. Send your API key as Authorization: Bearer <your API key>.

Request

Headers:

Name Type Required Description
Authorization string yes Bearer <your API key>. Keys are created in the dashboard; see Authentication.

Path parameters:

Name Type Required Description
stream_id string yes The stream id (str_...) from the stream's ready message. (at most 64 characters)

Response

200: Success.

Field Type Always there Description
request_id string yes
object string yes (always "stream")
stream_id string yes
status string yes (one of live, completed, interrupted, failed)
checks array of string yes
speaker_id string or null no
reference string or null no
audio object yes
audio.transport string or null no (one of binary, media_json)
audio.encoding string or null no (one of pcm_s16le, mulaw, alaw)
audio.sample_rate integer or null no
audio.track string or null no (one of inbound, outbound)
seconds number yes
speech_seconds number yes
ended_by string or null no
results object yes
operations object yes
credits object yes
credits.charged integer yes
created_at string or null no
ended_at string or null no

Example response:

JSON
{
  "request_id": "req_8f14e45fceea167a5a36dedd",
  "object": "stream",
  "stream_id": "str_3f2b9c0d4e5f4a6b8c7d9e0f1a2b3c4d",
  "status": "completed",
  "checks": [
    "deepfake",
    "verify"
  ],
  "speaker_id": "customer-4711",
  "reference": "CA1234567890abcdef",
  "seconds": 84.2,
  "speech_seconds": 51.6,
  "ended_by": "client_stop",
  "audio": {
    "transport": "media_json",
    "encoding": "mulaw",
    "sample_rate": 8000,
    "track": "inbound"
  },
  "results": {
    "deepfake": {
      "object": "deepfake.detection",
      "operation_id": "op_6f1ed002ab5595859014ebf0951522d9",
      "final": true,
      "result": {
        "verdict": "real",
        "score": 0.031
      }
    },
    "verification": {
      "operation_id": "op_0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e",
      "result": {
        "decision": "match"
      }
    }
  },
  "operations": {
    "deepfake": "op_6f1ed002ab5595859014ebf0951522d9",
    "verification": "op_0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e"
  },
  "created_at": "2026-10-13T09:30:00Z",
  "ended_at": "2026-11-11T09:31:24Z"
}

Errors

Status Meaning
400 The request is invalid, for example a missing or malformed field.
401 The API key is missing, invalid or revoked.
403 The key lacks the required scope, the email address is not verified, or the account is suspended.
404 Not found. Also returned for resources that belong to another account.
429 Too many requests or too many operations at the same time. Wait for the number of seconds in Retry-After.
500 Something went wrong on our side. No credits were used.

Every error body has the shape described in Errors, with a stable error.code.

Example

cURL
curl "https://platform.detectif.ai/v1/streams/str_3f2b9c0d4e5f4a6b8c7d9e0f1a2b3c4d" \
  -H "Authorization: Bearer $DETECTIF_API_KEY"

Credits and limits

  • Streams are billed like the matching checks: deepfake detection by the length of speech checked (silence is not billed), verification and enrollment per check. See Billing in the dashboard.
  • Credits for the deepfake check are held a little ahead of the audio; if they run out, the stream ends with code 4402 and you still get the results for the audio received.
  • Each account can have a few live streams at once (more once you have bought credits).
  • The speech used for a verification or an enrollment is kept like an uploaded recording (see Privacy). The rest of the call is checked as it arrives. The stream's record is kept 30 days.