From a1616da3bf9c10513dcc5347d281bd73e7fc894f Mon Sep 17 00:00:00 2001 From: Dan Goosewin Date: Tue, 19 Aug 2025 22:22:24 -0700 Subject: [PATCH 1/2] chore(quickstart/phone): simplify code snippets --- fern/quickstart/phone.mdx | 303 ++++++++++---------------------------- 1 file changed, 80 insertions(+), 223 deletions(-) diff --git a/fern/quickstart/phone.mdx b/fern/quickstart/phone.mdx index 52255fb35..d74bd7b2f 100644 --- a/fern/quickstart/phone.mdx +++ b/fern/quickstart/phone.mdx @@ -96,52 +96,20 @@ vapi assistant create ```typescript import { VapiClient } from '@vapi-ai/server-sdk'; - // Initialize the Vapi client - const vapi = new VapiClient({ - token: 'your-api-key', // Replace with your actual API key + const vapi = new VapiClient({ token: process.env.VAPI_API_KEY! }); + + const assistant = await vapi.assistants.create({ + name: 'Customer Support Assistant', + model: { + provider: 'openai', + model: 'gpt-4o', + messages: [{ role: 'system', content: 'You are Alex, a customer service voice assistant for TechSolutions.' }] + }, + voice: { provider: '11labs', voice_id: 'cgSgspJ2msm6clMCkdW9' }, + firstMessage: 'Hi there, this is Alex from TechSolutions customer support. How can I help you today?' }); - // Define the system prompt for customer support - const systemPrompt = `You are Alex, a customer service voice assistant for TechSolutions. Your primary purpose is to help customers resolve issues with their products, answer questions about services, and ensure a satisfying support experience. - - Sound friendly, patient, and knowledgeable without being condescending - - Use a conversational tone with natural speech patterns - - Speak with confidence but remain humble when you don'\''t know something - - Demonstrate genuine concern for customer issues`; - - async function createSupportAssistant() { - try { - const assistant = await vapi.assistants.create({ - name: 'Customer Support Assistant', - // Configure the AI model - model: { - provider: 'openai', - model: 'gpt-4o', - messages: [ - { - role: 'system', - content: systemPrompt, - }, - ], - }, - // Configure the voice - voice: { - provider: '11labs', - voice_id: 'cgSgspJ2msm6clMCkdW9', - }, - // Set the first message - firstMessage: 'Hi there, this is Alex from TechSolutions customer support. How can I help you today?', - }); - - console.log('Assistant created:', assistant.id); - return assistant; - } catch (error) { - console.error('Error creating assistant:', error); - throw error; - } - } - - // Create the assistant - createSupportAssistant(); + console.log(assistant.id); ``` @@ -157,50 +125,23 @@ vapi assistant create ```python + import os from vapi import Vapi - # Initialize the Vapi client - client = Vapi(token="your-api-key") # Replace with your actual API key + client = Vapi(token=os.getenv("VAPI_API_KEY")) - # Define the system prompt for customer support - system_prompt = """You are Alex, a customer service voice assistant for TechSolutions. Your primary purpose is to help customers resolve issues with their products, answer questions about services, and ensure a satisfying support experience. - - Sound friendly, patient, and knowledgeable without being condescending - - Use a conversational tone with natural speech patterns - - Speak with confidence but remain humble when you don't know something - - Demonstrate genuine concern for customer issues""" - - def create_support_assistant(): - try: - assistant = client.assistants.create( - name="Customer Support Assistant", - # Configure the AI model - model={ - "provider": "openai", - "model": "gpt-4o", - "messages": [ - { - "role": "system", - "content": system_prompt, - } - ], - }, - # Configure the voice - voice={ - "provider": "11labs", - "voice_id": "cgSgspJ2msm6clMCkdW9", - }, - # Set the first message - first_message="Hi there, this is Alex from TechSolutions customer support. How can I help you today?", - ) - - print(f"Assistant created: {assistant.id}") - return assistant - except Exception as error: - print(f"Error creating assistant: {error}") - raise error - - # Create the assistant - create_support_assistant() + assistant = client.assistants.create( + name="Customer Support Assistant", + model={ + "provider": "openai", + "model": "gpt-4o", + "messages": [{"role": "system", "content": "You are Alex, a customer service voice assistant for TechSolutions."}], + }, + voice={"provider": "11labs", "voice_id": "cgSgspJ2msm6clMCkdW9"}, + first_message="Hi there, this is Alex from TechSolutions customer support. How can I help you today?", + ) + + print(assistant.id) ``` @@ -211,24 +152,16 @@ vapi assistant create ```bash curl -X POST "https://api.vapi.ai/assistant" \ - -H "Authorization: Bearer your-api-key" \ + -H "Authorization: Bearer $VAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Customer Support Assistant", "model": { "provider": "openai", "model": "gpt-4o", - "messages": [ - { - "role": "system", - "content": "You are Alex, a customer service voice assistant for TechSolutions. Your primary purpose is to help customers resolve issues with their products, answer questions about services, and ensure a satisfying support experience.\n- Sound friendly, patient, and knowledgeable without being condescending\n- Use a conversational tone with natural speech patterns\n- Speak with confidence but remain humble when you don'\''t know something\n- Demonstrate genuine concern for customer issues" - } - ] - }, - "voice": { - "provider": "11labs", - "voice_id": "cgSgspJ2msm6clMCkdW9" + "messages": [{ "role": "system", "content": "You are Alex, a customer service voice assistant for TechSolutions." }] }, + "voice": { "provider": "11labs", "voice_id": "cgSgspJ2msm6clMCkdW9" }, "firstMessage": "Hi there, this is Alex from TechSolutions customer support. How can I help you today?" }' ``` @@ -266,44 +199,22 @@ vapi assistant create - + ```typescript - async function purchasePhoneNumber() { - try { - // Purchase a phone number - const phoneNumber = await vapi.phoneNumbers.create({ - fallbackDestination: { - type: 'number', - number: '+1234567890', // Your fallback number - }, - }); - - console.log('Phone number created:', phoneNumber.number); - return phoneNumber; - } catch (error) { - console.error('Error creating phone number:', error); - throw error; - } - } - ``` - - - - ```typescript - async function configureInboundCalls(phoneNumberId: string, assistantId: string) { - try { - // Update phone number with assistant configuration - const updatedNumber = await vapi.phoneNumbers.update(phoneNumberId, { - assistantId: assistantId, - }); - - console.log('Phone number configured for inbound calls'); - return updatedNumber; - } catch (error) { - console.error('Error configuring phone number:', error); - throw error; - } - } + const res = await fetch('https://api.vapi.ai/phone-number', { + method: 'POST', + headers: { + Authorization: `Bearer ${process.env.VAPI_API_KEY}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + provider: 'vapi', + assistantId: 'your-assistant-id', + numberDesiredAreaCode: '415', + }), + }); + const phoneNumber = await res.json(); + console.log(phoneNumber.id); ``` @@ -311,41 +222,25 @@ vapi assistant create - + ```python - def purchase_phone_number(): - try: - # Purchase a phone number - phone_number = client.phone_numbers.create( - fallback_destination={ - "type": "number", - "number": "+1234567890", # Your fallback number - } - ) - - print(f"Phone number created: {phone_number.number}") - return phone_number - except Exception as error: - print(f"Error creating phone number: {error}") - raise error - ``` - + import os, requests - - ```python - def configure_inbound_calls(phone_number_id: str, assistant_id: str): - try: - # Update phone number with assistant configuration - updated_number = client.phone_numbers.update( - phone_number_id, - assistant_id=assistant_id, - ) - - print("Phone number configured for inbound calls") - return updated_number - except Exception as error: - print(f"Error configuring phone number: {error}") - raise error + res = requests.post( + "https://api.vapi.ai/phone-number", + headers={ + "Authorization": f"Bearer {os.getenv('VAPI_API_KEY')}", + "Content-Type": "application/json", + }, + json={ + "provider": "vapi", + "assistantId": "your-assistant-id", + "numberDesiredAreaCode": "415", + }, + timeout=30, + ) + phone_number = res.json() + print(phone_number["id"]) ``` @@ -353,30 +248,20 @@ vapi assistant create - + ```bash curl -X POST "https://api.vapi.ai/phone-number" \ - -H "Authorization: Bearer your-api-key" \ + -H "Authorization: Bearer $VAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ - "fallbackDestination": { - "type": "number", - "number": "+1234567890" - } + "provider": "vapi", + "assistantId": "your-assistant-id", + "numberDesiredAreaCode": "415" }' ``` - - ```bash - curl -X PATCH "https://api.vapi.ai/phone-number/{phone-number-id}" \ - -H "Authorization: Bearer your-api-key" \ - -H "Content-Type: application/json" \ - -d '{ - "assistantId": "your-assistant-id" - }' - ``` - + @@ -405,58 +290,30 @@ vapi assistant create ```typescript - async function makeOutboundCall(assistantId: string, phoneNumber: string) { - try { - const call = await vapi.calls.create({ - assistant: { - assistantId: assistantId, - }, - phoneNumberId: 'your-phone-number-id', // Your Vapi phone number ID - customer: { - number: phoneNumber, // Target phone number - }, - }); - - console.log('Outbound call initiated:', call.id); - return call; - } catch (error) { - console.error('Error making outbound call:', error); - throw error; - } - } - - // Make a call to your own number for testing - makeOutboundCall('your-assistant-id', '+1234567890'); + const call = await vapi.calls.create({ + assistant: { assistantId: 'your-assistant-id' }, + phoneNumberId: 'your-phone-number-id', + customer: { number: '+1234567890' }, + }); + console.log(call.id); ``` ```python - def make_outbound_call(assistant_id: str, phone_number: str): - try: - call = client.calls.create( - assistant_id=assistant_id, - phone_number_id="your-phone-number-id", # Your Vapi phone number ID - customer={ - "number": phone_number, # Target phone number - }, - ) - - print(f"Outbound call initiated: {call.id}") - return call - except Exception as error: - print(f"Error making outbound call: {error}") - raise error - - # Make a call to your own number for testing - make_outbound_call("your-assistant-id", "+1234567890") + call = client.calls.create( + assistant_id="your-assistant-id", + phone_number_id="your-phone-number-id", + customer={"number": "+1234567890"}, + ) + print(call.id) ``` ```bash curl -X POST "https://api.vapi.ai/call" \ - -H "Authorization: Bearer your-api-key" \ + -H "Authorization: Bearer $VAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "assistant": { From d3c9bc36fad39cb425835c67cc01aa3c476e71d9 Mon Sep 17 00:00:00 2001 From: Dan Goosewin Date: Tue, 19 Aug 2025 22:38:35 -0700 Subject: [PATCH 2/2] fix: replace `voice_id` with `voiceId` in examples --- fern/assistants/examples/docs-agent.mdx | 6 +-- fern/assistants/examples/inbound-support.mdx | 6 +-- fern/assistants/examples/voice-widget.mdx | 4 +- fern/quickstart/phone.mdx | 40 +++++++++----------- fern/quickstart/web.mdx | 4 +- 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/fern/assistants/examples/docs-agent.mdx b/fern/assistants/examples/docs-agent.mdx index 6326858c4..fd2b1c896 100644 --- a/fern/assistants/examples/docs-agent.mdx +++ b/fern/assistants/examples/docs-agent.mdx @@ -137,7 +137,7 @@ Guidelines: // Configure voice settings voice={ "provider": "vapi", - "voice_id": "Harry" + "voiceId": "Harry" }, // Configure transcription transcriber={ @@ -274,7 +274,7 @@ Guidelines: // Configure voice settings voice: { provider: "vapi", - voice_id: "Harry" + voiceId: "Harry" }, // Configure transcription transcriber: { @@ -341,7 +341,7 @@ Guidelines: // Configure voice settings voice={ "provider": "vapi", - "voice_id": "Harry" + "voiceId": "Harry" }, // Configure transcription transcriber={ diff --git a/fern/assistants/examples/inbound-support.mdx b/fern/assistants/examples/inbound-support.mdx index ab8fbac3a..d0b726861 100644 --- a/fern/assistants/examples/inbound-support.mdx +++ b/fern/assistants/examples/inbound-support.mdx @@ -159,7 +159,7 @@ We will be creating a customer support agent for VapiBank, a bank that wants to }, voice: { provider: "11labs", - voice_id: "burt" + voiceId: "burt" } }); @@ -193,7 +193,7 @@ We will be creating a customer support agent for VapiBank, a bank that wants to }, "voice": { "provider": "11labs", - "voice_id": "burt" + "voiceId": "burt" } } @@ -222,7 +222,7 @@ We will be creating a customer support agent for VapiBank, a bank that wants to }, "voice": { "provider": "11labs", - "voice_id": "burt" + "voiceId": "burt" } }' ``` diff --git a/fern/assistants/examples/voice-widget.mdx b/fern/assistants/examples/voice-widget.mdx index 1f2fb4d14..98f61202e 100644 --- a/fern/assistants/examples/voice-widget.mdx +++ b/fern/assistants/examples/voice-widget.mdx @@ -382,7 +382,7 @@ const EcommerceSupportWidget = () => { greeting: 'Hi! Need help with your order?', voice: { provider: 'playht', - voice_id: 'jennifer', + voiceId: 'jennifer', }, }} /> @@ -403,7 +403,7 @@ const HealthcareWidget = () => { greeting: 'Hello! I can help schedule your appointment.', voice: { provider: 'playht', - voice_id: 'jennifer', + voiceId: 'jennifer', }, }} /> diff --git a/fern/quickstart/phone.mdx b/fern/quickstart/phone.mdx index d74bd7b2f..b30171c43 100644 --- a/fern/quickstart/phone.mdx +++ b/fern/quickstart/phone.mdx @@ -105,7 +105,7 @@ vapi assistant create model: 'gpt-4o', messages: [{ role: 'system', content: 'You are Alex, a customer service voice assistant for TechSolutions.' }] }, - voice: { provider: '11labs', voice_id: 'cgSgspJ2msm6clMCkdW9' }, + voice: { provider: '11labs', voiceId: 'cgSgspJ2msm6clMCkdW9' }, firstMessage: 'Hi there, this is Alex from TechSolutions customer support. How can I help you today?' }); @@ -137,7 +137,7 @@ vapi assistant create "model": "gpt-4o", "messages": [{"role": "system", "content": "You are Alex, a customer service voice assistant for TechSolutions."}], }, - voice={"provider": "11labs", "voice_id": "cgSgspJ2msm6clMCkdW9"}, + voice={"provider": "11labs", "voiceId": "cgSgspJ2msm6clMCkdW9"}, first_message="Hi there, this is Alex from TechSolutions customer support. How can I help you today?", ) @@ -161,7 +161,7 @@ vapi assistant create "model": "gpt-4o", "messages": [{ "role": "system", "content": "You are Alex, a customer service voice assistant for TechSolutions." }] }, - "voice": { "provider": "11labs", "voice_id": "cgSgspJ2msm6clMCkdW9" }, + "voice": { "provider": "11labs", "voiceId": "cgSgspJ2msm6clMCkdW9" }, "firstMessage": "Hi there, this is Alex from TechSolutions customer support. How can I help you today?" }' ``` @@ -273,21 +273,19 @@ vapi assistant create Call the phone number you just created. Your assistant will pick up and start the conversation with your configured first message. - - **Using the Dashboard:** - - In the dashboard, go to the outbound calls section: - 1. Enter your own phone number as the target - 2. Select your assistant - 3. Click "Make Call" - - - - - - **Using the SDK:** - + + + In the dashboard, go to the outbound calls section: + 1. Enter your own phone number as the target + 2. Select your assistant + 3. Click "Make Call" + + + + + + ```typescript const call = await vapi.calls.create({ @@ -316,13 +314,9 @@ vapi assistant create -H "Authorization: Bearer $VAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ - "assistant": { - "assistantId": "your-assistant-id" - }, + "assistant": { "assistantId": "your-assistant-id" }, "phoneNumberId": "your-phone-number-id", - "customer": { - "number": "+1234567890" - } + "customer": { "number": "+1234567890" } }' ``` diff --git a/fern/quickstart/web.mdx b/fern/quickstart/web.mdx index 5287a91b0..c616563af 100644 --- a/fern/quickstart/web.mdx +++ b/fern/quickstart/web.mdx @@ -676,7 +676,7 @@ Automate outbound calls and handle inbound call processing with server-side SDKs }, voice={ "provider": "11labs", - "voice_id": "21m00Tcm4TlvDq8ikWAM" + "voiceId": "21m00Tcm4TlvDq8ikWAM" } ) ``` @@ -720,7 +720,7 @@ Automate outbound calls and handle inbound call processing with server-side SDKs }, voice: { provider: "11labs", - voice_id: "21m00Tcm4TlvDq8ikWAM" + voiceId: "21m00Tcm4TlvDq8ikWAM" } ) ```