Initiate an outbound AI call
Initiate an outbound AI call with warm-up support: Telnyx attempts to warm up the assistant identified by AIAssistantId before placing the call and starts it automatically when the called party answers. Validates parameters, builds an internal TeXML with an AI Assistant configuration, encodes instructions into client state, and calls the dial API. The Twiml, Texml, and Url parameters are not allowed and will result in a 422 error.
Expected callback events:
Status callbacks: initiated, ringing, answered, one terminal status (completed, no-answer, busy, canceled, or failed), then analyzed after post-call processing completes.
Conversation callbacks: conversation_created and conversation_ended.
Recording, AMD, transcription, and deepfake detection callbacks are only sent when those features are enabled.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.texml.initiateAICall('connection_id', {
AIAssistantId: 'ai-assistant-id-123',
From: '+13120001234',
To: '+13121230000',
});
console.log(response.call_sid);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.texml.initiate_ai_call(
connection_id="connection_id",
ai_assistant_id="ai-assistant-id-123",
from_="+13120001234",
to="+13121230000",
)
print(response.call_sid)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Texml.InitiateAICall(
context.TODO(),
"connection_id",
telnyx.TexmlInitiateAICallParams{
AIAssistantID: "ai-assistant-id-123",
From: "+13120001234",
To: "+13121230000",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.CallSid)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.texml.TexmlInitiateAiCallParams;
import com.telnyx.sdk.models.texml.TexmlInitiateAiCallResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
TexmlInitiateAiCallParams params = TexmlInitiateAiCallParams.builder()
.connectionId("connection_id")
.aiAssistantId("ai-assistant-id-123")
.from("+13120001234")
.to("+13121230000")
.build();
TexmlInitiateAiCallResponse response = client.texml().initiateAiCall(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.texml.initiate_ai_call(
"connection_id",
ai_assistant_id: "ai-assistant-id-123",
from: "+13120001234",
to: "+13121230000"
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->texml->initiateAICall(
'connection_id',
aiAssistantID: 'ai-assistant-id-123',
from: '+13120001234',
to: '+13121230000',
aiAssistantDynamicVariables: [
'customer_name' => 'John Doe', 'account_id' => '12345'
],
aiAssistantVersion: 'AIAssistantVersion',
asyncAmd: true,
asyncAmdStatusCallback: 'https://www.example.com/callback',
asyncAmdStatusCallbackMethod: 'GET',
callerID: 'Info',
conversationCallback: 'https://www.example.com/conversation-callback',
conversationCallbackMethod: 'GET',
conversationCallbacks: [
'https://www.example.com/conversation-callback1',
'https://www.example.com/conversation-callback2',
],
customHeaders: [['name' => 'X-Custom-Header', 'value' => 'custom-value']],
detectionMode: 'Premium',
machineDetection: 'Enable',
machineDetectionPromptEndTimeout: 5000,
machineDetectionSilenceTimeout: 2000,
machineDetectionSpeechEndThreshold: 2000,
machineDetectionSpeechThreshold: 2000,
machineDetectionTimeout: 5000,
passports: 'Passports',
preferredCodecs: 'PCMA,PCMU',
record: false,
recordingChannels: 'dual',
recordingStatusCallback: 'https://example.com/recording_status_callback',
recordingStatusCallbackEvent: 'in-progress completed absent',
recordingStatusCallbackMethod: 'GET',
recordingTimeout: 5,
recordingTrack: 'inbound',
sendRecordingURL: false,
sipAuthPassword: '1234',
sipAuthUsername: 'user',
sipRegion: 'Canada',
statusCallback: 'https://www.example.com/callback',
statusCallbackEvent: 'initiated answered',
statusCallbackMethod: 'GET',
statusCallbacks: [
'https://www.example.com/callback1', 'https://www.example.com/callback2'
],
timeLimit: 3600,
timeoutSeconds: 60,
trim: 'trim-silence',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx texml initiate-ai-call \
--api-key 'My API Key' \
--connection-id connection_id \
--ai-assistant-id ai-assistant-id-123 \
--from +13120001234 \
--to +13121230000curl --request POST \
--url https://api.telnyx.com/v2/texml/ai_calls/{connection_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"From": "+13120001234",
"To": "+13121230000",
"AIAssistantId": "ai-assistant-id-123"
}
'{
"from": "+13120001234",
"to": "+13121230000",
"status": "queued",
"call_sid": "v3:example-call-sid"
}Authorizations
Body
Initiate AI Call request object
To be used as the caller id name (SIP From Display Name) presented to the destination (To number). The string should have a maximum of 128 characters, containing only letters, numbers, spaces, and -_~!.+ special characters. If omitted, the display name will be the same as the number in the From field.
"Info"
The status callback events for which Telnyx should send a webhook for this AI call. Multiple events can be defined when separated by a space. Valid values: initiated, ringing, answered, completed, no-answer, busy, canceled, failed, analyzed. When provided, this per-call value overrides the status callback events configured on the TeXML application/connection.
"initiated answered"
Array of URL destinations for Telnyx to send status callback events for this AI call. When provided, these per-call values override the status callback URL configured on the TeXML application/connection.
[
"https://www.example.com/callback1",
"https://www.example.com/callback2"
]
Allows you to choose between Regular, Premium, and PremiumCallScreening detections. See https://developers.telnyx.com/docs/voice/programmable-voice/answering-machine-detection
Premium, Regular, PremiumCallScreening "Premium"
Selects which detectors must validate a beep. both requires the amplitude and frequency detectors to agree. freq_only uses the frequency detector alone, for beeps whose volume is too unsteady for the default profile. Only used when MachineDetection is enabled.
both, freq_only "freq_only"
Lowest frequency, in Hz, that a tone must reach to be treated as a beep. Raising it above 480 excludes North American ringback (440 + 480 Hz), which can otherwise be reported as a beep when the freq_only profile is in use. Only used when MachineDetection is enabled.
200 <= x <= 4000550
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.texml.initiateAICall('connection_id', {
AIAssistantId: 'ai-assistant-id-123',
From: '+13120001234',
To: '+13121230000',
});
console.log(response.call_sid);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.texml.initiate_ai_call(
connection_id="connection_id",
ai_assistant_id="ai-assistant-id-123",
from_="+13120001234",
to="+13121230000",
)
print(response.call_sid)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.Texml.InitiateAICall(
context.TODO(),
"connection_id",
telnyx.TexmlInitiateAICallParams{
AIAssistantID: "ai-assistant-id-123",
From: "+13120001234",
To: "+13121230000",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.CallSid)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.texml.TexmlInitiateAiCallParams;
import com.telnyx.sdk.models.texml.TexmlInitiateAiCallResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
TexmlInitiateAiCallParams params = TexmlInitiateAiCallParams.builder()
.connectionId("connection_id")
.aiAssistantId("ai-assistant-id-123")
.from("+13120001234")
.to("+13121230000")
.build();
TexmlInitiateAiCallResponse response = client.texml().initiateAiCall(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.texml.initiate_ai_call(
"connection_id",
ai_assistant_id: "ai-assistant-id-123",
from: "+13120001234",
to: "+13121230000"
)
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->texml->initiateAICall(
'connection_id',
aiAssistantID: 'ai-assistant-id-123',
from: '+13120001234',
to: '+13121230000',
aiAssistantDynamicVariables: [
'customer_name' => 'John Doe', 'account_id' => '12345'
],
aiAssistantVersion: 'AIAssistantVersion',
asyncAmd: true,
asyncAmdStatusCallback: 'https://www.example.com/callback',
asyncAmdStatusCallbackMethod: 'GET',
callerID: 'Info',
conversationCallback: 'https://www.example.com/conversation-callback',
conversationCallbackMethod: 'GET',
conversationCallbacks: [
'https://www.example.com/conversation-callback1',
'https://www.example.com/conversation-callback2',
],
customHeaders: [['name' => 'X-Custom-Header', 'value' => 'custom-value']],
detectionMode: 'Premium',
machineDetection: 'Enable',
machineDetectionPromptEndTimeout: 5000,
machineDetectionSilenceTimeout: 2000,
machineDetectionSpeechEndThreshold: 2000,
machineDetectionSpeechThreshold: 2000,
machineDetectionTimeout: 5000,
passports: 'Passports',
preferredCodecs: 'PCMA,PCMU',
record: false,
recordingChannels: 'dual',
recordingStatusCallback: 'https://example.com/recording_status_callback',
recordingStatusCallbackEvent: 'in-progress completed absent',
recordingStatusCallbackMethod: 'GET',
recordingTimeout: 5,
recordingTrack: 'inbound',
sendRecordingURL: false,
sipAuthPassword: '1234',
sipAuthUsername: 'user',
sipRegion: 'Canada',
statusCallback: 'https://www.example.com/callback',
statusCallbackEvent: 'initiated answered',
statusCallbackMethod: 'GET',
statusCallbacks: [
'https://www.example.com/callback1', 'https://www.example.com/callback2'
],
timeLimit: 3600,
timeoutSeconds: 60,
trim: 'trim-silence',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx texml initiate-ai-call \
--api-key 'My API Key' \
--connection-id connection_id \
--ai-assistant-id ai-assistant-id-123 \
--from +13120001234 \
--to +13121230000curl --request POST \
--url https://api.telnyx.com/v2/texml/ai_calls/{connection_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"From": "+13120001234",
"To": "+13121230000",
"AIAssistantId": "ai-assistant-id-123"
}
'{
"from": "+13120001234",
"to": "+13121230000",
"status": "queued",
"call_sid": "v3:example-call-sid"
}