$npx -y skills add team-telnyx/ai --skill telnyx-ai-assistants-goAI 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 - Go |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | go get github.com/team-telnyx/telnyx-go |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```go |
| 14 | import ( |
| 15 | "context" |
| 16 | "fmt" |
| 17 | "os" |
| 18 | |
| 19 | "github.com/team-telnyx/telnyx-go" |
| 20 | "github.com/team-telnyx/telnyx-go/option" |
| 21 | ) |
| 22 | |
| 23 | client := telnyx.NewClient( |
| 24 | option.WithAPIKey(os.Getenv("TELNYX_API_KEY")), |
| 25 | ) |
| 26 | ``` |
| 27 | |
| 28 | All examples below assume `client` is already initialized as shown above. |
| 29 | |
| 30 | ## Error Handling |
| 31 | |
| 32 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 33 | or authentication errors (401). Always handle errors in production code: |
| 34 | |
| 35 | ```go |
| 36 | import "errors" |
| 37 | |
| 38 | assistant, err := client.AI.Assistants.New(context.Background(), telnyx.AIAssistantNewParams{ |
| 39 | Instructions: "You are a helpful assistant.", |
| 40 | Name: "my-resource", |
| 41 | Model: "openai/gpt-4o", |
| 42 | }) |
| 43 | if err != nil { |
| 44 | var apiErr *telnyx.Error |
| 45 | if errors.As(err, &apiErr) { |
| 46 | switch apiErr.StatusCode { |
| 47 | case 422: |
| 48 | fmt.Println("Validation error — check required fields and formats") |
| 49 | case 429: |
| 50 | fmt.Println("Rate limited, retrying...") |
| 51 | default: |
| 52 | fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error()) |
| 53 | } |
| 54 | } else { |
| 55 | fmt.Println("Network error — check connectivity and retry") |
| 56 | } |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 61 | `404` resource not found, `422` validation error (check field formats), |
| 62 | `429` rate limited (retry with exponential backoff). |
| 63 | |
| 64 | ## Important Notes |
| 65 | |
| 66 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 67 | - **Pagination:** Use `ListAutoPaging()` for automatic iteration: `iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }`. |
| 68 | |
| 69 | ## Reference Use Rules |
| 70 | |
| 71 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 72 | |
| 73 | - 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. |
| 74 | - 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). |
| 75 | |
| 76 | ## Core Tasks |
| 77 | |
| 78 | ### Create an assistant |
| 79 | |
| 80 | 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. |
| 81 | |
| 82 | `client.AI.Assistants.New()` — `POST /ai/assistants` |
| 83 | |
| 84 | | Parameter | Type | Required | Description | |
| 85 | |-----------|------|----------|-------------| |
| 86 | | `Name` | string | Yes | | |
| 87 | | `Instructions` | string | Yes | System instructions for the assistant. | |
| 88 | | `Tags` | array[string] | No | Tags associated with the assistant. | |
| 89 | | `Model` | string | No | ID of the model to use when `external_llm` is not set. | |
| 90 | | `Tools` | array[object] | No | Deprecated for new integrations. | |
| 91 | | ... | | | +23 optional params in [references/api-details.md](references/api-details.md) | |
| 92 | |
| 93 | ```go |
| 94 | assistant, err := client.AI.Assistants.New(context.Background(), telnyx.AIAssistantNewParams{ |
| 95 | Instructions: "You are a helpful assistant.", |
| 96 | Name: "my-resource", |
| 97 | Model: "openai/gpt-4o", |
| 98 | }) |
| 99 | if err != nil { |
| 100 | log.Fatal(err) |
| 101 | } |
| 102 | fmt.Printf("%+v\n", assistant.ID) |
| 103 | ``` |
| 104 | |
| 105 | Primary response fields: |
| 106 | - `assistant.ID` |
| 107 | - `assistant.Name` |
| 108 | - `assistant.Model` |
| 109 | - `assistant.Instructions` |
| 110 | - `assistant.CreatedAt` |
| 111 | - `assistant.ConversationFlow` |
| 112 | |
| 113 | ### Chat with an assistant |
| 114 | |
| 115 | Chat is the primary runtime path. Agents need the exact assistant method and the response content field. |
| 116 | |
| 117 | `client.AI.Assistants.Chat()` — `POST /ai/assistants/{assistant_id}/chat` |
| 118 | |
| 119 | | Parameter | Type | Required | Description | |
| 120 | |-----------|------|----------|-------------| |
| 121 | | `Content` | string | Yes | The message content sent by the client to the assistant | |
| 122 | | `ConversationId` | string (UUID) | Yes | A unique identifier for the conversation thread, used to mai... | |
| 123 | | `AssistantId` | string (UUID) | Yes | Unique identifier of the assistant. | |
| 124 | | `Name` | string | No | The optional display name of the user sending the message | |
| 125 | |
| 126 | ```go |
| 127 | response, err := client.AI.Assistants.Chat( |
| 128 | context.Background(), |
| 129 | "assistant_id", |
| 130 | telnyx.AIAssistantChatParams{ |
| 131 | Content: "Tell me a joke about cats", |
| 132 | ConversationID: "42b20469-1215-4a9a-8964-c36f66b406f4", |
| 133 | }, |
| 134 | ) |
| 135 | if err != nil { |
| 136 | log.Fatal(err) |
| 137 | } |
| 138 | fmt.Printf("%+v\n", response.Content) |
| 139 | ``` |
| 140 | |
| 141 | Primary response fields: |
| 142 | - `response.Content` |
| 143 | |
| 144 | ### Create an assistant test |
| 145 | |
| 146 | Test creation is the main validation path for production assistant behavior before deployment. |
| 147 | |
| 148 | `client.AI.Assistants.Tests.New()` — `POS |