← Speech data prep and inference API

Duplex Text

Preview

A live 12.5 Hz (80 ms) full-duplex text and asynchronous tool-calling WebSocket for voice engineers bringing their own streaming ASR and TTS. Handles turn-taking, backchannels, mid-sentence barge-in yielding, and parallel tool bursts inside a single stream ($0.30 / connected hour, $0.005 / min).

Preview status: Live for all Trelis API accounts. Looking for end-to-end audio input and output? See Duplex Speech (Preview).

WebSocket protocol and specifications

Stream arriving monotonic ASR deltas in via partner.text while receiving real-time agent.text.delta, atomic agent.tool_call bursts, and agent.speech.pause turn/barge-in events on a fixed 80 ms frame clock.

WebSocket endpointwss://api.trelis.com/v1/duplex/text (model=duplex-text-1)
Pricing$0.30 / connected hour ($0.005 / min), billed per connected second ($0.001 minimum). See pricing →
AuthenticationAuthorization: Bearer tk_live_... header or Sec-WebSocket-Protocol: trelis.auth, tk_live_...
Client framessession.start (system_prompt, optional OpenAI tools), partner.text, tool.result, tool.cancel, session.update (emit_bias, pause_speech), ping, end
Server framesready, session.started, agent.text.delta, agent.tool_call, agent.speech.pause (turn_pause or barge_in), optional tick (including speech_paused), done
Long-call stabilityBounded memory window preserving system prompt, tool schemas, and recent conversational cadence across 30+ minute calls

Live Duplex Text vs. cascaded turn-based LLM stacks

12 realistic phone-support scenarios (4 direct Q&A, 4 async tool calls including parallel 2-tool lookup with 120 ms tool fixtures, and 4 mid-sentence barge-ins) run live against WS /v1/duplex/text versus turn-based pipelines combining Trelis's measured 752 ms p50 turn-endpoint hold with streaming chat completions. Latency is measured from the end of caller text to the first spoken agent token (lower is better).

StackDirectToolsMid-sentence barge-inFirst spoken token p50 (↓)First spoken token p90 (↓)
Trelis duplex-text-1 ($0.30 / connected hr)4 / 44 / 44 / 4 (243 ms p50 / 325 ms p90)208 ms452 ms
Cascaded: Turn-based ASR (752 ms hold) + Trelis gemma-4-e4b-conversational4 / 44 / 4No native 80 ms yield895 ms1,466 ms
Cascaded: Turn-based ASR (752 ms hold) + OpenAI gpt-4o-mini4 / 44 / 4No native 80 ms yield1,327 ms2,490 ms

Core duplex decision, barge-in, and long-call stress suites

BenchmarkResultDetails
Live 80 ms tool-decision accuracy (789 attempts)94.42%92.55% precision, 84.88% recall, 93.88% no-tool specificity, 0 malformed calls
Locked live duplex probes (16 scenarios)15 / 16 (93.8%)Includes atomic single-tick parallel tool calls
Mid-sentence barge-in yield within 1.0 s (8 probes)8 / 8 (100%)100% post-barge-in uptake, 0.00 mean late overlap emits
Multi-turn tool orchestration (18 cases)12 / 18 (66.7%)Includes 3-way parallel tool fan-out and missing-info clarification
Server frame timing (80 ms real-time clock)30.6 ms p5049.5 ms max tick on live US East sessions; well inside the 80 ms frame budget
Timing calibration (301,371 held-out & OOD frames)1.007 emit ratio1.002 on out-of-domain phone calls; 0 markdown leaks on spoken scenarios
30-minute continuous call stability (22,500 frames)0.000 GB driftBounded memory with flat tick latency and intact minute-30 tool calling

Quickstart (Python)

pythonduplex_text.py
import asyncio, json, os, websockets

async def main():
    url = "wss://api.trelis.com/v1/duplex/text"
    headers = {"Authorization": f"Bearer {os.environ['TRELIS_API_KEY']}"}
    async with websockets.connect(url, additional_headers=headers) as ws:
        print(json.loads(await ws.recv()))  # ready (tick_ms=80)
        await ws.send(json.dumps({
            "type": "session.start",
            "system_prompt": "You are a concise phone support agent. Keep answers brief and spoken.",
            "tools": [
                {
                    "type": "function",
                    "function": {
                        "name": "lookup_order",
                        "description": "Look up customer order status and ETA.",
                        "parameters": {
                            "type": "object",
                            "properties": {"order_id": {"type": "string"}},
                            "required": ["order_id"],
                        },
                    },
                }
            ],
        }))
        print(json.loads(await ws.recv()))  # session.started

        await ws.send(json.dumps({"type": "partner.text", "delta": "Hi, can you check order B42?"}))
        while True:
            ev = json.loads(await ws.recv())
            print(ev)
            if ev["type"] == "agent.tool_call":
                await ws.send(json.dumps({
                    "type": "tool.result",
                    "call_id": ev["call_id"],
                    "content": {"order_id": "B42", "status": "out_for_delivery", "eta": "3pm today"},
                }))
            elif ev["type"] == "agent.speech.pause":
                break
        await ws.send(json.dumps({"type": "end"}))
        print(json.loads(await ws.recv()))  # done (connected_seconds, cost_usd)

asyncio.run(main())