{"slug": "predict-churn-before-customers-leave", "title": "Predict churn before customers leave", "summary": "Telnyx released an AI Customer Churn Predictor that uses its AI Inference API to analyze call and message patterns via Telnyx APIs, predicting churn risk and suggesting interventions. The open-source Python tool, built with Flask, allows developers to deploy a churn prediction service that triggers predictions and returns results via REST endpoints.", "body_md": "| name | ai-customer-churn-predictor | |\n|---|---|---|\n| title | AI Customer Churn Predictor | |\n| description | AI Customer Churn Predictor - analyze call/message patterns via Telnyx APIs, AI predicts churn risk and suggests interventions. | |\n| language | python | |\n| framework | flask | |\n| telnyx_products |\n|\n\nAI Customer Churn Predictor - analyze call/message patterns via Telnyx APIs, AI predicts churn risk and suggests interventions.\n\n**AI Inference**:`POST /v2/ai/chat/completions`\n\n-[API reference](https://developers.telnyx.com/api/inference/chat-completions)\n\n```\n  API Request\n        │\n        ▼\n  ┌──────────────────┐\n  │ Your App          │\n  └────────┬─────────┘\n           │\n           ├──► Telnyx AI Inference\n           │\n           ├──► Classification / triage\n           │\n           ▼\n     JSON response\n```\n\nCopy `.env.example`\n\nto `.env`\n\nand fill in:\n\n| Variable | Type | Example | Required | Description | Where to get it |\n|---|---|---|---|---|---|\n`TELNYX_API_KEY` |\n`string` |\n`KEY0123456789ABCDEF` |\nyes |\nTelnyx API v2 key |\n|\n\n`AI_MODEL`\n\n`string`\n\n`moonshotai/Kimi-K2.6`\n\n[Portal](https://developers.telnyx.com/docs/inference/models)`PORT`\n\n`integer`\n\n`5000`\n\n```\ngit clone https://github.com/team-telnyx/telnyx-code-examples.git\ncd telnyx-code-examples/ai-customer-churn-predictor-python\ncp .env.example .env    # ← fill in your credentials\npip install -r requirements.txt\npython app.py           # starts on http://localhost:5000\n```\n\nTriggers predict\n\n```\ncurl -X POST http://localhost:5000/predict \\\n  -H \"Content-Type: application/json\" \\\n  -d '{}'\n```\n\n**Response:**\n\n```\n{\n  \"id\": \"item-1750280400\",\n  \"status\": \"created\",\n  \"created_at\": \"2026-07-15T14:30:00Z\"\n}\n```\n\nTriggers batch\n\n```\ncurl -X POST http://localhost:5000/predict/batch \\\n  -H \"Content-Type: application/json\" \\\n  -d '{}'\n```\n\n**Response:**\n\n```\n{\n  \"id\": \"item-1750280400\",\n  \"status\": \"created\",\n  \"created_at\": \"2026-07-15T14:30:00Z\"\n}\n```\n\nReturns predictions\n\n```\ncurl http://localhost:5000/predictions\n```\n\n**Response:**\n\n```\n{\n  \"items\": [\n    {\n      \"id\": \"item-001\",\n      \"status\": \"active\",\n      \"created_at\": \"2026-07-15T14:30:00Z\"\n    }\n  ]\n}\n```\n\nReturns health\n\n```\ncurl http://localhost:5000/health\n```\n\n**Response:**\n\n```\n{\n  \"status\": \"ok\",\n  \"uptime_seconds\": 3842,\n  \"active_sessions\": 2,\n  \"version\": \"1.0.0\"\n}\n```\n\n| Issue | Cause | Fix |\n|---|---|---|\n`401 Unauthorized` |\nInvalid or missing API key | Verify `TELNYX_API_KEY` in `.env` matches your key in the\n|\n| Webhook not received | Local server not publicly reachable | Expose it with a tunnel (e.g. ngrok) and set the webhook URL in the\n|\n\n`422 Unprocessable Entity`\n\n[AI After Hours Emergency Triage (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-after-hours-emergency-triage-python/README.md)[AI Assistant Knowledge Base (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-assistant-knowledge-base-python/README.md)[AI Assistant Multi Tool (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-assistant-multi-tool-python/README.md)[AI Assistant Phone Setup (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-assistant-phone-setup-python/README.md)[AI Audiobook Narrator (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/ai-audiobook-narrator-python/README.md)\n\nTelnyx is an **AI Communications Infrastructure** platform - voice, messaging, SIP, AI, and IoT on one private, global network.", "url": "https://wpnews.pro/news/predict-churn-before-customers-leave", "canonical_source": "https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-customer-churn-predictor-python", "published_at": "2026-06-29 22:06:59+00:00", "updated_at": "2026-06-29 22:20:32.845377+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-products", "ai-tools", "ai-infrastructure", "machine-learning"], "entities": ["Telnyx", "AI Customer Churn Predictor", "Telnyx AI Inference", "Flask", "Python", "Kimi-K2.6"], "alternates": {"html": "https://wpnews.pro/news/predict-churn-before-customers-leave", "markdown": "https://wpnews.pro/news/predict-churn-before-customers-leave.md", "text": "https://wpnews.pro/news/predict-churn-before-customers-leave.txt", "jsonld": "https://wpnews.pro/news/predict-churn-before-customers-leave.jsonld"}}