Create Assistant via API to then initiate call
# support
j
Hi all, I'm wondering if this is possible. I have a brief from a client and first I want to ask if this is possible and if it is, maybe you can guide me a little bit into achieving this setup. I’ll be using N8N and Vapi in this setup. 1. N8N receives via webhook a phone number and a website. 2. N8N automation scrapes that website for some basic information 3. N8N + OpenAI generates a KB document for Vapi Assistant 4. N8N + OpenAI generates a System Prompt for the Vapi Assistant 5. N8N creates the Assistant in Vapi using the System Prompt data, configures the model, recording, transcription and other needed steps (I don’t know what will be needed yet) and attaches a Vapi / Twilio number. 6. N8N creates a KB in Vap and attaches it to the Assistant. 7. Vapi calls back the number received via webhook at step 1. This is the setup, is this possible? Thank you!
@Vapi Support Bot how do I create an assistant via API, give me a sample json
v
Yes, your proposed workflow is possible with Vapi's API. Here's how to create an assistant and attach a KB:
Copy code
bash
# 1. Create Assistant
curl -X POST https://api.vapi.ai/assistant \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Assistant",
    "firstMessage": "Hello, how can I help?",
    "model": {
      "provider": "openai",
      "model": "gpt-4o",
      "messages": [
        {
          "role": "system",
          "content": "Your system prompt here"
        }
      ]
    }
  }'
After creating the assistant, you can attach a KB and initiate calls using similar API endpoints. Sources: - [Creating an Assistant via API](https://docs.vapi.ai/api-reference/assistants/create-assistant) - [Creating a KB in Vapi](https://docs.vapi.ai/knowledge-base) - [Initiating a call with a Vapi Assistant](https://docs.vapi.ai/documentation/advanced-concepts/customization/custom-transcriber)
To create a Vapi Assistant via API, use a POST request to
https://api.vapi.ai/assistant
with your auth token in the header. Here's a sample JSON payload:
Copy code
json
{
  "name": "My Assistant",
  "model": {
    "provider": "openai",
    "model": "gpt-4o",
    "systemPrompt": "You're a helpful assistant"
  },
  "voice": {
    "provider": "azure",
    "voiceId": "emma"
  },
  "firstMessage": "Hi, how can I help you today?"
}
Sources: - [API Reference Create Assistant](https://docs.vapi.ai/api-reference/assistants/create-assistant) - [Customization Custom Keywords](https://docs.vapi.ai/customization/custom-keywords)
j
@Vapi Support Bot in this workflow please describe all steps involving vapi step by step with code: I’ll be using N8N and Vapi in this setup. N8N receives via webhook a phone number and a website. N8N automation scrapes that website for some basic information N8N + OpenAI generates a KB document for Vapi Assistant N8N + OpenAI generates a System Prompt for the Vapi Assistant N8N creates the Assistant in Vapi using the System Prompt data, configures the model, recording, transcription and other needed steps (I don’t know what will be needed yet) and attaches a Vapi / Twilio number. N8N creates a KB in Vap and attaches it to the Assistant. Vapi calls back the number received via webhook at step 1.
v
Here's how to create a Vapi Assistant with custom model, transcription, and recording settings:
Copy code
bash
curl -X POST https://api.vapi.ai/assistant \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Website Assistant",
    "model": {
      "provider": "openai",
      "model": "gpt-4o",
      "systemPrompt": "YOUR_GENERATED_SYSTEM_PROMPT"
    },
    "transcriber": {
      "provider": "deepgram",
      "model": "nova-2",
      "language": "en"
    },
    "recordingEnabled": true,
    "firstMessage": "Hello, I'm your website assistant."
  }'
After creating the assistant, you'll need to attach a phone number and KB separately. Sources: - [Creating an assistant via API](https://docs.vapi.ai/api-reference/assistants/create-assistant) - [Configuring transcription settings](https://discord.com/channels/1211482211119796234/1331035264751112202)
j
@Vapi Support Bot how do I attach a phone number to the assistant via API
v
To attach a phone number to your Vapi Assistant, use the
POST /phone-number
endpoint:
Copy code
bash
curl --location 'https://api.vapi.ai/phone-number' \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "provider": "vapi",
        "sipUri": "sip:username@sip.vapi.ai",
        "assistantId": "YOUR_ASSISTANT_ID"
    }'
Replace
YOUR_ASSISTANT_ID
with the ID of your created assistant. Sources: - [Vapi API Documentation](https://docs.vapi.ai/advanced/sip) - [Vapi API Reference](https://docs.vapi.ai/api-reference/phone-numbers/create)
j
@Vapi Support Bot I created a file using this command: curl -X POST https://api.vapi.ai/file \ -H "Authorization: Bearer 8b2a07b4-7003-4e11-9739-a2dxxxxxxxxxxxx" \ -H "Content-Type: multipart/form-data" \ -F file=@"kb.txt;type=text/plain" now, how do I make sure I attach this file to my agent, give me the full code to do it via api
v
To attach your uploaded file to your assistant, you need to update the assistant configuration with a PATCH request:
Copy code
bash
curl -X PATCH https://api.vapi.ai/assistant/YOUR_ASSISTANT_ID \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
  "model": {
    "provider": "openai",
    "model": "gpt-4o",
    "knowledgeBaseId": "YOUR_KNOWLEDGE_BASE_ID"
  }
}'
Make sure to include all previously used properties in the model object (like system prompt) to avoid overwriting them. Sources: - [Knowledge Base Documentation](https://docs.vapi.ai/knowledge-base) - [Discord Channel Discussion](https://discord.com/channels/1211482211119796234/1333975440003563604)
k
Yes it's possible by involving steps like receiving data via webhook, scraping the website, generating a knowledge base and system prompt with OpenAI, creating and configuring an assistant in Vapi, and initiating an outbound call to the provided phone number..
j
@Kings_big💫 I can't seem to figure out knowledgebaseID.... is that the ID of a file I upload in Files? Because that's what I need, after creating the KB file, upload it and attach it into the assistant.
k
The knowledgebaseID refers to the ID of a created knowledge base (not the file itself); you upload your file into that knowledge base, then attach its ID to your assistant.
4 Views