Extract structured JSON from messy text with Telnyx AI Inference 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. | name | extract-structured-json-with-ai | | |---|---|---| | title | Extract Structured JSON with AI | | | description | Extract structured JSON from support tickets, emails, leads, or incident reports with Telnyx AI Inference. | | | language | python | | | framework | flask | | | telnyx products | | Extract structured JSON from support tickets, emails, leads, or incident reports with Telnyx AI Inference. AI Inference : POST /v2/ai/chat/completions - API reference https://developers.telnyx.com/api/inference/chat-completions Unstructured text | v Flask API validates request | v Telnyx AI Inference extracts JSON | v Structured JSON response 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 | | AI MODEL string moonshotai/Kimi-K2.6 Models https://developers.telnyx.com/docs/inference/models HOST string 127.0.0.1 PORT integer 5000 git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/extract-structured-json-with-ai-python cp .env.example .env pip install -r requirements.txt python app.py Extract structured data from text. If you do not provide a schema, the app uses a default support-ticket schema. curl -X POST http://localhost:5000/extract \ -H "Content-Type: application/json" \ -d '{ "text": "Account: Acme Health. Production verification jobs started failing after an API key rotation. Users cannot finish signup. Logs show 401 errors." }' Response: { "model": "moonshotai/Kimi-K2.6", "result": { "company": "Acme Health", "category": "authentication", "priority": "urgent", "summary": "Production verification jobs are failing after an API key rotation.", "affected environment": "production", "affected region": "unknown", "customer impact": "Users cannot finish signup.", "error codes": "401" , "suspected cause": "The new API key may be invalid or missing required permissions.", "requested action": "Check API key configuration and permissions." } } Returns sample text and the default schema. Returns service status and configured model. | Issue | Cause | Fix | |---|---|---| 401 Unauthorized | Invalid or missing Telnyx API key | Verify TELNYX API KEY in .env | 400 Bad Request | Missing text or invalid schema | Send a non-empty text string and a JSON object schema | 502 Model response was not valid JSON | The selected model did not return parseable JSON | Retry with the default model or simplify the schema | 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 Telnyx is an AI Communications Infrastructure platform - voice, messaging, SIP, AI, and IoT on one private, global network.