{"slug": "extract-structured-json-from-messy-text-with-telnyx-ai-inference", "title": "Extract structured JSON from messy text with Telnyx AI Inference", "summary": "Telnyx launched a new AI Inference feature that extracts structured JSON from unstructured text such as support tickets, emails, leads, and incident reports. The tool uses a Flask API to validate requests and leverages Telnyx's AI models to return structured data, enabling developers to automate data extraction and processing.", "body_md": "| name | extract-structured-json-with-ai | |\n|---|---|---|\n| title | Extract Structured JSON with AI | |\n| description | Extract structured JSON from support tickets, emails, leads, or incident reports with Telnyx AI Inference. | |\n| language | python | |\n| framework | flask | |\n| telnyx_products |\n|\n\nExtract structured JSON from support tickets, emails, leads, or incident reports with Telnyx AI Inference.\n\n**AI Inference**:`POST /v2/ai/chat/completions`\n\n-[API reference](https://developers.telnyx.com/api/inference/chat-completions)\n\n```\n  Unstructured text\n        |\n        v\n  Flask API validates request\n        |\n        v\n  Telnyx AI Inference extracts JSON\n        |\n        v\n  Structured 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[Models](https://developers.telnyx.com/docs/inference/models)`HOST`\n\n`string`\n\n`127.0.0.1`\n\n`PORT`\n\n`integer`\n\n`5000`\n\n```\ngit clone https://github.com/team-telnyx/telnyx-code-examples.git\ncd telnyx-code-examples/extract-structured-json-with-ai-python\ncp .env.example .env\npip install -r requirements.txt\npython app.py\n```\n\nExtract structured data from text. If you do not provide a schema, the app uses a default support-ticket schema.\n\n```\ncurl -X POST http://localhost:5000/extract \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"text\": \"Account: Acme Health. Production verification jobs started failing after an API key rotation. Users cannot finish signup. Logs show 401 errors.\"\n  }'\n```\n\n**Response:**\n\n```\n{\n  \"model\": \"moonshotai/Kimi-K2.6\",\n  \"result\": {\n    \"company\": \"Acme Health\",\n    \"category\": \"authentication\",\n    \"priority\": \"urgent\",\n    \"summary\": \"Production verification jobs are failing after an API key rotation.\",\n    \"affected_environment\": \"production\",\n    \"affected_region\": \"unknown\",\n    \"customer_impact\": \"Users cannot finish signup.\",\n    \"error_codes\": [\"401\"],\n    \"suspected_cause\": \"The new API key may be invalid or missing required permissions.\",\n    \"requested_action\": \"Check API key configuration and permissions.\"\n  }\n}\n```\n\nReturns sample text and the default schema.\n\nReturns service status and configured model.\n\n| Issue | Cause | Fix |\n|---|---|---|\n`401 Unauthorized` |\nInvalid or missing Telnyx API key | Verify `TELNYX_API_KEY` in `.env` |\n`400 Bad Request` |\nMissing `text` or invalid `schema` |\nSend a non-empty `text` string and a JSON object schema |\n`502 Model response was not valid JSON` |\nThe selected model did not return parseable JSON | Retry with the default model or simplify the schema |\n\n[Run LLM Inference (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/run-llm-inference-python/README.md)[Build RAG with Telnyx Inference (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/build-rag-with-telnyx-inference-python/README.md)[Fax to Structured Data Pipeline (Python)](https://raw.githubusercontent.com/team-telnyx/telnyx-code-examples/main/fax-to-structured-data-pipeline-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/extract-structured-json-from-messy-text-with-telnyx-ai-inference", "canonical_source": "https://github.com/team-telnyx/telnyx-code-examples/tree/main/extract-structured-json-with-ai-python", "published_at": "2026-06-25 22:25:51+00:00", "updated_at": "2026-06-25 22:35:34.045635+00:00", "lang": "en", "topics": ["ai-tools", "natural-language-processing", "developer-tools"], "entities": ["Telnyx", "Flask", "Kimi-K2.6", "Acme Health"], "alternates": {"html": "https://wpnews.pro/news/extract-structured-json-from-messy-text-with-telnyx-ai-inference", "markdown": "https://wpnews.pro/news/extract-structured-json-from-messy-text-with-telnyx-ai-inference.md", "text": "https://wpnews.pro/news/extract-structured-json-from-messy-text-with-telnyx-ai-inference.txt", "jsonld": "https://wpnews.pro/news/extract-structured-json-from-messy-text-with-telnyx-ai-inference.jsonld"}}