Ruby SDK
The official Vidiking Ruby SDK. Requires Ruby 3.0+.
Installation
gem install vidiai
Or add to your Gemfile:
gem 'vidiking'
Setup
require 'vidiking'
client = Vidiking::Client.new(
api_key: ENV['VIDIKING_API_KEY'],
sandbox: false
)
Video Rendering
Render
result = client.render(
timeline: {
background: '#000000',
tracks: [
{
clips: [
{
asset: { type: 'title', text: 'Hello World', style: 'minimal', size: 'large' },
start: 0,
length: 5
}
]
}
]
},
output: { format: 'mp4', resolution: 'hd' }
)
puts "Job ID: #{result.job_id}"
Get Render Status
job = client.get_render(result.job_id)
puts job.status # QUEUED | PROCESSING | COMPLETE | FAILED
puts job.url # Available when COMPLETE
Poll Until Complete
job = client.poll_job(result.job_id, interval: 3, timeout: 300)
puts "Output: #{job.url}"
Stitch
result = client.stitch(
clips: [
{ src: 'https://example.com/intro.mp4' },
{ src: 'https://example.com/main.mp4', trim: 5, length: 30 },
{ src: 'https://example.com/outro.mp4' }
],
output: { format: 'mp4', resolution: 'hd' }
)
Trim
result = client.trim(
src: 'https://example.com/video.mp4',
start: 10,
length: 20,
output: { format: 'mp4', resolution: 'hd' }
)
AI Features
Image Generation
image = client.ai.generate_image(
prompt: 'A mountain landscape at sunset',
model: 'flux',
width: 1920,
height: 1080
)
puts image.url
Video Generation
result = client.ai.generate_video(
prompt: 'Aerial shot of ocean waves',
model: 'runway-gen4-turbo',
duration: 5
)
job = client.poll_job(result.job_id)
puts job.url
Voiceover
voiceover = client.ai.generate_voiceover(
text: 'Welcome to our product tour.',
voice: 'rachel',
model: 'elevenlabs-flash'
)
puts "#{voiceover.url} (#{voiceover.duration}s)"
Templates
# List templates
templates = client.templates.list(category: 'marketing')
# Render template
result = client.templates.render('tpl_promo_001',
merge_fields: {
headline: 'Big Sale',
product_image: 'https://example.com/product.png'
},
output: { format: 'mp4', resolution: 'hd' }
)
Error Handling
begin
client.render(...)
rescue Vidiking::InsufficientFundsError => e
puts "Not enough balance: #{e.balance}"
rescue Vidiking::RateLimitError => e
puts "Rate limited. Retry after: #{e.retry_after}s"
rescue Vidiking::Error => e
puts "API error: #{e.code} - #{e.message}"
end
Configuration
client = Vidiking::Client.new(
api_key: 'your_api_key',
sandbox: false,
base_url: 'https://api.vidiking.com',
timeout: 30,
max_retries: 3
)