ModelsLabs
ModelsLabTools generates images, video, and audio from text prompts using the ModelsLab API.
Prerequisites
You need to install the requests and openai libraries.
uv pip install agno requests openaiSet the MODELS_LAB_API_KEY environment variable.
export MODELS_LAB_API_KEY=****Example
The following agents use ModelsLabs to generate images, videos, and audio from text prompts.
from agno.agent import Agent
from agno.models.response import FileType
from agno.tools.models_labs import ModelsLabTools
from agno.utils.media import download_audio
from agno.utils.pprint import pprint_run_response
# Create an image agent (PNG, using the Flux model)
image_agent = Agent(
tools=[
ModelsLabTools(file_type=FileType.PNG, model_id="flux", width=1024, height=1024)
],
send_media_to_model=False,
)
# Create a video agent (set to make MP4)
video_agent = Agent(
tools=[ModelsLabTools(file_type=FileType.MP4)], send_media_to_model=False
)
# Create audio agent (set to make WAV)
audio_agent = Agent(
tools=[ModelsLabTools(file_type=FileType.WAV)], send_media_to_model=False
)
# Generate an image
image_response = image_agent.run(
"Generate an image of a beautiful sunset over the ocean"
)
pprint_run_response(image_response, markdown=True)
# Generate a sound effect
response = audio_agent.run("Generate a SFX of a ocean wave", markdown=True)
pprint_run_response(response, markdown=True)
if response.audio and response.audio[0].url:
download_audio(
url=response.audio[0].url,
output_path="./tmp/nature.wav",
)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | The ModelsLab API key for authentication. Uses MODELS_LAB_API_KEY if not set |
wait_for_completion | bool | False | Attempts polling; see the current completion limitation below |
add_to_eta | int | 15 | Time to add to the ETA to account for the time it takes to fetch the video |
max_wait_time | int | 60 | Maximum time to wait for the video to be ready |
file_type | FileType | FileType.MP4 | The type of file to generate (MP4, GIF, PNG, JPG, WAV, MP3) |
model_id | Optional[str] | None | ModelsLab model ID. Defaults per file type (flux for images, cogvideox for video) |
width | int | 512 | Image/video width; not used for audio requests |
height | int | 512 | Image/video height; not used for audio requests |
Toolkit Functions
| Function | Description |
|---|---|
generate_media | Generates media (video, GIF, image, or audio) based on a text prompt |
Completion and downloads
Generation can return a future media URL while the provider job is still processing. The current adapter's polling path uses a newly generated UUID instead of the provider's job ID, and can return a success message after polling times out. Setting wait_for_completion=True does not resolve this issue.
Do not treat the immediate download in the cookbook as proof that the asset is ready. For a workflow that must wait for completion, submit and poll through the provider API using its returned job ID before downloading; see ModelsLab fetch. The Agno adapter does not currently expose that provider job ID in its result.