cd /news/developer-tools/build-a-fax-to-json-pipeline-in-pyth… · home topics developer-tools article
[ARTICLE · art-50353] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=↑ positive

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.

read2 min views1 publishedJul 8, 2026

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

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://<id>.ngrok.io/webhooks/fax

The demo keeps state in memory. For production, I would add:

media_url

The example repo is also agent-readable. A coding agent can inspect the README, API reference, guide, environment file, and app code, then help you add OCR, storage, tests, queue workers, or stricter validation.

── more in #developer-tools 4 stories · sorted by recency
── more on @telnyx 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/build-a-fax-to-json-…] indexed:0 read:2min 2026-07-08 ·