Image to Video AI Ruby
A small Ruby client for the Image to Video AI generator. It creates image-to-video tasks, polls task status, and returns generated video URLs. The gem uses only the Ruby standard library at runtime.
Installation
gem install image_to_video_ai
Or add it to your Gemfile:
gem "image_to_video_ai", "~> 0.1"
Create an API key in your Image to Video AI account, then keep it outside source control:
export IMAGE_TO_VIDEO_AI_API_KEY="your_api_key"
Create a video
The input image must be available through a public HTTPS URL.
require "image_to_video_ai"
client = ImageToVideoAI::Client.new
task = client.create_video(
image_url: "https://example.com/start-frame.jpg",
prompt: "Slow camera push-in while the subject turns toward the light",
model: "seedance-1.5-pro",
duration: 5,
aspect_ratio: "16:9"
)
puts "Created #{task.task_id} with status #{task.status}"
Query or wait for the result
task = client.result(task_id: task.task_id)
finished = client.wait_for_result(
task_id: task.task_id,
interval: 5,
timeout: 600
)
if finished.successful?
puts finished.url
else
warn "Generation ended with status: #{finished.status}"
end
Optional generation controls
create_video also accepts resolution, generate_audio, tail_image_url, and audio_url. Model capabilities and credit costs vary; unsupported parameter combinations are returned as structured API errors.
begin
client.create_video(image_url: "https://example.com/frame.jpg", prompt: "Pan left")
rescue ImageToVideoAI::APIError => error
warn "#{error.status}: #{error.} (API code #{error.code})"
end
Development
Run tests without real credentials or network requests:
ruby -Ilib test/client_test.rb
Build the gem locally:
gem build image_to_video_ai.gemspec
Security
- Never commit API keys.
- Load
IMAGE_TO_VIDEO_AI_API_KEYfrom the environment or a secret manager. - The client sends the key only in the
Authorization: Bearerheader. - Tests use an injected fake transport and contain no credentials.
License
MIT