Skip to main content

module  pixeltable.functions.bfl

Pixeltable UDFs that wrap Black Forest Labs (BFL) FLUX image generation API. In order to use them, the API key must be specified either with BFL_API_KEY environment variable, or as api_key in the bfl section of the Pixeltable config file. For more information on FLUX models, see the BFL documentation.

udf  edit()

Signature
@pxt.udf
edit(
    prompt: pxt.String,
    image: pxt.Image,
    *,
    model: pxt.String,
    reference_images: pxt.Json | None = None,
    width: pxt.Int | None = None,
    height: pxt.Int | None = None,
    seed: pxt.Int | None = None,
    safety_tolerance: pxt.Int | None = None,
    output_format: pxt.String | None = None,
    steps: pxt.Int | None = None,
    guidance: pxt.Float | None = None
) -> pxt.Image
Edit an image using FLUX models with text prompts and optional reference images. This UDF wraps the BFL FLUX image editing API. For more information, refer to the official API documentation. Parameters:
  • prompt (pxt.String): Text description of the edit to apply.
  • image (pxt.Image): The base image to edit.
  • model (pxt.String): The FLUX model to use for editing. See available models at https://docs.bfl.ai/.
  • reference_images (pxt.Json | None): Additional reference images (up to 7) for multi-reference editing.
  • width (pxt.Int | None): Output width in pixels (multiple of 16). Matches input if not specified.
  • height (pxt.Int | None): Output height in pixels (multiple of 16). Matches input if not specified.
  • seed (pxt.Int | None): Random seed for reproducible results.
  • safety_tolerance (pxt.Int | None): Moderation level from 0 (strict) to 6 (permissive). Default 2.
  • output_format (pxt.String | None): Image format, ‘jpeg’ or ‘png’. Default ‘jpeg’.
  • steps (pxt.Int | None): Number of inference steps (flux-2-flex only, max 50).
  • guidance (pxt.Float | None): Guidance scale 1.5-10 (flux-2-flex only). Default 4.5.
Returns:
  • pxt.Image: An edited PIL Image.
Examples: Edit an image to change its background:
t.add_computed_column(
    edited=bfl.edit(
        'Change the background to a sunset beach',
        t.original_image,
        model='flux-2-pro',
    )
)
Multi-reference editing with additional images:
t.add_computed_column(
    edited=bfl.edit(
        'Combine the person from the first image with the background from the second',
        t.person_image,
        model='flux-kontext-pro',
        reference_images=[t.background_image],
    )
)

udf  expand()

Signature
@pxt.udf
expand(
    prompt: pxt.String,
    image: pxt.Image,
    *,
    model: pxt.String,
    top: pxt.Int = 0,
    bottom: pxt.Int = 0,
    left: pxt.Int = 0,
    right: pxt.Int = 0,
    seed: pxt.Int | None = None,
    safety_tolerance: pxt.Int | None = None,
    output_format: pxt.String | None = None
) -> pxt.Image
Expand an image by adding pixels on any side using FLUX Expand models. Outpaint an image by specifying how many pixels to add to each edge. The expansion maintains context from the original image. This UDF wraps the BFL FLUX Expand API. For more information, refer to the official API documentation. Parameters:
  • prompt (pxt.String): Text description to guide the expansion.
  • image (pxt.Image): The base image to expand.
  • model (pxt.String): The FLUX Expand model to use. See available models at https://docs.bfl.ai/.
  • top (pxt.Int): Pixels to add to the top edge.
  • bottom (pxt.Int): Pixels to add to the bottom edge.
  • left (pxt.Int): Pixels to add to the left edge.
  • right (pxt.Int): Pixels to add to the right edge.
  • seed (pxt.Int | None): Random seed for reproducible results.
  • safety_tolerance (pxt.Int | None): Moderation level from 0 (strict) to 6 (permissive). Default 2.
  • output_format (pxt.String | None): Image format, ‘jpeg’ or ‘png’. Default ‘jpeg’.
Returns:
  • pxt.Image: An expanded PIL Image.
Examples: Expand an image to create a wider landscape:
t.add_computed_column(
    wide=bfl.expand(
        'Continue the landscape scenery',
        t.original_image,
        model='flux-pro-1.0-expand',
        left=256,
        right=256,
    )
)

udf  fill()

Signature
@pxt.udf
fill(
    prompt: pxt.String,
    image: pxt.Image,
    mask: pxt.Image,
    *,
    model: pxt.String,
    steps: pxt.Int | None = None,
    guidance: pxt.Float | None = None,
    seed: pxt.Int | None = None,
    safety_tolerance: pxt.Int | None = None,
    output_format: pxt.String | None = None
) -> pxt.Image
Inpaint an image using FLUX Fill models. Fill specified areas of an image based on a mask and text prompt. The mask can be a separate image or applied to the alpha channel of the input image. This UDF wraps the BFL FLUX Fill API. For more information, refer to the official API documentation. Parameters:
  • prompt (pxt.String): Text description of what to fill in the masked area.
  • image (pxt.Image): The base image to inpaint.
  • mask (pxt.Image): Mask image where white areas indicate regions to fill (black areas preserved).
  • model (pxt.String): The FLUX Fill model to use. See available models at https://docs.bfl.ai/.
  • steps (pxt.Int | None): Number of inference steps (max 50). Default 50.
  • guidance (pxt.Float | None): Guidance scale for generation. Default 30.
  • seed (pxt.Int | None): Random seed for reproducible results.
  • safety_tolerance (pxt.Int | None): Moderation level from 0 (strict) to 6 (permissive). Default 2.
  • output_format (pxt.String | None): Image format, ‘jpeg’ or ‘png’. Default ‘jpeg’.
Returns:
  • pxt.Image: An inpainted PIL Image.
Examples: Fill a masked region with generated content:
t.add_computed_column(
    filled=bfl.fill(
        'A beautiful garden with flowers',
        t.original_image,
        t.mask_image,
        model='flux-pro-1.0-fill',
    )
)

udf  generate()

Signature
@pxt.udf
generate(
    prompt: pxt.String,
    *,
    model: pxt.String,
    width: pxt.Int | None = None,
    height: pxt.Int | None = None,
    seed: pxt.Int | None = None,
    safety_tolerance: pxt.Int | None = None,
    output_format: pxt.String | None = None,
    steps: pxt.Int | None = None,
    guidance: pxt.Float | None = None
) -> pxt.Image
Generate an image from a text prompt using FLUX models. This UDF wraps the BFL FLUX API endpoints. For more information, refer to the official API documentation. Parameters:
  • prompt (pxt.String): Text description of the image to generate.
  • model (pxt.String): The FLUX model to use. See available models at https://docs.bfl.ai/.
  • width (pxt.Int | None): Output width in pixels (multiple of 16). Default 1024.
  • height (pxt.Int | None): Output height in pixels (multiple of 16). Default 1024.
  • seed (pxt.Int | None): Random seed for reproducible results.
  • safety_tolerance (pxt.Int | None): Moderation level from 0 (strict) to 6 (permissive). Default 2.
  • output_format (pxt.String | None): Image format, ‘jpeg’ or ‘png’. Default ‘jpeg’.
  • steps (pxt.Int | None): Number of inference steps (flux-2-flex only, max 50).
  • guidance (pxt.Float | None): Guidance scale 1.5-10 (flux-2-flex only). Default 4.5.
Returns:
  • pxt.Image: A generated PIL Image.
Examples: Generate images using default dimensions:
t.add_computed_column(image=bfl.generate(t.prompt, model='flux-2-pro'))
Generate with custom dimensions:
t.add_computed_column(
    image=bfl.generate(
        t.prompt, model='flux-2-pro', width=1920, height=1080
    )
)
Generate with specific seed for reproducibility:
t.add_computed_column(
    image=bfl.generate(t.prompt, model='flux-2-pro', seed=42)
)
Last modified on March 15, 2026