Build a Fax-to-JSON Pipeline in Python Telnyx released a Python example that builds a fax-to-JSON pipeline using Flask and Telnyx AI Inference. The app receives fax events via webhooks, extracts structured data from document text using an AI model, and returns JSON output. It supports document types like invoices and purchase orders, with optional automatic type inference. Fax is still part of a lot of real business workflows. Healthcare, insurance, logistics, legal, finance, and back-office teams still receive forms, invoices, purchase orders, prescriptions, claims, and signed documents by fax. The problem is what happens after the fax arrives. This Python example shows how to receive a Telnyx fax event and turn document text into structured JSON with Telnyx AI Inference: https://github.com/team-telnyx/telnyx-code-examples/tree/main/fax-to-structured-data-pipeline-python https://github.com/team-telnyx/telnyx-code-examples/tree/main/fax-to-structured-data-pipeline-python The app is a small Flask API with these routes: POST /webhooks/fax receive Telnyx fax events POST /extract extract structured data from document text GET /faxes list queued fax metadata GET /extracted list recent extraction results GET /health health check The extraction route supports: The AI call uses: POST /v2/ai/chat/completions git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/fax-to-structured-data-pipeline-python cp .env.example .env pip install -r requirements.txt python app.py Set these values in .env : TELNYX API KEY=your telnyx api key TELNYX PUBLIC KEY=your telnyx public key AI MODEL=moonshotai/Kimi-K2.6 HOST=127.0.0.1 You do not need to send a live fax to test the extraction path. Send document text directly: curl -X POST http://localhost:5000/extract \ -H "Content-Type: application/json" \ -d '{ "type": "invoice", "text": "Invoice INV-1042 from Acme Medical Supplies dated 2026-07-01. Due 2026-07-31. Bill to North Clinic. Item: Nitrile gloves, quantity 10, unit price 12.50, total 125.00. Item: Face masks, quantity 5, unit price 20.00, total 100.00. Subtotal 225.00. Tax 18.00. Total 243.00. Payment terms Net 30." }' | python3 -m json.tool The app asks the model for invoice-shaped JSON: { "vendor": "Acme Medical Supplies", "invoice number": "INV-1042", "date": "2026-07-01", "due date": "2026-07-31", "line items": { "description": "Nitrile gloves", "quantity": 10, "unit price": 12.5, "total": 125 } , "subtotal": 225, "tax": 18, "total": 243, "payment terms": "Net 30" } Use type: "auto" when you want the model to infer the document type: curl -X POST http://localhost:5000/extract \ -H "Content-Type: application/json" \ -d '{ "type": "auto", "text": "Purchase Order PO-7781. Vendor: Harbor Office Supply. Ship to: 500 Market St, San Francisco, CA. SKU CHAIR-22, ergonomic chair, quantity 12, unit price 199.00. Total 2388.00. Delivery requested 2026-07-20." }' | python3 -m json.tool The live fax route is: POST /webhooks/fax The app verifies the Telnyx webhook signature before trusting the event. When it receives fax.received , it queues metadata like: For local webhook testing, expose your app: ngrok http 5000 Then set your Telnyx Fax Application webhook URL to: https://