Install and configure a provider
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 inFAL_KEY, not GEMINI_API_KEY.
FAL_KEY to your application’s private environment, then clear or rebuild its configuration cache. Configure the field’s action explicitly:
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
aiImageEditor() method is available on FlexFileUpload and FlexSpatieMediaLibraryFileUpload.
What happens to generated images?
- The original remains associated with the field while editing.
- 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.
- Use this version admits the selected result through the field’s validation and replaces the field’s draft association. Rejected results are removed.
- Saving the surrounding form runs the field’s existing storage and conversion pipeline. For Spatie, the model’s collections and conversions remain authoritative.
- Closing without selecting a result discards generated candidates and leaves the original association intact. Closing after selecting does not delete the selected form draft.
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 inconfig/filament-flex-fields.php so Laravel configuration caching remains supported:
->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: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.
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: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.