Download the PHP package marceloeatworld/falai-php without Composer
On this page you can find all versions of the php package marceloeatworld/falai-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marceloeatworld/falai-php
More information about marceloeatworld/falai-php
Files in marceloeatworld/falai-php
Package falai-php
Short Description #1 PHP client for the fal.ai serverless AI platform, compatible with Laravel and native PHP, built on Saloon v4
License MIT
Informations about the package falai-php
fal.ai PHP Client
1 PHP client for the fal.ai serverless AI platform, compatible with Laravel and native PHP, built on Saloon v4.
Requirements
- PHP 8.2+
- ext-sodium (optional, only for webhook signature verification)
Installation
Quick Start
Streaming
Models that expose a /stream endpoint (check the model page, or stream_url in its catalog metadata) push partial results as server-sent events. stream() yields each event as an array; the last event is the final result and is also returned by the generator.
Models without a /stream endpoint answer 404 (Path /stream not found). fal-ai/flux/schnell, for example, has none; fal-ai/flux/dev does.
Queue (Async Workflow)
For long-running models, use the queue to submit jobs and retrieve results later.
Status, result and cancel are addressed by application id (fal-ai/flux), not by the full endpoint id (fal-ai/flux/schnell). The client derives it automatically, so pass the same model id you submitted with. The URLs returned by submit() (statusUrl, responseUrl, cancelUrl) are also exposed on the QueuedJob DTO.
Subscribe (Submit + Auto-Poll)
Submit a job and automatically poll until it completes.
Status Streaming
Instead of polling, the queue can push status updates as server-sent events until the request completes. The last yielded status is the COMPLETED one.
Webhooks
Receive results via webhook instead of polling.
Verifying Webhook Signatures
fal.ai signs every webhook with ED25519 (X-Fal-Webhook-* headers). Verify before trusting the payload:
Public keys are fetched from the fal.ai JWKS endpoint (https://rest.fal.ai/.well-known/jwks.json) and cached per instance for 24 hours, so reuse the verifier (singleton) across requests. If a signature matches none of the cached keys, the JWKS is fetched again once to pick up rotated keys. verify() throws with a reason, isValid() returns a boolean. Timestamps more than 5 minutes away from the server clock are rejected.
Webhook payloads carry status ("OK" or "ERROR"), request_id, gateway_request_id and payload. On error an error field is added; if the output could not be serialized, payload is null and payload_error explains why. fal.ai retries deliveries that do not answer with a 2xx (redirects count as failures), so keep handlers idempotent.
File Upload
Upload local files to the fal.ai CDN for use with image-to-image models. Files above 90 MB are uploaded in 10 MB parts (multipart flow of the official clients, each part retried up to 3 times); smaller files use a single PUT.
In-memory content works too:
Both methods accept a lifecycle to control expiration and access (see below):
File Expiration and Access Control
By default generated and uploaded files stay on the CDN forever and are publicly readable (unless your account settings say otherwise). Pass an ObjectLifecycle to run(), stream(), queue->submit(), queue->subscribe(), storage->upload() or storage->uploadData() to change that per request. It is sent as the X-Fal-Object-Lifecycle-Preference header.
Private files answer 403 to anonymous requests. To read them, exchange your API key for a CDN token (POST https://rest.fal.ai/storage/auth/token?storage_type=fal-cdn-v3) and send it as Authorization: Bearer <token>, or create a signed URL from the fal.ai dashboard or Platform API.
Model Catalog
Search the fal.ai model catalog (no API key required for this endpoint, but one is always sent).
Pricing
Fetch unit prices and estimate costs (API key required).
Queue Options
Fine-tune queue behavior with named parameters.
subscribe() accepts the same options (timeout there is the client-side polling limit, use requestTimeout for the server-side deadline). run() and stream() accept timeout, noRetry, lifecycle and storeIo.
Useful response headers on run() and result(): x-fal-request-id, x-fal-billable-units, and x-fal-error-type on failures.
Custom Base URLs
Override default endpoints if needed.
Laravel Integration
Add to config/services.php:
Register in a service provider:
Use via injection:
Error Handling
The client throws Saloon exceptions on HTTP errors (4xx/5xx). Queue subscribe throws dedicated exceptions (both extend \RuntimeException) on timeouts and on jobs whose status reports an error (for example client_cancelled).
Input validation errors are not reported in the queue status: the job completes and the result endpoint answers 422 with a detail array, so result() and subscribe() throw a Saloon RequestException in that case. Catch both.
Status responses expose error and error_type (QueueStatus::$error, QueueStatus::$errorType); request-level error types include request_timeout, startup_timeout, client_cancelled, runner_server_error and internal_error.
Architecture
License
MIT
Credits
- Built with Saloon v4
- fal.ai API Documentation