{"slug": "keep-outbound-numbers-healthy-with-ai", "title": "Keep Outbound Numbers Healthy with AI", "summary": "A developer built a Python Flask app that monitors Telnyx phone numbers, analyzes reputation risk using Telnyx AI Inference, and recommends whether to keep, rotate, or retire a number. The app scans up to 20 numbers, sends health metrics to an AI model, and logs rotation recommendations without automatically swapping live numbers. It provides a starting point for a real number-health dashboard for outbound workflows.", "body_md": "Subtitle: Build a Python app that monitors Telnyx phone numbers, analyzes reputation risk with Telnyx AI Inference, and recommends when to keep, rotate, or retire a number.\n\nOutbound workflows depend on number health more than most teams want to admit.\n\nA number can look fine in inventory and still perform badly in the real world. Answer rates drop. Complaints increase. Campaign patterns get stale. A number that worked last month might need a cooldown, a review, or a replacement today.\n\nThat is the workflow behind this example:\n\nIt is a small Python Flask app that lists your Telnyx phone numbers, sends number-health context to Telnyx AI Inference, and records a recommendation: keep, rotate, or retire.\n\nThe app exposes three routes:\n\n`POST /scan`\n\nto analyze up to 20 numbers`GET /health-report`\n\nto inspect tracked number health and rotation recommendations`GET /health`\n\nfor app healthIt uses two Telnyx APIs:\n\n```\nGET /v2/phone_numbers\nPOST /v2/ai/chat/completions\n```\n\nThe current default model is set in `.env.example`\n\n:\n\n```\nAI_MODEL=MiniMaxAI/MiniMax-M3-MXFP8\n```\n\nThe pattern is simple: pull number inventory, attach health metrics, ask the model for a constrained recommendation, and store the result.\n\nYou start the scan like this:\n\n```\ncurl -X POST http://localhost:5000/scan \\\n  -H \"Content-Type: application/json\" \\\n  -d '{}'\n```\n\nThe app calls Telnyx to list phone numbers, then analyzes up to the first 20 numbers.\n\nFor each number, it builds a small health payload. In the sample, the default metrics are intentionally simple:\n\n```\n{\n  \"calls\": 0,\n  \"complaints\": 0,\n  \"answer_rate\": 0.5,\n  \"number\": \"+12125551234\"\n}\n```\n\nThen the app asks the model to return JSON like this:\n\n```\n{\n  \"risk_level\": \"warning\",\n  \"recommendation\": \"rotate\",\n  \"reasoning\": \"Answer rate is low and complaint activity is elevated\"\n}\n```\n\nIf the recommendation is `rotate`\n\n, the app records it in a rotation log.\n\nThat is important: this sample does not automatically swap live numbers. It logs the recommendation. In a real outbound system, rotation should usually include policy checks, campaign state, routing rules, and human approval.\n\nNumber reputation is not a single flag.\n\nIt is usually a collection of signals:\n\nA model is useful here when it is not asked to invent a decision from nothing. It is useful when it gets structured operational context and returns a constrained recommendation.\n\nThat makes the output easier to route into a dashboard, review queue, or outbound routing system.\n\nAfter a scan, you can inspect current state:\n\n```\ncurl http://localhost:5000/health-report\n```\n\nThe response includes tracked numbers and recent rotation recommendations:\n\n```\n{\n  \"numbers\": {\n    \"+12125551234\": {\n      \"calls\": 0,\n      \"complaints\": 0,\n      \"answer_rate\": 0.5,\n      \"analysis\": {\n        \"risk_level\": \"warning\",\n        \"recommendation\": \"rotate\",\n        \"reasoning\": \"Example reason\"\n      }\n    }\n  },\n  \"rotations\": []\n}\n```\n\nThat structure gives you a starting point for a real number-health dashboard.\n\nThe prompt asks the model to return only JSON, with no prose and no markdown fences.\n\nThe app still includes a helper to strip markdown fences and parse the JSON object. I like that pattern because AI app code should be defensive. Prompts help, but validation is what keeps the output usable as application state.\n\nFor production, I would add:\n\nThe repo is also structured to be agent-readable. Your coding agent can inspect the README, API reference, guide, environment file, and app code, then help extend it. You can ask it to add scheduled scans, persistent metrics, tests, dashboards, or real routing integration.\n\nTelnyx AI skills and toolkits:\n\n[https://github.com/team-telnyx/ai](https://github.com/team-telnyx/ai)\n\nList Phone Numbers API:\n\n[https://developers.telnyx.com/api/numbers/list-phone-numbers](https://developers.telnyx.com/api/numbers/list-phone-numbers)\n\nTelnyx AI Inference docs:\n\n[https://developers.telnyx.com/docs/inference](https://developers.telnyx.com/docs/inference)\n\nChat Completions API:\n\n[https://developers.telnyx.com/api/inference/chat-completions](https://developers.telnyx.com/api/inference/chat-completions)\n\nTelnyx Portal:\n\n[https://portal.telnyx.com/](https://portal.telnyx.com/)", "url": "https://wpnews.pro/news/keep-outbound-numbers-healthy-with-ai", "canonical_source": "https://dev.to/sonam_50a41a4ced7e6b4f3fa/keep-outbound-numbers-healthy-with-ai-1i62", "published_at": "2026-06-30 23:52:18+00:00", "updated_at": "2026-07-01 00:18:44.086028+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools", "ai-products"], "entities": ["Telnyx", "Telnyx AI Inference", "Python", "Flask", "MiniMaxAI/MiniMax-M3-MXFP8"], "alternates": {"html": "https://wpnews.pro/news/keep-outbound-numbers-healthy-with-ai", "markdown": "https://wpnews.pro/news/keep-outbound-numbers-healthy-with-ai.md", "text": "https://wpnews.pro/news/keep-outbound-numbers-healthy-with-ai.txt", "jsonld": "https://wpnews.pro/news/keep-outbound-numbers-healthy-with-ai.jsonld"}}