Pre-visit insurance clearance is one of those workflows that sounds simple until you see how many phone calls it creates.
A patient calls before an appointment. They need to know whether a procedure, test, or medication requires prior authorization. Staff need to identify the patient, understand what they are asking for, collect payer and provider context, decide how urgent it is, and route the request to the right billing queue.
I built a Telnyx code example that turns that call into a structured intake ticket.
The code example:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-pre-visit-clearance-voice-agent-python
The Flow
A patient calls a Telnyx number. Telnyx sends the inbound call event to a Flask webhook. The app answers with Call Control, then starts gather_using_ai to collect the patient's spoken pre-clearance request as structured fields.
When Telnyx finishes collecting those fields, the app receives call.ai_gather.ended. From there, the app classifies the request with AI Inference, confirms the details with the patient, creates a staff-facing ticket, sends the patient an SMS confirmation, and optionally alerts billing staff in Slack.
The agent is non-clinical. It doesn't give medical advice, approve or deny coverage, or diagnose. It collects administrative data and routes it — which is the bottleneck in a lot of healthcare revenue-cycle work.
Why This Pattern Matters
The main Telnyx primitive here is Gather Using AI.
The app asks Telnyx to gather the fields it needs directly inside the call. The webhook response gives the backend something structured enough to use in a workflow.
That makes the rest of the app cleaner:
- Call Control handles the inbound call lifecycle
- Gather Using AI collects the spoken intake details
-
call.ai_gather.endedadvances the workflow - AI Inference classifies urgency and type
- Messaging sends the patient a confirmation
- Slack gives billing staff a queue signal
The implementation patterns it covers:
- DOB fallback when caller ID is unknown
-
command_idon Call Control commands -
send_silence_when_idlewhen answering - structured JSON classification for procedure, urgency, and request type
- keyword-based urgency override for phrases like "ASAP" or "can't wait"
- confirmation before ticket creation
- partial ticket creation if the caller hangs up after providing useful context
Run It Locally
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/ai-pre-visit-clearance-voice-agent-python
cp .env.example .env
pip install -r requirements.txt
python app.py
ngrok http 5000
Point your Telnyx Call Control Application webhook to:
https://<your-ngrok-domain>/webhooks/voice
Seed a patient:
curl -X POST http://localhost:5000/patients \
-H "Content-Type: application/json" \
-d '{"patient_id":"P001","name":"Jordan Lee","phone":"+15551112233","dob":"03/15/1990","insurance":"Blue Cross","provider":"Dr. Smith"}'
Call the number and say:
I need clearance for an MRI on my lower back.
The app collects the request, classifies it, confirms the details, creates a ticket, and sends an SMS confirmation.
Where To Take It Next
Replace in-memory storage with your EHR, PMS, or billing system integration. Wire ticket completion into real prior auth submission APIs. Add privacy review and HIPAA-ready operational controls before production use. Queue Slack and SMS side effects so webhook responses stay fast.
The key boundary should stay the same: the agent collects and routes. Staff and payer systems make the actual coverage decisions.
Resources
- Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-pre-visit-clearance-voice-agent-python
- Gather Using AI: https://developers.telnyx.com/api-reference/call-commands/gather-using-ai
-
call.ai_gather.ended: https://developers.telnyx.com/api-reference/callbacks/call-ai-gather-ended - Voice API commands: https://developers.telnyx.com/docs/voice/programmable-voice/voice-api-commands-and-resources
- AI Inference docs: https://developers.telnyx.com/docs/inference
- Messaging docs: https://developers.telnyx.com/docs/messaging
- Telnyx Portal: https://portal.telnyx.com
Top comments (0)