Getting Started with the Voice API
This page will talk you through all of the necessary steps to get up and running with the Vonage Voice API.
Prerequisites
Create a Vonage account
To create your free Vonage account:
- In your browser, navigate to Dashboard.
- Add your company information and click Sign up. Vonage sends a PIN to your phone as a text message or automated phone call. The timeout for each verification attempt is 5 minutes. Note: you can associate a phone number with one account only. If your phone number is already associated with a Vonage account you should remove that phone number from the existing account.
- In Phone number verification, enter the PIN sent to you by Vonage and click Verify. You are logged into Dashboard and shown how to start developing with Vonage. This page is displayed each time you login until you have made your first successful call with Vonage APIs.
When you create your Vonage account you are given €2 free test credit and your account is set in DEMO mode. You can use our products to send messages to up to 10 destination numbers, a message stating that the account is in demo mode is added to all the SMS you send. To move out of the demo mode add credit to your account.
For very few countries Vonage cannot create an account for you automatically. This is because of payment restrictions or legal trading restrictions for a US registered company.
Create an Application
You can install the CLI with the following command:
Before you can start working with your apps, you need to register your configuration: API Key and Secret. You can find them via the Dashboard, in API Settings. Once set, initialize your account using the following command:
As soon as the CLI is both installed and configured, use it to create a Vonage application using the following command:
The command starts an interactive prompt to ask for the application name, and the capabilities you want to enable - make sure to enable Voice.
When finished, it creates the vonage_app.json file in the current directory containing the Application ID, Application name and private key. It also creates a second file with the private key name app_name.key.
Go to the Application's page on the Dashboard, and define a Name for your Application.

Make sure to click on the Generate public and private key button, and keep the file private.key around.
Then, enable the Voice capability. For the moment, leave everything by default.

Finally, click Save at the bottom of the page.
Rent a Number
You can rent a number using the Vonage CLI. The following command purchases an available number in the United States:
Specify an alternative two-character country code to purchase a number in another country.
In the Dashboard, go to the Buy Numbers page. Make sure to tick Voice in the search filter, and select the country you want to buy a number in.

You can then click the Buy button next to the number you want, and validate your purchase.
Congratulations! Your virtual number is now listed in Your Numbers
Link a Number
Now that you have both an application and a number, you need to link them together.
Replace YOUR_VONAGE_NUMBER with the number you bought and APPLICATION_ID with your application id, then run the following command:
Now that you have both an application and a number, you need to link them together.
Go to the Application page, and click on the application you created earlier.

In the Voice section, click on the Link button next to the number you want to link.
Voice Playground
In the Developer Dashboard, you can try out the Voice API interactively in the Voice Playground. Once you are signed up for a Vonage API account, you can go to Voice Playground in the Dashboard.
Making an Outbound Call
The primary way that you'll interact with the Vonage API voice platform is via the public API. To place an outbound call, you make a POST request to https://api.nexmo.com/v1/calls.
To make your first call with the Voice API, choose your language below and replace the following variables in the example code:
| Key | Description |
|---|---|
VONAGE_NUMBER | Your Vonage number that the call will be made from. For example 447700900000. |
TO_NUMBER | The number you would like to call to in E.164 format. For example 447700900001. |
Prerequisites
Execute the following command at your terminal prompt to create the JWT for authentication:
export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)Write the code
Add the following to make-an-outbound-call.sh:
curl -X POST https://api.nexmo.com/v1/calls\
-H "Authorization: Bearer $JWT"\
-H "Content-Type: application/json"\
-d '{"to":[{"type": "phone","number": "'$TO_NUMBER'"}],
"from": {"type": "phone","number": "'$VONAGE_NUMBER'"},
"answer_url":["https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json"]}'Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named make-call.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_APPLICATION_PRIVATE_KEY_PATH,
});Write the code
Add the following to make-call.js:
vonage.voice.createOutboundCall({
to: [
{
type: 'phone',
number: TO_NUMBER,
},
],
from: {
type: 'phone',
number: VONAGE_NUMBER,
},
answer_url: [ANSWER_URL],
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:1.1.2'Create a class named OutboundTextToSpeechCall and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the OutboundTextToSpeechCall class:
val callEvent = client.voice.createCall {
toPstn(TO_NUMBER)
from(VONAGE_NUMBER)
answerUrl(ANSWER_URL)
}Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing OutboundTextToSpeechCall:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:8.15.1'Write the code
Add the following to the main method of the OutboundTextToSpeech class:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();
final String VONAGE_NUMBER = envVar("VONAGE_NUMBER");
final String TO_NUMBER = envVar("TO_NUMBER");
final String ANSWER_URL = "https://nexmo-community.github.io/ncco-examples/talk.json";
client.getVoiceClient().createCall(new Call(TO_NUMBER, VONAGE_NUMBER, ANSWER_URL));Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing OutboundTextToSpeech:
Prerequisites
Install-Package VonageWrite the code
Add the following to MakeOutboundCall.cs:
var creds = Credentials.FromAppIdAndPrivateKeyPath(vonageApplicationId, vonagePrivateKeyPath);
var client = new VonageClient(creds);
var answerUrl = "https://nexmo-community.github.io/ncco-examples/text-to-speech.json";
var toEndpoint = new PhoneEndpoint() { Number = toNumber };
var fromEndpoint = new PhoneEndpoint() { Number = vonageNumber };
var command = new CallCommand() { To = new Endpoint[] { toEndpoint }, From = fromEndpoint, AnswerUrl = new[] { answerUrl } };
var response = await client.VoiceClient.CreateCallAsync(command);Prerequisites
composer require vonage/clientWrite the code
Add the following to text-to-speech-outbound.php:
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';
// Building Blocks
// 1. Make a Phone Call
// 2. Play Text-to-Speech
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone(TO_NUMBER),
new \Vonage\Voice\Endpoint\Phone(VONAGE_NUMBER)
);
$outboundCall->setAnswerWebhook(
new \Vonage\Voice\Webhook(
'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json',
\Vonage\Voice\Webhook::METHOD_GET
)
);
$response = $client->voice()->createOutboundCall($outboundCall);
var_dump($response);Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonageWrite the code
Add the following to make-an-outbound-call.py:
client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
response = client.voice.create_call({
'to': [{'type': 'phone', 'number': TO_NUMBER}],
'from': {'type': 'phone', 'number': FROM_NUMBER},
'answer_url': ['https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json']
})
pprint(response)Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageWrite the code
Add the following to outbound_tts_call.rb:
client = Vonage::Client.new(
api_key: VONAGE_API_KEY,
api_secret: VONAGE_API_SECRET,
application_id: VONAGE_APPLICATION_ID,
private_key: File.read(VONAGE_APPLICATION_PRIVATE_KEY_PATH)
)
response = client.voice.create(
to: [{
type: 'phone',
number: TO_NUMBER
}],
from: {
type: 'phone',
number: VONAGE_NUMBER
},
answer_url: [
'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json'
]
)
puts response.inspectRun your code
Save this file to your machine and run it:
To make this easier, Vonage provides Server SDKs in various languages that take care of authentication and creating the correct request body for you.
What Next?
Once you've made your first call, you're ready to try out other aspects of the Voice API. Check out our documentation and references linked below for more information.