$npx -y skills add team-telnyx/ai --skill telnyx-ai-assistants-pythonAI voice assistants with custom instructions, knowledge bases, and tool integrations.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx AI Assistants - Python |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | pip install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```python |
| 14 | import os |
| 15 | from telnyx import Telnyx |
| 16 | |
| 17 | client = Telnyx( |
| 18 | api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted |
| 19 | ) |
| 20 | ``` |
| 21 | |
| 22 | All examples below assume `client` is already initialized as shown above. |
| 23 | |
| 24 | ## Error Handling |
| 25 | |
| 26 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 27 | or authentication errors (401). Always handle errors in production code: |
| 28 | |
| 29 | ```python |
| 30 | import telnyx |
| 31 | |
| 32 | try: |
| 33 | assistant = client.ai.assistants.create( |
| 34 | instructions="You are a helpful assistant.", |
| 35 | name="my-resource", |
| 36 | model="openai/gpt-4o", |
| 37 | ) |
| 38 | except telnyx.APIConnectionError: |
| 39 | print("Network error — check connectivity and retry") |
| 40 | except telnyx.RateLimitError: |
| 41 | import time |
| 42 | time.sleep(1) # Check Retry-After header for actual delay |
| 43 | except telnyx.APIStatusError as e: |
| 44 | print(f"API error {e.status_code}: {e.message}") |
| 45 | if e.status_code == 422: |
| 46 | print("Validation error — check required fields and formats") |
| 47 | ``` |
| 48 | |
| 49 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 50 | `404` resource not found, `422` validation error (check field formats), |
| 51 | `429` rate limited (retry with exponential backoff). |
| 52 | |
| 53 | ## Important Notes |
| 54 | |
| 55 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 56 | - **Pagination:** List methods return an auto-paginating iterator. Use `for item in page_result:` to iterate through all pages automatically. |
| 57 | - **Model availability** varies by account. If a model returns 422 "not available for inference", use `client.ai.assistants.list()` to discover working models. Commonly available: `openai/gpt-4o`, `Qwen/Qwen3-235B-A22B`. |
| 58 | |
| 59 | ## Reference Use Rules |
| 60 | |
| 61 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 62 | |
| 63 | - If the parameter, enum, or response field you need is not shown inline in this skill, read [references/api-details.md](references/api-details.md) before writing code. |
| 64 | - Before using any operation in `## Additional Operations`, read [the optional-parameters section](references/api-details.md#optional-parameters) and [the response-schemas section](references/api-details.md#response-schemas). |
| 65 | |
| 66 | ## Core Tasks |
| 67 | |
| 68 | ### Create an assistant |
| 69 | |
| 70 | Assistant creation is the entrypoint for any AI assistant integration. Agents need the exact creation method and the top-level fields returned by the SDK. |
| 71 | |
| 72 | `client.ai.assistants.create()` — `POST /ai/assistants` |
| 73 | |
| 74 | | Parameter | Type | Required | Description | |
| 75 | |-----------|------|----------|-------------| |
| 76 | | `name` | string | Yes | | |
| 77 | | `instructions` | string | Yes | System instructions for the assistant. | |
| 78 | | `tags` | array[string] | No | Tags associated with the assistant. | |
| 79 | | `model` | string | No | ID of the model to use when `external_llm` is not set. | |
| 80 | | `tools` | array[object] | No | Deprecated for new integrations. | |
| 81 | | ... | | | +23 optional params in [references/api-details.md](references/api-details.md) | |
| 82 | |
| 83 | ```python |
| 84 | assistant = client.ai.assistants.create( |
| 85 | instructions="You are a helpful assistant.", |
| 86 | name="my-resource", |
| 87 | model="openai/gpt-4o", |
| 88 | ) |
| 89 | print(assistant.id) |
| 90 | ``` |
| 91 | |
| 92 | Primary response fields: |
| 93 | - `assistant.id` |
| 94 | - `assistant.name` |
| 95 | - `assistant.model` |
| 96 | - `assistant.instructions` |
| 97 | - `assistant.created_at` |
| 98 | - `assistant.conversation_flow` |
| 99 | |
| 100 | ### Chat with an assistant |
| 101 | |
| 102 | Chat is the primary runtime path. Agents need the exact assistant method and the response content field. |
| 103 | |
| 104 | `client.ai.assistants.chat()` — `POST /ai/assistants/{assistant_id}/chat` |
| 105 | |
| 106 | | Parameter | Type | Required | Description | |
| 107 | |-----------|------|----------|-------------| |
| 108 | | `content` | string | Yes | The message content sent by the client to the assistant | |
| 109 | | `conversation_id` | string (UUID) | Yes | A unique identifier for the conversation thread, used to mai... | |
| 110 | | `assistant_id` | string (UUID) | Yes | Unique identifier of the assistant. | |
| 111 | | `name` | string | No | The optional display name of the user sending the message | |
| 112 | |
| 113 | ```python |
| 114 | response = client.ai.assistants.chat( |
| 115 | assistant_id="550e8400-e29b-41d4-a716-446655440000", |
| 116 | content="Tell me a joke about cats", |
| 117 | conversation_id="42b20469-1215-4a9a-8964-c36f66b406f4", |
| 118 | ) |
| 119 | print(response.content) |
| 120 | ``` |
| 121 | |
| 122 | Primary response fields: |
| 123 | - `response.content` |
| 124 | |
| 125 | ### Create an assistant test |
| 126 | |
| 127 | Test creation is the main validation path for production assistant behavior before deployment. |
| 128 | |
| 129 | `client.ai.assistants.tests.create()` — `POST /ai/assistants/tests` |
| 130 | |
| 131 | | Parameter | Type | Required | Description | |
| 132 | |-----------|------|----------|-- |