This quick start guide will help you create your first voice AI agent, set up a phone number, and make a test call in just a few minutes.
First, create a new project and install the Pinecall SDK:
# Create a new directorymkdir pinecall-quickstartcd pinecall-quickstart
# Initialize a new Node.js projectnpm init -y
# Install the Pinecall SDKnpm install @pinecall/sdk dotenv
Create a .env
file in your project root to store your API key:
PINECALL_API_KEY=your_api_key_here
Create a file named create-agent.js
with the following code:
require('dotenv').config();const { Pinecall } = require('@pinecall/sdk');
// Initialize the Pinecall clientconst pinecall = new Pinecall({ apiKey: process.env.PINECALL_API_KEY});
async function createAgent() { try { // Create a customer support agent const agent = await pinecall.agents.create({ name: 'My First Agent', voice: 'sophia', language: 'en-US', prompt: `You are a helpful customer support agent for Acme Inc. Be friendly and concise in your responses. You specialize in answering frequently asked questions about Acme's products and services. If asked about specific customer information, politely explain that you don't have access to individual account details.` console.log(`Agent created successfully with ID: ${agent.id}`); console.log(`Make note of this agent ID: ${agent.id}`); return agent; } catch (error) { console.error('Error creating agent:', error.message); }}
// Run the functioncreateAgent();
Run the script to create your agent:
node create-agent.js
Make note of the agent ID that is output. You'll need it in the next step.
Create a file named acquire-number.js
with the following code:
require('dotenv').config();const { Pinecall } = require('@pinecall/sdk');
// Initialize the Pinecall clientconst pinecall = new Pinecall({ apiKey: process.env.PINECALL_API_KEY});
// Replace with your agent ID from step 2const AGENT_ID = 'your_agent_id_here';
async function acquirePhoneNumber() { try { // Find available phone numbers in the US const availableNumbers = await pinecall.phoneNumbers.list({ country: 'US', type: 'local' }); if (availableNumbers.length === 0) { console.log('No available phone numbers found'); return; } console.log(`Found ${availableNumbers.length} available numbers`); // Acquire the first available number const phoneNumber = await pinecall.phoneNumbers.acquire({ phoneNumber: availableNumbers[0].number }); console.log(`Acquired phone number: ${phoneNumber.number}`); // Configure the phone number to use our agent const updatedNumber = await pinecall.phoneNumbers.update(phoneNumber.id, { friendlyName: 'My First Phone Number', agentId: AGENT_ID }); console.log(`Phone number configured successfully!`); console.log(`You can now call ${updatedNumber.number} to talk to your agent.`); } catch (error) { console.error('Error:', error.message); }}
// Run the functionacquirePhoneNumber();
Update the AGENT_ID
variable with your agent ID from step 2, then run the script:
node acquire-number.js
Now you can call the phone number you acquired to interact with your AI agent. Use your mobile phone or any phone to dial the number.
Try asking your agent some of these questions:
You can also use your agent to make outbound calls. Create a file named make-call.js
with the following code:
require('dotenv').config();const { Pinecall } = require('@pinecall/sdk');
// Initialize the Pinecall clientconst pinecall = new Pinecall({ apiKey: process.env.PINECALL_API_KEY});
// Replace with your agent ID from step 2const AGENT_ID = 'your_agent_id_here';
// Replace with your phone number that will receive the callconst YOUR_PHONE_NUMBER = '+15551234567';
async function makeOutboundCall() { try { // Initiate an outbound call // Initiate an outbound call const call = await pinecall.calls.create({ agentId: AGENT_ID, to: YOUR_PHONE_NUMBER, from: null, // Will use one of your Pinecall numbers automatically initialMessage: `Hello, this is Acme customer support calling. I'm checking in to see if you need any assistance today.` }); console.log(`Call initiated with ID: ${call.id}`); console.log(`You should receive a call shortly on ${YOUR_PHONE_NUMBER}`); } catch (error) { console.error('Error making call:', error.message); }}
// Run the functionmakeOutboundCall();
Update the AGENT_ID
variable with your agent ID and YOUR_PHONE_NUMBER
with your phone number, then run the script:
node make-call.js
Congratulations! You've created your first voice AI agent and set up a phone number. Here's what you can do next: