fal-client

0.13.2 · active · verified Sat Apr 11

The `fal-client` library is a Python client for fal.ai, providing a streamlined interface to interact with machine learning models deployed on the fal.ai platform. It abstracts away authentication, handles retries, and offers a clean API for various inference methods, including synchronous and asynchronous calls. Currently at version 0.13.2, the library maintains an active development and release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform a synchronous inference call using the `fal-client`. It requires the `FAL_KEY` environment variable to be set for authentication with fal.ai.

import fal_client
import os

# Ensure FAL_KEY is set in your environment (e.g., export FAL_KEY="YOUR_API_KEY")
# Get your API key from fal.ai
fal_key = os.environ.get('FAL_KEY', '')
if not fal_key:
    print("Warning: FAL_KEY environment variable not set. Please configure your API key for fal.ai.")

# Example of synchronous inference using a public model
try:
    response = fal_client.run(
        "fal-ai/fast-sdxl",
        arguments={
            "prompt": "a cute cat, realistic, orange, 4k"
        }
    )
    if response and "images" in response and response["images"]:
        print(f"Generated image URL: {response['images'][0]['url']}")
    else:
        print("No image URL found in the response.")
except Exception as e:
    print(f"An error occurred during inference: {e}")

view raw JSON →