A client library for the Luma Labs API, providing a simple and intuitive interface for Elixir applications to interact with Luma Labs services.
Add lumaai_ex
to your list of dependencies in mix.exs
:
def deps do
[
{:lumaai_ex, "~> 0.1.1"}
]
end
To use the Luma Labs API, you need an API key. Sign up for an account on the Luma Labs website to obtain your key.
- Get a key from https://lumalabs.ai/dream-machine/api/keys
- Pass it to the
LumaaiEx
client by either:- Setting the
LUMAAI_API_KEY
environment variable - Passing
auth_token
to theLumaaiEx.new
function
- Setting the
Using LUMAAI_API_KEY
env variable:
lumaai = LumaaiEx.new()
Using auth_token
parameter:
lumaai = LumaaiEx.new(auth_token: "your_auth_token")
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "A teddy bear in sunglasses playing electric guitar and dancing"
})
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "A teddy bear in sunglasses playing electric guitar and dancing",
loop: true,
aspect_ratio: "3:4"
})
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "Low-angle shot of a majestic tiger prowling through a snowy landscape, leaving paw prints on the white blanket",
keyframes: %{
frame0: %{
type: "image",
url: "https://storage.cdn-luma.com/dream_machine/7e4fe07f-1dfd-4921-bc97-4bcf5adea39a/video_0_thumb.jpg"
}
}
})
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "A teddy bear in sunglasses playing electric guitar and dancing",
keyframes: %{
frame0: %{
type: "generation",
id: "d1968551-6113-4b46-b567-09210c2e79b0"
}
}
})
{:ok, generation} = LumaaiEx.get_generation(lumaai, "d1968551-6113-4b46-b567-09210c2e79b0")
{:ok, generations} = LumaaiEx.list_generations(lumaai, limit: 100, offset: 0)
{:ok, _} = LumaaiEx.delete_generation(lumaai, "d1968551-6113-4b46-b567-09210c2e79b0")
{:ok, supported_camera_motions} = LumaaiEx.get_camera_motions(lumaai)
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "A teddy bear in sunglasses playing electric guitar and dancing",
callback_url: "https://your-api-endpoint.com/callback"
})
Right now, the only supported way is via polling. The create endpoint returns an id which is a UUID V4. You can use it to poll for updates (you can see the video at generation[:assets][:video]
).
defmodule GenerationPoller do
def poll_until_completed(lumaai, generation) do
case LumaaiEx.get_generation(lumaai, generation[:id]) do
{:ok, %{state: "completed", assets: %{video: video_url}}} ->
{:ok, video_url}
{:ok, %{state: "failed", failure_reason: reason}} ->
{:error, "Generation failed: #{reason}"}
{:ok, _} ->
IO.puts("Dreaming...")
Process.sleep(3000)
poll_until_completed(lumaai, generation)
{:error, reason} ->
{:error, reason}
end
end
end
{:ok, generation} = LumaaiEx.create_generation(lumaai, %{
prompt: "A teddy bear in sunglasses playing electric guitar and dancing"
})
case GenerationPoller.poll_until_completed(lumaai, generation) do
{:ok, video_url} ->
# Download the video
{:ok, %HTTPoison.Response{body: body}} = HTTPoison.get(video_url)
File.write!(~s(#{generation[:id]}.mp4), body)
IO.puts(~s(File downloaded as "#{generation[:id]}.mp4"))
{:error, reason} ->
IO.puts("Error: " <> reason)
end
For more information on available endpoints and parameters, refer to the Luma Labs API documentation.
Please find documentation on the HexDocs.
Contributions are welcome! Please feel free to submit a Pull Request.
Copyright (c) 2024 Vitaly Gorodetsky This project is licensed under the MIT License.