$npx -y skills add team-telnyx/ai --skill telnyx-numbers-compliance-pythonManage regulatory requirements, number bundles, supporting documents, and verified numbers for compliance. This skill provides Python SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Compliance - 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 | result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello") |
| 34 | except telnyx.APIConnectionError: |
| 35 | print("Network error — check connectivity and retry") |
| 36 | except telnyx.RateLimitError: |
| 37 | # 429: rate limited — wait and retry with exponential backoff |
| 38 | import time |
| 39 | time.sleep(1) # Check Retry-After header for actual delay |
| 40 | except telnyx.APIStatusError as e: |
| 41 | print(f"API error {e.status_code}: {e.message}") |
| 42 | if e.status_code == 422: |
| 43 | print("Validation error — check required fields and formats") |
| 44 | ``` |
| 45 | |
| 46 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 47 | `404` resource not found, `422` validation error (check field formats), |
| 48 | `429` rate limited (retry with exponential backoff). |
| 49 | |
| 50 | ## Important Notes |
| 51 | |
| 52 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 53 | - **Pagination:** List methods return an auto-paginating iterator. Use `for item in page_result:` to iterate through all pages automatically. |
| 54 | |
| 55 | ## Retrieve Bundles |
| 56 | |
| 57 | Get all allowed bundles. |
| 58 | |
| 59 | `GET /bundle_pricing/billing_bundles` |
| 60 | |
| 61 | ```python |
| 62 | page = client.bundle_pricing.billing_bundles.list() |
| 63 | page = page.data[0] |
| 64 | print(page.id) |
| 65 | ``` |
| 66 | |
| 67 | Returns: `cost_code` (string), `created_at` (date), `currency` (string), `id` (uuid), `is_public` (boolean), `mrc_price` (float), `name` (string), `slug` (string), `specs` (array[string]) |
| 68 | |
| 69 | ## Get Bundle By Id |
| 70 | |
| 71 | Get a single bundle by ID. |
| 72 | |
| 73 | `GET /bundle_pricing/billing_bundles/{bundle_id}` |
| 74 | |
| 75 | ```python |
| 76 | billing_bundle = client.bundle_pricing.billing_bundles.retrieve( |
| 77 | bundle_id="8661948c-a386-4385-837f-af00f40f111a", |
| 78 | ) |
| 79 | print(billing_bundle.data) |
| 80 | ``` |
| 81 | |
| 82 | Returns: `active` (boolean), `bundle_limits` (array[object]), `cost_code` (string), `created_at` (date), `id` (uuid), `is_public` (boolean), `name` (string), `slug` (string) |
| 83 | |
| 84 | ## Get User Bundles |
| 85 | |
| 86 | Get a paginated list of user bundles. |
| 87 | |
| 88 | `GET /bundle_pricing/user_bundles` |
| 89 | |
| 90 | ```python |
| 91 | page = client.bundle_pricing.user_bundles.list() |
| 92 | page = page.data[0] |
| 93 | print(page.id) |
| 94 | ``` |
| 95 | |
| 96 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 97 | |
| 98 | ## Create User Bundles |
| 99 | |
| 100 | Creates multiple user bundles for the user. |
| 101 | |
| 102 | `POST /bundle_pricing/user_bundles/bulk` |
| 103 | |
| 104 | Optional: `idempotency_key` (uuid), `items` (array[object]) |
| 105 | |
| 106 | ```python |
| 107 | user_bundle = client.bundle_pricing.user_bundles.create() |
| 108 | print(user_bundle.data) |
| 109 | ``` |
| 110 | |
| 111 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 112 | |
| 113 | ## Get Unused User Bundles |
| 114 | |
| 115 | Returns all user bundles that aren't in use. |
| 116 | |
| 117 | `GET /bundle_pricing/user_bundles/unused` |
| 118 | |
| 119 | ```python |
| 120 | response = client.bundle_pricing.user_bundles.list_unused() |
| 121 | print(response.data) |
| 122 | ``` |
| 123 | |
| 124 | Returns: `billing_bundle` (object), `user_bundle_ids` (array[string]) |
| 125 | |
| 126 | ## Get User Bundle by Id |
| 127 | |
| 128 | Retrieves a user bundle by its ID. |
| 129 | |
| 130 | `GET /bundle_pricing/user_bundles/{user_bundle_id}` |
| 131 | |
| 132 | ```python |
| 133 | user_bundle = client.bundle_pricing.user_bundles.retrieve( |
| 134 | user_bundle_id="ca1d2263-d1f1-43ac-ba53-248e7a4bb26a", |
| 135 | ) |
| 136 | print(user_bundle.data) |
| 137 | ``` |
| 138 | |
| 139 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 140 | |
| 141 | ## Deactivate User Bundle |
| 142 | |
| 143 | Deactivates a user bundle by its ID. |
| 144 | |
| 145 | `DELETE /bundle_pricing/user_bundles/{user_bundle_id}` |
| 146 | |
| 147 | ```python |
| 148 | response = client.bundle_pricing.user_bundles.deactivate( |
| 149 | user_bundle_id="ca1d2263-d1f1-43ac-ba53-248e7a4bb26a", |
| 150 | ) |
| 151 | print(response.data) |
| 152 | ``` |
| 153 | |
| 154 | Returns: `active` (boolean), `billing_bundle` (object), `created_at` (date), `id` (uuid), `resources` (array[object]), `updated_at` (date), `user_id` (uuid) |
| 155 | |
| 156 | ## Get User Bundle Resources |
| 157 | |
| 158 | Retrieves the resources of a user bundle by its ID. |
| 159 | |
| 160 | `GET /bundle_pricing/user_bundles/{user_bundle_id}/resources` |
| 161 | |
| 162 | ```python |
| 163 | response = client.bundle_pricing.user_bundles.list_resources( |
| 164 | user_bundle_id="ca1d2263-d1f1-43ac |