Retell's custom LLM is not a base_url swap: Retell connects out to your
WebSocket (wss://…/llm/<secret>/<call_id>) and speaks its own protocol
(response_required in → response chunks out). This recipe is that server —
a ~150-line adapter that turns each Retell turn into a streaming Floe
gateway call, which puts the model leg under Floe governance:
- every token metered on your one
floe_key, - pre-call gated — the turn that would start past the session cap is
refused
402before any tokens are bought, - graceful ending — on
402the adapter speaks "I've reached my budget limit for this call" and setsend_call: true(Retell hangs up cleanly), X-Floe-Budget-Advisoryavailable per turn for tapering to a cheaper slug.
Retell (STT ⇄ TTS ⇄ telephony)
└── custom-llm ──wss──► server.ts ──SSE──► Floe /v1/chat/completions
response_required │ adapter metered • gated • ledgered
response chunks ◄────┘
cp .env.example .env # RETELL_API_KEY, FLOE_API_KEY, secrets, model
npm install
npm start # the adapter (expose: ngrok http 3112 → wss URL)
npm run setup # sets the Floe cap, creates the Retell agentAttach the created agent to a Retell number and call it.
- Socket auth: Retell documents no auth header for the custom-LLM socket —
the unguessable path secret is the auth. Keep
LLM_PATH_SECRETlong. To rotate it, redeploy with the new secret and update the agent'sllm_websocket_url(or recreate the agent withnpm run setup) — the URL written at setup time carries the old secret, so a redeploy alone locks the existing agent out. - Turn racing: Retell can supersede a turn (
reminder_required, barge-in). The adapter tracks the latestresponse_idand abandons stale streams. - The other legs (STT/TTS/telephony) stay on Retell — govern them with
Reconcile Mode:
POST /v1/developer/orchestrators(providerretell, secret = your Retell API key, which Retell signs webhooks with), then point the agent's webhook at the returnedcall-endURL and the phone number's inbound webhook at thepre-callURL — an over-budget agent's next inbound call is rejected before it connects. - Spend proof:
GET /v1/agents/transactionson your Floe key.