$npx -y skills add team-telnyx/ai --skill telnyx-ai-inference-rubyAccess Telnyx LLM inference APIs, embeddings, and AI analytics for call insights and summaries. This skill provides Ruby SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Ai Inference - Ruby |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | gem install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```ruby |
| 14 | require "telnyx" |
| 15 | |
| 16 | client = Telnyx::Client.new( |
| 17 | api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted |
| 18 | ) |
| 19 | ``` |
| 20 | |
| 21 | All examples below assume `client` is already initialized as shown above. |
| 22 | |
| 23 | ## Error Handling |
| 24 | |
| 25 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 26 | or authentication errors (401). Always handle errors in production code: |
| 27 | |
| 28 | ```ruby |
| 29 | begin |
| 30 | result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello") |
| 31 | rescue Telnyx::Errors::APIConnectionError |
| 32 | puts "Network error — check connectivity and retry" |
| 33 | rescue Telnyx::Errors::RateLimitError |
| 34 | # 429: rate limited — wait and retry with exponential backoff |
| 35 | sleep(1) # Check Retry-After header for actual delay |
| 36 | rescue Telnyx::Errors::APIStatusError => e |
| 37 | puts "API error #{e.status}: #{e.message}" |
| 38 | if e.status == 422 |
| 39 | puts "Validation error — check required fields and formats" |
| 40 | end |
| 41 | end |
| 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:** Use `.auto_paging_each` for automatic iteration: `page.auto_paging_each { |item| puts item.id }`. |
| 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 | ```ruby |
| 59 | response = client.ai.audio.transcribe(model: :"distil-whisper/distil-large-v2") |
| 60 | |
| 61 | puts(response) |
| 62 | ``` |
| 63 | |
| 64 | Returns: `duration` (number), `segments` (array[object]), `text` (string) |
| 65 | |
| 66 | ## Create a chat completion |
| 67 | |
| 68 | 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. |
| 69 | |
| 70 | `POST /ai/chat/completions` — Required: `messages` |
| 71 | |
| 72 | 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) |
| 73 | |
| 74 | ```ruby |
| 75 | response = client.ai.chat.create_completion( |
| 76 | messages: [{content: "You are a friendly chatbot.", role: :system}, {content: "Hello, world!", role: :user}] |
| 77 | ) |
| 78 | |
| 79 | puts(response) |
| 80 | ``` |
| 81 | |
| 82 | ## List conversations |
| 83 | |
| 84 | 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. |
| 85 | |
| 86 | `GET /ai/conversations` |
| 87 | |
| 88 | ```ruby |
| 89 | conversations = client.ai.conversations.list |
| 90 | |
| 91 | puts(conversations) |
| 92 | ``` |
| 93 | |
| 94 | Returns: `created_at` (date-time), `id` (uuid), `last_message_at` (date-time), `metadata` (object), `name` (string) |
| 95 | |
| 96 | ## Create a conversation |
| 97 | |
| 98 | Create a new AI Conversation. |
| 99 | |
| 100 | `POST /ai/conversations` |
| 101 | |
| 102 | Optional: `metadata` (object), `name` (string) |
| 103 | |
| 104 | ```ruby |
| 105 | conversation = client.ai.conversations.create |
| 106 | |
| 107 | puts(conversation) |
| 108 | ``` |
| 109 | |
| 110 | Returns: `created_at` (date-time), `id` (uuid), `last_message_at` (date-time), `metadata` (object), `name` (string) |
| 111 | |
| 112 | ## Get Insight Template Groups |
| 113 | |
| 114 | Get all insight groups |
| 115 | |
| 116 | `GET /ai/conversations/insight-groups` |
| 117 | |
| 118 | ```ruby |
| 119 | page = client.ai.conversations.insight_groups.retrieve_insight_groups |
| 120 | |
| 121 | puts(page) |
| 122 | ``` |
| 123 | |
| 124 | Returns: `created_at` (date-time), `description` (string), `id` (uuid), `insights` (array[object]), `name` (string), `webhook` (string) |
| 125 | |
| 126 | ## Create Insight Template Group |
| 127 | |
| 128 | Create a new insight group |
| 129 | |
| 130 | `POST /ai/conversations/insight-groups` — Required: `name` |
| 131 | |
| 132 | Optional: `description` (string), `webhook` (string) |
| 133 | |
| 134 | ```ruby |
| 135 | insight_template_group_detail = client.ai.conversations.insight_groups.insight_groups(name: "my-resource") |
| 136 | |
| 137 | puts(insight_template_group_detail) |
| 138 | ``` |
| 139 | |
| 140 | Returns: `created_at` (date-time), `description` (string), `id` (uuid), `insights` (array[object]), `name` (string), `webhook` (string) |
| 141 | |
| 142 | ## Get Insight Template Group |
| 143 | |
| 144 | Get insight group by ID |
| 145 | |
| 146 | `GET /ai/ |