AI News HubLIVE
In-site rewrite2 min read

Predict churn before customers leave

Analyze, classify, summarize, and translate this AI news article. Root object must contain exactly one key: "translations". Do not include root keys named topics, tags, importanceScore, title, summary, key_points, generateBody, or locales. translations must contain exactly "zh-CN", "en", and "ja". Each translation must contain exactly title, summary, keyPoints, and body. The application derives topics, tags, importanceScore, whyItMatters, technicalImpact, audience, difficulty, zh-TW, and zh-HK after parsing. Do not include those fields in the JSON. summary should be concise and useful, with no fixed character limit. keyPoints should be an array of two to four concise strings. When input.generateBody is true and input.body is present, body must be a rewritten article in the target locale, generated in your own words from the source text. If input.originalLanguage is en, en.body must be null because the application uses input.body directly for English. If input.originalLanguage is ja, ja.body must be null because the application uses input.body directly for Japanese. If input.originalLanguage is zh-CN, zh-CN.body must be null because the application uses input.body directly for Simplified Chinese and derives Traditional Chinese with OpenCC. body must read as a complete in-site article, not a short summary. Preserve all substantive facts, context, caveats, and timeline details from input.body. For source text of 1,500+ characters, body must be a substantial multi-paragraph article, not a compressed digest. Use multiple coherent paragraphs for body when the source contains enough material. Do not copy source paragraphs verbatim into body. If input.generateBody is false or input.body is empty, body must be null for every locale. Required JSON shape example: { "translations": { "zh-CN": { "title": "简体中文标题", "summary": "简体中文摘要。", "keyPoints": [ "简体中文要点" ], "body": null }, "en": { "title": "English title", "summary": "English summary.", "keyPoints": [ "English key point" ], "body": null }, "ja": { "title": "日本語タイトル", "summary": "日本語の要約。", "keyPoints": [ "日本語の要点" ], "body": null } } } Input article: { "title": "Predict churn before customers leave", "excerpt": null, "body": "Uh oh!\n\nThere was an error while loading. Please reload this page.\n\nNotifications\nYou must be signed in to change notification settings\n\nFork\n3\n\nStar\n143\n\nCopy path\n\nMore options\n\nMore options\n\nMore options\n\nMore options\n\nLatest commit\n\n \n\nHistory\n\nHistory\n\nHistory\n\nCopy path\n\nFolders and files\n\nNameName\n\nLast commit message\n\nLast commit date\n\nparent directory\n\n..\n\n.env.example\n\n.env.example\n\n \n\n \n\nAPI.md\n\nAPI.md\n\n \n\n \n\nGUIDE.md\n\nGUIDE.md\n\n \n\n \n\nREADME.md\n\nREADME.md\n\n \n\n \n\napp.py\n\napp.py\n\n \n\n \n\nrequirements.txt\n\nrequirements.txt\n\n \n\n \n\nAI Customer Churn Predictor\n\nAI Customer Churn Predictor - analyze call/message patterns via Telnyx APIs, AI predicts churn risk and suggests interventions.\n\nTelnyx API Endpoints Used\n\nAI Inference: POST /v2/ai/chat/completions - API reference\n\nArchitecture\n\nAPI Request\n│\n▼\n┌──────────────────┐\n│ Your App │\n└────────┬─────────┘\n│\n├──► Telnyx AI Inference\n│\n├──► Classification / triage\n│\n▼\nJSON response\n\nEnvironment Variables\n\nCopy .env.example to .env and fill in:\n\nVariable\nType\nExample\nRequired\nDescription\nWhere to get it\n\nTELNYX_API_KEY\nstring\nKEY0123456789ABCDEF\nyes\nTelnyx API v2 key\nPortal\n\nAI_MODEL\nstring\nmoonshotai/Kimi-K2.6\nno\nTelnyx AI Inference model name\nPortal\n\nPORT\ninteger\n5000\nno\nHTTP server port\n-\n\nSetup\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\nAPI Reference\n\nPOST /predict\n\nTriggers predict\n\ncurl -X POST http://localhost:5000/predict \\n-H "Content-Type: application/json" \\n-d '{}'\n\nResponse:\n\n{\n"id": "item-1750280400",\n"status": "created",\n"created_at": "2026-07-15T14:30:00Z"\n}\n\nPOST /predict/batch\n\nTriggers batch\n\ncurl -X POST http://localhost:5000/predict/batch \\n-H "Content-Type: application/json" \\n-d '{}'\n\nResponse:\n\n{\n"id": "item-1750280400",\n"status": "created",\n"created_at": "2026-07-15T14:30:00Z"\n}\n\nGET /predictions\n\nReturns predictions\n\ncurl http://localhost:5000/predictions\n\nResponse:\n\n{\n"items": [\n{\n"id": "item-001",\n"status": "active",\n"created_at": "2026-07-15T14:30:00Z"\n}\n]\n}\n\nGET /health\n\nReturns health\n\ncurl http://localhost:5000/health\n\nResponse:\n\n{\n"status": "ok",\n"uptime_seconds": 3842,\n"active_sessions": 2,\n"version": "1.0.0"\n}\n\nTroubleshooting\n\nIssue\nCause\nFix\n\n401 Unauthorized\nInvalid or missing API key\nVerify TELNYX_API_KEY in .env matches your key in the Portal\n\nWebhook not received\nLocal server not publicly reachable\nExpose it with a tunnel (e.g. ngrok) and set the webhook URL in the Telnyx Portal\n\n422 Unprocessable Entity\nMissing or malformed request fields\nCheck the request body against the API Reference above\n\nRelated Examples\n\nAI After Hours Emergency Triage (Python)\n\nAI Assistant Knowledge Base (Python)\n\nAI Assistant Multi Tool (Python)\n\nAI Assistant Phone Setup (Python)\n\nAI Audiobook Narrator (Python)\n\nResources\n\nAI Inference Guide\n\nTelnyx Developer Docs\n\nTelnyx Portal\n\nWhy Telnyx\n\nTelnyx is an AI Communications Infrastructure platform - voice, messaging, SIP, AI, and IoT on one private, global network.", "generateBody": true, "sourceId": "hacker-news-ai", "canonicalUrl": "https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-customer-churn-predictor-python", "originalLanguage": "en" }

SourceHacker News AIAuthor: sona-coffee11

Uh oh!

There was an error while loading. Please reload this page.

Notifications You must be signed in to change notification settings

Fork 3

Star 143

Copy path

More options

More options

More options

More options

Latest commit

History

History

History

Copy path

Folders and files

NameName

Last commit message

Last commit date

parent directory

..

.env.example

.env.example

API.md

API.md

GUIDE.md

GUIDE.md

README.md

README.md

app.py

app.py

requirements.txt

requirements.txt

AI Customer Churn Predictor

AI Customer Churn Predictor - analyze call/message patterns via Telnyx APIs, AI predicts churn risk and suggests interventions.

Telnyx API Endpoints Used

AI Inference: POST /v2/ai/chat/completions - API reference

Architecture

API Request │ ▼ ┌──────────────────┐ │ Your App │ └────────┬─────────┘ │ ├──► Telnyx AI Inference │ ├──► Classification / triage │ ▼ JSON response

Environment Variables

Copy .env.example to .env and fill in:

Variable Type Example Required Description Where to get it

TELNYX_API_KEY string KEY0123456789ABCDEF yes Telnyx API v2 key Portal

AI_MODEL string moonshotai/Kimi-K2.6 no Telnyx AI Inference model name Portal

PORT integer 5000 no HTTP server port -

Setup

git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/ai-customer-churn-predictor-python cp .env.example .env # ← fill in your credentials pip install -r requirements.txt python app.py # starts on http://localhost:5000

API Reference

POST /predict

Triggers predict

curl -X POST http://localhost:5000/predict \ -H "Content-Type: application/json" \ -d '{}'

Response:

{ "id": "item-1750280400", "status": "created", "created_at": "2026-07-15T14:30:00Z" }

POST /predict/batch

Triggers batch

curl -X POST http://localhost:5000/predict/batch \ -H "Content-Type: application/json" \ -d '{}'

Response:

{ "id": "item-1750280400", "status": "created", "created_at": "2026-07-15T14:30:00Z" }

GET /predictions

Returns predictions

curl http://localhost:5000/predictions

Response:

{ "items": [ { "id": "item-001", "status": "active", "created_at": "2026-07-15T14:30:00Z" } ] }

GET /health

Returns health

curl http://localhost:5000/health

Response:

{ "status": "ok", "uptime_seconds": 3842, "active_sessions": 2, "version": "1.0.0" }

Troubleshooting

Issue Cause Fix

401 Unauthorized Invalid or missing API key Verify TELNYX_API_KEY in .env matches your key in the Portal

Webhook not received Local server not publicly reachable Expose it with a tunnel (e.g. ngrok) and set the webhook URL in the Telnyx Portal

422 Unprocessable Entity Missing or malformed request fields Check the request body against the API Reference above

Related Examples

AI After Hours Emergency Triage (Python)

AI Assistant Knowledge Base (Python)

AI Assistant Multi Tool (Python)

AI Assistant Phone Setup (Python)

AI Audiobook Narrator (Python)

Resources

AI Inference Guide

Telnyx Developer Docs

Telnyx Portal

Why Telnyx

Telnyx is an AI Communications Infrastructure platform - voice, messaging, SIP, AI, and IoT on one private, global network.