Download the PHP package shareaichat/fal-ai-php-image-generator without Composer

On this page you can find all versions of the php package shareaichat/fal-ai-php-image-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fal-ai-php-image-generator

fal.ai PHP SDK — AI Image Generator with FLUX.1 (Schnell / Dev / Kontext) & Stable Diffusion XL

Latest Version PHP Version Made with fal.ai Maintained by ShareAIChat

A lightweight, zero-dependency PHP library for generating AI images with the fal.ai API. Generate stunning images from text (text-to-image), edit existing images with natural-language instructions (image-to-image), produce multiple variations in one call, and download the results locally — all with a few lines of PHP.

This package wraps the most popular fal.ai image models — FLUX.1 Schnell, FLUX.1 Dev, FLUX.1 Kontext / Kontext Multi, and Stable Diffusion XL — behind a single clean interface, with per-model validation (for example the 12-step limit of FLUX.1 Schnell), typed results and detailed exceptions.

🚀 In production: This SDK powers the AI creation studio at ShareAIChat — the free AI art community to create, remix and share AI-generated artwork. See thousands of real FLUX.1 generations and remix them yourself at shareaichat.com.


Table of Contents


Why this library?

This SDK Writing raw cURL yourself
Zero dependencies ✅ PHP 8 + curl only —
FLUX.1 Schnell step limit handled ✅ Validates num_inference_steps <= 12 ❌ Confusing HTTP 422
Model-specific params ✅ guidance_scale only sent to models that accept it ❌ Easily rejected
Typed image results ✅ URL, width, height, content type ❌ Parse JSON manually
Batch & multi-image ✅ Built in ❌ DIY
Friendly errors ✅ Human-readable validation messages from fal.ai ❌ Raw JSON detail
Save to disk ✅ One method, follows redirects ❌ DIY

No Laravel, Symfony or framework required — it works in plain PHP, WordPress, Drupal, or any modern PHP project.


Requirements


Installation

Composer (recommended)

Without Composer (standalone)

Copy the src/ folder into your project and include the files directly:

Set your API key as an environment variable:


Quick Start — Generate an AI Image in 5 Lines

That's it — the returned URL points to a hosted PNG on fal.media that you can display, download or store immediately.


Supported Models

Model ID constant Best for Max images Steps Image-to-image
FLUX.1 Schnell Models::FLUX_SCHNELL Fast, cheap prototyping & bulk generation 4 ≤ 12 ❌
FLUX.1 Dev Models::FLUX_DEV High-quality text-to-image 4 ≤ 50 ✅
FLUX.1 Kontext Models::FLUX_KONTEXT Instruction-based image editing 1 ≤ 50 ✅
FLUX.1 Kontext Multi Models::FLUX_KONTEXT_MULTI Editing with multiple reference images 1 ≤ 50 ✅
Stable Diffusion XL Models::STABLE_DIFFUSION_XL Classic open-weights diffusion model 1 ≤ 50 ✅

FLUX.1 Schnell is the cheapest and fastest model and is ideal for AI art galleries, SEO content pipelines and prototypes. It produces great images in just 4 inference steps.


Usage

Text-to-Image (FLUX.1 Schnell — fast & cheap)

Higher Quality with FLUX.1 Dev

Generate Multiple Images

Get up to 4 variations in a single request (FLUX.1 Schnell / Dev):

Image-to-Image Editing with FLUX.1 Kontext

Pass a reference image URL plus an editing instruction:

Multiple reference images with Kontext Multi:

Batch Content Generation

Great for generating dozens of unique AI artworks for a gallery, blog or marketplace:

See the full example: examples/batch-generate.php.

Save Images to Disk

Call Any fal.ai Endpoint

Need an endpoint that isn't in the catalog? Use the escape hatch:

Or parse a custom image-model response into GeneratedImage objects with generate($endpoint, $payload).


API Reference

new FalAiClient(string $apiKey, array $options = [])

Option Default Description
base_url https://fal.run fal.ai API base URL
timeout 180 Request timeout (seconds)
connect_timeout 10 Connection timeout (seconds)

textToImage(string $prompt, array $options = []): GeneratedImage[]

Option Type Default Description
model string FLUX_SCHNELL Model ID from Models
image_size string square_hd One of the SIZE_* constants
num_images int 1 Number of images (model-dependent max)
num_inference_steps int model default Diffusion steps (validated per model)
guidance_scale float — Prompt adherence (ignored by Schnell)
negative_prompt string — What to avoid
safety_checker bool false Enable the fal.ai safety checker
extra array [] Any additional raw fal.ai parameters

imageToImage(string $prompt, string|array $referenceUrls, array $options = []): GeneratedImage[]

Same options as textToImage(); the model must support image-to-image.

GeneratedImage

Property / Method Description
$image->url Hosted image URL on fal.media
$image->width / $image->height Output dimensions in px
$image->contentType e.g. image/jpeg
$image->save($dir, $filename = null) Download the image, returns the local path

Error Handling

All failures throw a FalAiException with the HTTP status and parsed fal.ai validation details:

Common cases handled for you:


Image Sizes & Prompt Tips

Sizes: SIZE_SQUARE_HD, SIZE_SQUARE, SIZE_PORTRAIT_4_3, SIZE_PORTRAIT_16_9, SIZE_LANDSCAPE_4_3, SIZE_LANDSCAPE_16_9

Prompt formula that works well with FLUX.1:

Looking for inspiration? Browse thousands of community prompts and remix them free at ShareAIChat — the AI art sharing community built on this library.


Use Cases


FAQ

Is this library free? Yes. It is released under the MIT license. You only pay fal.ai for the images you generate. FLUX.1 Schnell is the cheapest option and needs just 4 inference steps.

Do I need a fal.ai account? Yes — create a free account and grab an API key at fal.ai/dashboard/keys. The key is only used server-side; never expose it in browser code.

What is the difference between FLUX.1 Schnell and FLUX.1 Dev? Schnell is optimized for speed and low cost (4–12 steps, seconds per image) and is perfect for prototyping and bulk generation. Dev offers higher fidelity and finer prompt adherence with up to 50 steps.

Can I use this in Laravel / WordPress / plain PHP? Yes. It is a framework-agnostic Composer package with zero dependencies beyond curl and json, and it also works without Composer.

Where are the generated images stored? fal.ai returns URLs hosted on its fal.media CDN. Display them directly or download with $image->save() and upload to your own storage / S3 / OSS.

Can I generate videos too? This package focuses on image generation (text-to-image and image-to-image). The underlying request() escape hatch can be pointed at any fal.ai endpoint if you want to extend it yourself.

Where can I see AI art built with this SDK? Visit shareaichat.com — a free community to create, remix and share AI-generated artwork powered by this exact library.


Contributing

Contributions are welcome — issues, pull requests and new model catalog entries. When adding a model, please include its endpoint, image limit, step limit and whether it accepts guidance_scale and negative_prompt.


License

ShareAIChat

Create freely. Share imagination. Find inspiration — shareaichat.com.


All versions of fal-ai-php-image-generator with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package shareaichat/fal-ai-php-image-generator contains the following files

Loading the files please wait ...