Ruby gem for integrating with the VAPI voice AI platform. Supports assistants, calls, phone numbers, squads, tools, files, knowledge bases, logs, and analytics.
Installation
Add to your Gemfile:
gem 'vapi-ruby'Then run:
bundle installOr install directly:
gem install vapi-rubyConfiguration
Vapi.configure do |config|
config.api_key = ENV['VAPI_API_KEY']
# Optional
config.timeout = 30 # seconds, default
endUsage
All resources can be initialized without arguments (uses Vapi.client by default) or with an explicit client.
Assistants
assistants = Vapi::Assistant.new
# List all assistants
assistants.list
# List with filters
assistants.list(limit: 10, createdAtGt: '2024-01-01T00:00:00Z')
# Get an assistant
assistants.find('assistant_id')
# Create an assistant
assistants.create(
name: 'Sales Agent',
model: { provider: 'openai', model: 'gpt-4' },
voice: { provider: 'vapi', voiceId: 'Tara' },
firstMessage: 'Hello! How can I help you today?'
)
# Update an assistant
assistants.update('assistant_id', name: 'Updated Name')
# Delete an assistant
assistants.delete('assistant_id')Calls
calls = Vapi::Call.new
# List all calls
calls.list
# Filter by assistant
calls.list(assistantId: 'assistant_id')
# Get a call
calls.find('call_id')
# Create an outbound call
calls.create(
assistantId: 'assistant_id',
phoneNumberId: 'phone_number_id',
customer: { number: '+1234567890' }
)
# Update a call
calls.update('call_id', name: 'Follow-up Call')
# Delete a call
calls.delete('call_id')Phone Numbers
phone_numbers = Vapi::PhoneNumber.new
# List phone numbers
phone_numbers.list
# Get a phone number
phone_numbers.find('phone_number_id')
# Create a phone number
phone_numbers.create(
provider: 'twilio',
number: '+1234567890',
twilioAccountSid: 'sid',
twilioAuthToken: 'token'
)
# Update a phone number
phone_numbers.update('phone_number_id', name: 'Main Line')
# Delete a phone number
phone_numbers.delete('phone_number_id')Squads
squads = Vapi::Squad.new
# List squads
squads.list
# Get a squad
squads.find('squad_id')
# Create a squad
squads.create(
name: 'Sales Team',
members: [{ assistantId: 'assistant_id' }]
)
# Update a squad
squads.update('squad_id', name: 'Updated Team')
# Delete a squad
squads.delete('squad_id')Tools
tools = Vapi::Tool.new
# List tools
tools.list
# Get a tool
tools.find('tool_id')
# Create a tool
tools.create(
type: 'function',
function: {
name: 'lookup_order',
description: 'Look up an order by ID',
parameters: { type: 'object', properties: { orderId: { type: 'string' } } }
}
)
# Update a tool
tools.update('tool_id', function: { name: 'updated_lookup' })
# Delete a tool
tools.delete('tool_id')Files
files = Vapi::File.new
# List files
files.list
# Get a file
files.find('file_id')
# Upload a file
files.create(name: 'training_data.pdf')
# Update a file
files.update('file_id', name: 'renamed.pdf')
# Delete a file
files.delete('file_id')Knowledge Bases
knowledge_bases = Vapi::KnowledgeBase.new
# List knowledge bases
knowledge_bases.list
# Get a knowledge base
knowledge_bases.find('knowledge_base_id')
# Create a knowledge base
knowledge_bases.create(
name: 'Product FAQ',
provider: 'trieve'
)
# Update a knowledge base
knowledge_bases.update('knowledge_base_id', name: 'Updated FAQ')
# Delete a knowledge base
knowledge_bases.delete('knowledge_base_id')Logs
logs = Vapi::Log.new
# List all logs
logs.list
# Filter by call
logs.list(callId: 'call_id')Analytics
analytics = Vapi::Analytics.new
# Query analytics
analytics.query(
queries: [
{
name: 'total_calls',
table: 'call',
operations: [{ operation: 'count', column: 'id' }]
}
]
)Using Multiple Clients
config1 = Vapi::Configuration.new
config1.api_key = 'key_for_org_1'
client1 = Vapi::Client.new(config1)
config2 = Vapi::Configuration.new
config2.api_key = 'key_for_org_2'
client2 = Vapi::Client.new(config2)
# Use explicit clients
Vapi::Assistant.new(client1).list
Vapi::Assistant.new(client2).listError Handling
begin
calls.create(assistantId: 'invalid')
rescue Vapi::ConfigurationError => e
# Missing API key
rescue Vapi::AuthenticationError => e
# Invalid API key
rescue Vapi::ValidationError => e
puts e.errors
rescue Vapi::NotFoundError => e
# 404 - Resource not found
rescue Vapi::RateLimitError => e
puts e.retry_after # Seconds to wait
rescue Vapi::APIError => e
puts e.status_code
puts e.response_body
endDevelopment
# Install dependencies
bundle install
# Run tests
bundle exec rspec
# Run linter
bundle exec rubocopContributing
Bug reports and pull requests are welcome on GitHub. See CONTRIBUTING.md for details.
License
The gem is available as open source under the terms of the MIT License.