POST https://fal.run/execute. fal runs the first model, which is the primary. If the primary fails with an error that you allow, fal runs the next model in the list. The response contains the first successful result and a record of each attempt.
Use a fallback chain when a different model can give an acceptable result if your preferred model is not available. For example, you can send an image request to a fast model first and to a second model if the first model times out.
A fallback chain is different from model fallbacks. Model fallbacks are automatic and fal selects the alternative endpoint. In a fallback chain, you select the models, the input for each model, and the errors that move the request to the next model.Some models apply their own automatic model fallbacks. These still run inside each attempt, independent of your fallback chain. To disable them, pass the
x-app-fal-disable-fallback: true header in your request.Quick Start
Send the primary model inendpoint, input, and config. Send each fallback model in the fallback list.
fal-ai/flux/schnell must start in 10 seconds. If it does not start in this time, fal runs fal-ai/flux/dev with the same prompt.
The fal client libraries do not have a method for fallback chains. Send the request with an HTTP client, as the examples show.
How a Chain Runs
fal runs the models one at a time, in the order of the list.Fallback N is the next model in the fallback list, first fallback[0] and then fallback[1]. Each attempt is a separate request with its own request ID. A model moves the chain to the next model only when its error category is in its own fallback_errors.
- Return output: the response has
"status": "OK"and the output of the model that succeeded. - Return error: the response has
"status": "ERROR"and the error of the last model that ran.
Request Format
Model Settings
Each model in the chain has its ownconfig. The top-level config applies only to the primary model. A fallback model does not inherit it. If a fallback item has no config, that model uses the default values.
- The primary model has 10 seconds to start. It uses the default
fallback_errors. - The first fallback model has 30 seconds to start. The chain moves to the next model only when this model does not start in time.
- The last fallback model has no
config. It has no start timeout.
Input References
A fallback model can use values from the input of the primary model. To use a value, write a reference as a string value in the fallback input. fal replaces the reference with the value from the primary input, and the value keeps its type. A reference can point to a string, a number, a boolean, an object, or an array.
For example, if the primary input is
{"prompt": "a cat", "steps": 28}, this fallback input:
{"text": "a cat", "num_inference_steps": 28}.
A reference must be the full string value. fal does not replace a reference inside a longer string, for example "a photo of $input.prompt". A path can only contain object keys. You cannot select an item of an array, for example $input.images.0. A reference always uses the input of the primary model, not the input of the previous fallback model. If fal cannot find the value of a reference, it rejects the request with 422 and no model runs.
Headers and Query Parameters
fal sends the headers and query parameters of your request to each attempt. Each attempt gets a new request ID. Platform headers, for exampleX-Fal-Store-IO, apply to each attempt. See platform headers.
Error Categories
When a model fails, fal puts the error in one category. If the category is in thefallback_errors of the model, the chain moves to the next model.
Some errors always stop the chain. They do not have a category:
400,404, and other client errors that are not in the table.- The account concurrency limit, because the next model has the same limit.
- An endpoint that does not exist.
startup_timeout becomes queue_timeout, and runner_disconnected becomes internal_error.
To add a category, write the full list:
Response Format
Success
When a model returns a successful response, the HTTP status is200 and status is OK.
Error
When the chain stops without a success,status is ERROR. The HTTP status is the status of the last attempt. For example, if the last model returned 422, the HTTP status is 422.
Attempts
Each record inattempts has these fields:
A
skipped record has only endpoint and outcome.
Response Body Encoding
fal puts the response body of the model inoutput or error.body:
For example, when a model returns a PNG image,
output is a data URL:
x-fal-request-id is the request ID of the last attempt, and X-Fal-Billable-Units shows the units of the last attempt. See response headers.
Request Errors
fal rejects these requests before a model runs. No model runs and fal does not bill you. Each model checks its own input when it runs.Test a Fallback Model
Use test mode to check the input references and the response of a fallback model. Add thefal_fallback_test_candidate query parameter with the position of the fallback model. Use 1 for the first fallback model and 2 for the second.
- fal runs only the selected fallback model. The primary model does not run.
- fal resolves the input references against the input of the primary model.
- The
attemptslist contains all models in their usual order. The models that did not run have the outcomeskipped. - If the selected model fails,
reasonistest_candidate_failed. - fal does not send
fal_fallback_test_candidateto the model.
Billing
Each attempt is a separate request with its own request ID. fal bills each attempt with the usual rules of its model. For example, if the primary model fails with a 5xx error and the fallback model succeeds, fal does not bill the primary attempt and bills the fallback attempt.Limitations
- Fallback chains are synchronous only. You cannot submit a chain to the queue.
- You cannot use streaming, WebSocket, or real-time endpoints in a chain. fal rejects an endpoint that ends in
stream,ws, orrealtime. - You cannot use workflow endpoints (
workflows/...) or ComfyUI workflow endpoints (comfy/...) in a chain. - A chain has at most three models.
Synchronous Inference
Call one model with a direct request
Reliability
Learn about queue retries and model fallbacks