Skip to main content

Fal Integration

Generate high-quality images from text prompts using Fal.ai's advanced AI image generation models.


Timbal integrates with Fal.ai to enable AI-powered image generation. This integration allows you to generate high-quality images from text prompts using various models.

Prerequisites

Before using the Fal integration, you'll need:

  1. A Fal.ai account
  2. An API key from your Fal.ai dashboard
  3. Set the FAL_KEY environment variable with your API key

Authentication Setup

Set your Fal.ai API key as an environment variable: FAL_KEY="your-api-key-here"

Installation

Install the requirements by doing:

uv add timbal[steps-fal]

Generate Images

Description

The gen_images step allows you to generate images from text prompts using Fal.ai's models.

Example

from timbal.steps.fal.text_to_image import gen_images
# Generate a single image
images = await gen_images(
prompt="a green ferrari",
model="fal-ai/flux-pro/v1.1-ultra"
)
# Returns a File object with the image URL
image = images[0]

Parameters

ParameterTypeDescriptionRequired
promptstrThe text prompt to generate an image fromYes
modelstrThe model to use for image generation. Default: "fal-ai/flux-pro/v1.1-ultra"No

Agent Integration Example

from timbal.steps.fal.text_to_image import gen_images
from timbal import Agent
agent = Agent(
tools=[gen_images]
)
response = await agent.complete(
prompt={
"prompt": "a futuristic cityscape at night",
"model": "fal-ai/flux-pro/v1.1-ultra"
}
)

Notes

  • Make sure your Fal.ai API key is properly set in the environment variables
  • The default model (fal-ai/flux-pro/v1.1-ultra) costs approximately $0.06 per image
  • The function returns a list of File objects containing the generated image URLs
  • Images are generated asynchronously and the function will wait for completion
  • For more advanced usage and available models, see the Fal.ai documentation