Skip to main content
Open an image in a full-screen editor, describe a change and compare the results before selecting a replacement. AI editing is optional. Ordinary uploads do not need an AI provider or Laravel AI SDK.

Install and configure a provider

Configure your provider in Laravel’s config/ai.php. For example, Gemini uses GEMINI_API_KEY; OpenAI uses OPENAI_API_KEY. Keep keys on the server. An API account needs access to the selected image model and sufficient quota; a consumer chat subscription does not configure an application’s API access.

Use Gemini through fal.ai

FLEX includes an optional image-only extension for Laravel AI SDK. This is a separate connection from Google’s direct Gemini API: a fal key belongs in FAL_KEY, not GEMINI_API_KEY.
Add FAL_KEY to your application’s private environment, then clear or rebuild its configuration cache. Configure the field’s action explicitly:
Use the imports shown in the next example. falGemini() supports the approved Nano Banana 2 and Nano Banana Pro edit endpoints, references, aspect selection, 1K/2K/4K quality labels and one or four outputs. Set stricter field limits and model capabilities for your application’s processing budget. Four outputs request four images and can incur additional provider charges. This extension still uses Laravel AI SDK’s image API, events and testing facilities. FLEX sends bounded inline images to fal’s synchronous endpoint with no application retry, requests inline PNG outputs and disables request/response history storage through fal’s supported header. It never downloads arbitrary result URLs or sends the key to the browser. Provider retention and billing remain governed by fal’s policies. The action’s optional Laravel background queue works with this connection too.

Enable editing on an upload field

Only profiles with a configured provider key and a compatible SDK image adapter are offered. The field owns source authorization, candidate admission and replacement. The same aiImageEditor() method is available on FlexFileUpload and FlexSpatieMediaLibraryFileUpload.

What happens to generated images?

  1. The original remains associated with the field while editing.
  2. Generated results are private temporary uploads in an editing workspace, not permanent gallery entries or new media records. Prompts and failed attempts stay in the current browser workspace.
  3. Use this version admits the selected result through the field’s validation and replaces the field’s draft association. Rejected results are removed.
  4. Saving the surrounding form runs the field’s existing storage and conversion pipeline. For Spatie, the model’s collections and conversions remain authoritative.
  5. Closing without selecting a result discards generated candidates and leaves the original association intact. Closing after selecting does not delete the selected form draft.
This preserves normal form semantics: accepting an image in the editor does not silently save the surrounding record. Application-owned gallery relationships continue to use their existing save handlers; see the gallery recipe. A selected generated version can itself be edited again. The server resolves that version from the same private workspace; it does not download an arbitrary URL supplied by the browser. FLEX does not create a persistent image-version or prompt-history table. Durable history is a separate application feature, not a side effect of opening this editor. A provider’s own data-retention policy is separate from FLEX’s temporary storage.

Reference images, ratios, quality and result counts

Capabilities belong to each model profile. Models without reference support have no reference-upload action. Supported reference images appear beside the prompt. Their order follows the upload order; describe the main image as image 1 and references as subsequent images when your provider uses ordered inputs.
preserveAspect exposes Original. It leaves the output ratio unspecified so a compatible model can follow its input; it is not a guarantee of identical pixel dimensions. The named ratios use SDK size() values. Quality keys use SDK low, medium and high; their display labels should describe the selected model’s actual quality or resolution settings. counts must match what the model and its SDK adapter support. The OpenAI preset offers one or four results using the provider’s batch option. The Gemini preset offers one result; FLEX does not silently issue four separately billed requests. Input and output images are bounded JPEG, PNG or WebP rasters: up to 10 MiB and 16 million pixels per image, with at most 32 MiB of combined input images. The presets allow three references. The attachment button disables at the limit without displaying a counter, and becomes available again after a reference is removed. Both browser and server enforce the selected model’s limit. A custom model profile can allow up to 13 additional reference images. Use stricter limits where appropriate. Provider limits, image dimensions and field rules still apply; only offer output qualities that fit your application’s upload and image-processing budgets.

SDK adapter compatibility

A provider’s ability to generate images does not imply that every model or SDK adapter can edit an existing image. Profiles declare the approved model IDs and capabilities on the server. Selecting a different model in the browser cannot enable unsupported references or settings.

Shared application profiles

Declare plain arrays in config/filament-flex-fields.php so Laravel configuration caching remains supported:
Fields can then opt in with ->aiImageEditor(). A field’s models([...]) list overrides shared profiles. The package’s shared list is empty by default.

Use the action outside File Upload

EditImageWithAiAction is a native Filament action. Supply an authorized display preview and a separate server-side input resolver. acceptUsing() receives the selected TemporaryUploadedFile; your application chooses its persistence workflow.
SavePortrait is your application’s service, not a bundled FLEX class. Unlike an upload-field integration, a standalone action cannot infer your record’s destination, conversion rules or transaction. Provide admitUsing() for validation before acceptance. Recheck authorization and the current record revision in an application-owned write service when supporting concurrent edits.

Run generation in a background queue

Enable queue processing on the action when your application runs queue workers:
Implement QueuedImageEditAuthorizer on AuthorizePortraitEdit. Its allows(array $scope): bool method must look up the current actor, tenant and record and check the image-edit policy against fresh data. For upload fields, the server-built scope includes resource.actor, resource.tenant, resource.record, resource.field, and resource.source. Use the identity and source fields relevant to your application. For standalone actions, provide the resource identifiers through workspaceScopeUsing(). Avoid relying on the current HTTP session in the worker. The worker checks authorization before sending the image to the provider and again before staging results. A missing authorizer blocks queued generation. To share an authorizer across actions, set media_capture.ai_image_editor.queue_authorizer in the FLEX config. Use a real asynchronous Laravel connection, such as Redis or database. For the default 120-second model timeout, configure the connection’s retry_after above 135 seconds, for example 180. For SQS, configure its visibility timeout accordingly. The job allows one attempt and sets its timeout to the model timeout plus 15 seconds.
FLEX dispatches an encrypted Laravel job that invokes Laravel AI SDK in the worker. It does not use the SDK’s own Image::queue() callback API. Input copies stay in the private temporary workspace; API keys and image bytes are not serialized into the job. The prompt is part of the encrypted queued payload, so apply your application’s queue and failed-job retention policy. The open editor shows queued/running states and polls for completion. Only one generation runs per workspace. Closing before processing prevents the provider call; closing after processing has started discards late results but cannot guarantee cancellation of the provider’s request or charges. This is temporary editing, not a durable job history that reopens after a page reload. Use shared cache and private temporary storage accessible to the web application and worker. No FLEX-specific queue migration is needed; a database queue still needs Laravel’s normal jobs table.

Reject edits based on an outdated image

For an upload field backed by a record, bind the workspace to a revision that changes when the selected image is replaced:
Here, portrait_revision is an application-managed value. Update it as part of persisting the replacement. An open editor in a second tab will then reject acceptance against the older revision. If both tabs accept a draft before either saves, apply the revision check in your record update transaction as well.

Failed generations

A failed attempt remains as an error tile in the right-hand history, with Retry, Reuse prompt and Delete actions. The main preview returns to the image used for that attempt, without error overlays. Reference-limit and acceptance messages also appear in the history panel rather than over the image. Retry restores the attempt’s model and settings and starts a new request. If its original references were removed, reuse the prompt with current references instead. Provider quota and credit errors have explicit messages. FLEX does not promise that an unsuccessful or interrupted request was free: billing is determined by the provider. Retrying is a user action; the application does not automatically start another generation after an uncertain completion. The SDK may apply its own transport retry policy.

Temporary storage and cleanup

Use a private Livewire temporary-upload disk and a shared cache supporting atomic locks when running multiple application servers. Editing workspaces expire after 30 minutes. The close request seals the workspace separately from Livewire’s request queue, so a late provider result cannot revive a closed editor. Schedule cleanup to remove abandoned candidates after browser crashes or lost connections:
Expiration prevents using an old workspace immediately; physical cleanup of abandoned files depends on your scheduler. Accepted temporary uploads follow Livewire’s normal temporary-upload lifecycle until the surrounding form saves them. Reference uploads use that temporary-upload lifecycle too. Cleanup never deletes permanent media or the selected form draft.
Last modified on November 29, 2026