$npx -y skills add team-telnyx/ai --skill telnyx-ai-inference-curlAccess Telnyx LLM inference APIs, embeddings, and AI analytics for call insights and summaries. This skill provides REST API (curl) examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Ai Inference - curl |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```text |
| 8 | # curl is pre-installed on macOS, Linux, and Windows 10+ |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```bash |
| 14 | export TELNYX_API_KEY="YOUR_API_KEY_HERE" |
| 15 | ``` |
| 16 | |
| 17 | All examples below use `$TELNYX_API_KEY` for authentication. |
| 18 | |
| 19 | ## Error Handling |
| 20 | |
| 21 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 22 | or authentication errors (401). Always handle errors in production code: |
| 23 | |
| 24 | ```bash |
| 25 | # Check HTTP status code in response |
| 26 | response=$(curl -s -w "\n%{http_code}" \ |
| 27 | -X POST "https://api.telnyx.com/v2/messages" \ |
| 28 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 29 | -H "Content-Type: application/json" \ |
| 30 | -d '{"to": "+13125550001", "from": "+13125550002", "text": "Hello"}') |
| 31 | |
| 32 | http_code=$(echo "$response" | tail -1) |
| 33 | body=$(echo "$response" | sed '$d') |
| 34 | |
| 35 | case $http_code in |
| 36 | 2*) echo "Success: $body" ;; |
| 37 | 422) echo "Validation error — check required fields and formats" ;; |
| 38 | 429) echo "Rate limited — retry after delay"; sleep 1 ;; |
| 39 | 401) echo "Authentication failed — check TELNYX_API_KEY" ;; |
| 40 | *) echo "Error $http_code: $body" ;; |
| 41 | esac |
| 42 | ``` |
| 43 | |
| 44 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 45 | `404` resource not found, `422` validation error (check field formats), |
| 46 | `429` rate limited (retry with exponential backoff). |
| 47 | |
| 48 | ## Important Notes |
| 49 | |
| 50 | - **Pagination:** List endpoints return paginated results. Use `page[number]` and `page[size]` query parameters to navigate pages. Check `meta.total_pages` in the response. |
| 51 | |
| 52 | ## Transcribe speech to text |
| 53 | |
| 54 | Transcribe speech to text. This endpoint is consistent with the [OpenAI Transcription API](https://platform.openai.com/docs/api-reference/audio/createTranscription) and may be used with the OpenAI JS or Python SDK. |
| 55 | |
| 56 | `POST /ai/audio/transcriptions` |
| 57 | |
| 58 | ```bash |
| 59 | curl \ |
| 60 | -X POST \ |
| 61 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 62 | -F "file=@/path/to/file" \ |
| 63 | -F "file_url=https://example.com/file.mp3" \ |
| 64 | -F "model=distil-whisper/distil-large-v2" \ |
| 65 | -F "response_format=json" \ |
| 66 | -F "timestamp_granularities[]=segment" \ |
| 67 | -F "language=en-US" \ |
| 68 | -F "model_config={'smart_format': True, 'punctuate': True}" \ |
| 69 | "https://api.telnyx.com/v2/ai/audio/transcriptions" |
| 70 | ``` |
| 71 | |
| 72 | Returns: `duration` (number), `segments` (array[object]), `text` (string) |
| 73 | |
| 74 | ## Create a chat completion |
| 75 | |
| 76 | Chat with a language model. This endpoint is consistent with the [OpenAI Chat Completions API](https://platform.openai.com/docs/api-reference/chat) and may be used with the OpenAI JS or Python SDK. |
| 77 | |
| 78 | `POST /ai/chat/completions` — Required: `messages` |
| 79 | |
| 80 | Optional: `api_key_ref` (string), `best_of` (integer), `early_stopping` (boolean), `enable_thinking` (boolean), `frequency_penalty` (number), `guided_choice` (array[string]), `guided_json` (object), `guided_regex` (string), `length_penalty` (number), `logprobs` (boolean), `max_tokens` (integer), `min_p` (number), `model` (string), `n` (number), `presence_penalty` (number), `response_format` (object), `stream` (boolean), `temperature` (number), `tool_choice` (enum: none, auto, required), `tools` (array[object]), `top_logprobs` (integer), `top_p` (number), `use_beam_search` (boolean) |
| 81 | |
| 82 | ```bash |
| 83 | curl \ |
| 84 | -X POST \ |
| 85 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 86 | -H "Content-Type: application/json" \ |
| 87 | -d '{ |
| 88 | "messages": [ |
| 89 | { |
| 90 | "role": "system", |
| 91 | "content": "You are a friendly chatbot." |
| 92 | }, |
| 93 | { |
| 94 | "role": "user", |
| 95 | "content": "Hello, world!" |
| 96 | } |
| 97 | ] |
| 98 | }' \ |
| 99 | "https://api.telnyx.com/v2/ai/chat/completions" |
| 100 | ``` |
| 101 | |
| 102 | ## List conversations |
| 103 | |
| 104 | Retrieve a list of all AI conversations configured by the user. Supports [PostgREST-style query parameters](https://postgrest.org/en/stable/api.html#horizontal-filtering-rows) for filtering. Examples are included for the standard metadata fields, but you can filter on any field in the metadata JSON object. |
| 105 | |
| 106 | `GET /ai/conversations` |
| 107 | |
| 108 | ```bash |
| 109 | curl -H "Authorization: Bearer $TELNYX_API_KEY" "https://api.telnyx.com/v2/ai/conversations" |
| 110 | ``` |
| 111 | |
| 112 | Returns: `created_at` (date-time), `id` (uuid), `last_message_at` (date-time), `metadata` (object), `name` (string) |
| 113 | |
| 114 | ## Create a conversation |
| 115 | |
| 116 | Create a new AI Conversation. |
| 117 | |
| 118 | `POST /ai/conversations` |
| 119 | |
| 120 | Optional: `metadata` (object), `name` (string) |
| 121 | |
| 122 | ```bash |
| 123 | curl \ |
| 124 | -X POST \ |
| 125 | -H "Authorization: Bearer $TELNYX_API_KEY" \ |
| 126 | -H "Content-Type: application/json" \ |
| 127 | "https://api.telnyx.com/v2/ai/conversations" |
| 128 | ``` |
| 129 | |
| 130 | Returns: `created_at` (date-time), `id` (uuid), `last_message_at` (date-time), `metadata` (object), `name` (string) |
| 131 | |
| 132 | ## Get Insight Template Groups |
| 133 | |
| 134 | Get all insight groups |
| 135 | |
| 136 | `GET /ai/conversations/insight-groups` |
| 137 | |
| 138 | ```bash |
| 139 | curl -H "Authorization: Bearer $TELNYX_API_KEY |