Cartesia Agents with Exotel AgentStream
15 min
connect an exotel phone call to a deployed cartesia https //play cartesia ai/agents voice agent over agentstream cartesia runs the full speech to speech stack (stt, llm, tts, turn taking) your bridge only moves pcm between exotel and cartesia’s agents websocket api https //docs cartesia ai/line/integrations/websocket api sample code integrations/agents/cartesia line native https //github com/exotel/agent stream/tree/main/integrations/agents/cartesia line native in the agent stream https //github com/exotel/agent stream repo if you have not set up connect yet, start with connect voice ai with agentstream https //docs exotel com/exotel agentstream/connect voice ai with agentstream what you get outbound (or inbound via applet) calls that talk to your cartesia line agent ( agent … ) bidirectional agentstream pcm at 8 khz (telephony default) uplink gate so early line noise does not barge into the greeting access token cache + startup prewarm to cut first media latency caller ←→ exotel ←wss pcm→ fastapi /ws ←wss→ cartesia line agent this is not the same as using cartesia sonic as tts inside a cascaded stt→llm→tts pipeline (for example pipecat or deepgram gemini cartesia native ) here the line agent owns the conversation before you start item notes cartesia api key ( sk car … ) + deployed line agent id ( agent … ) exotel account sid, api key, api token, exophone python 3 10–3 12 prefer 3 12 ( audioop + websockets work cleanly) public wss cloudflared or ngrok for the first test audio tip default wire format is cartesia mulaw 8000 (μ law at 8 khz) exotel agentstream stays pcm16 @ 8 khz; the bridge converts both ways with no resample that keeps pitch/speed correct on the handset install git clone https //github com/exotel/agent stream git cd agent stream cp shared/env exotel example shared/ env exotel \# fill exotel account sid, exotel api key, exotel api token, exotel caller id cd integrations/agents/cartesia line native python3 12 m venv venv && source venv/bin/activate pip install r requirements txt cp env example env edit env (never commit this file) cartesia api key=sk car cartesia agent id=agent server port=4055 \# optional cartesia uplink gate ms=2500 smoke test cartesia alone (no phone) python test ws connection py you should see ack , then media output / transcript deltas from the agent greeting run the bridge and open a tunnel terminal a cd integrations/agents/cartesia line native source venv/bin/activate python server py on startup you should see cartesia access token prewarmed , then uvicorn on 0 0 0 0 4055 websocket path /ws terminal b cloudflared tunnel url http //127 0 0 1 4055 \# or ngrok http 4055 place a connect call from the repo root set a && source shared/ env exotel && set +a python shared/place connect call py \\ \ to +91xxxxxxxxxx \\ \ stream url "wss\ //your host/ws?sample rate=8000" streamurl wss\ //host/ws?sample rate=8000 port 4055 streamtype bidirectional answer the handset the line agent should greet within about 1–1 5s of agentstream start (after token prewarm), then respond when you speak auth (cartesia) server side flow matches cartesia docs post https //api cartesia ai/access token with grants { "agent" true } connect wss\ //api cartesia ai/agents/stream/{agent id} with authorization bearer \<token> and cartesia version 2025 04 16 first message must be start ( input format , optional voice id / agent overrides) stream media input / receive media output , handle clear , conversation events this sample caches the token and refreshes it before expiry so later calls skip the http rtt latency notes without gating, first audio can land around 4s because cold access token + websocket connect ( 1s) early exotel uplink noise is treated as a user turn → cartesia clear delays the greeting ( 2–3s) the sample mitigates both (token prewarm + uplink gate) useful log lines ready ms=… / token ms=… / ws ms=… / ack ms=… cartesia first media out ms=… / since ack ms=… first audio ms=… uplink open reason=assistant turn ended|gate timeout tune cartesia uplink gate ms (default 2500 ) set 0 to disable the gate verify test ws connection py prints ack + greeting audio/text connect call logs show cartesia ready … call id=ac … then turn started … role=assistant voice is normal pitch/speed (not slow/deep) call lasts well beyond a few seconds go live checklist bridge on a stable host with real tls for wss\ // api keys only in env / secret store cartesia agent id points at the production line deployment uplink gate tuned for your greeting length monitoring on process health, cartesia disconnect reasons, first audio ms load tested concurrent calls for expected traffic troubleshoot symptom what to check call drops in 4 seconds streamurl path / ?sample rate=8000 ; tunnel; bot accepting wss slow / deep voice confirm exotel is 8 khz and cartesia format is mulaw 8000 (or matching pcm rate) greeting delayed / cut off uplink gate ( cartesia uplink gate ms ); look for false turn started role=user before assistant no agent audio api key, agent id, access token with agent grant, cartesia console / call record ack timeout agent deployment status; cartesia version header; network to api cartesia ai related recipe readme integrations/agents/cartesia line native/readme md cartesia agents websocket api https //docs cartesia ai/line/integrations/websocket api connect voice ai api https //docs exotel com/exotel agentstream/connect voice ai api
