Skip to main content
Use the quickstart client. Replace uppercase IDs with your resource IDs. A response represents one task. Use its ID to observe, answer, or cancel that task.

Methods

All methods below belong to the configured agent client. Response in this table means AgentResponseView.

Request fields

A structured user message has role: "user" and 1–40 content parts. Supported parts are input_text, input_image, input_file, and fal.input_artifact. Use image_url for images and file_url for files. See media inputs. Follow-ups create new response IDs. Answers continue the existing response ID.

Options

selectFinalArtifacts uses resource options: signal and timeoutMs only. It uses expected_sequence_number to detect conflicting writes. maxReconnects must be a nonnegative integer. reconnectDelayMs must be nonnegative and finite. Idempotency keys must be nonempty, single-line strings with at most 200 characters. onAccepted is synchronous. The helper does not await a promise returned by this callback. Use responses.create when durable asynchronous storage must finish before observation starts.

Read the response

Observation also stops at fal.phase === "waiting_for_input", even when the status is not terminal. After answering, resume observation with the same response ID. Observation also stops when fal.pending_submission reports a saved answer that could not resume. Follow saved-answer recovery before resuming observation. fal.model_usage reports conversation model tokens across the response’s turns. Its scope is "conversation_model". The input_tokens and output_tokens fields are included only when every turn has reported that count. These counts exclude media generation and auxiliary model calls. An absent field or null means unavailable, never zero. usage is null when complete accounting is unavailable. Do not treat conversation model counts as a billing total. fal.pending_input_ids and fal.final_artifact_ids reference items in output. The convenience views are derived getters. JSON.stringify(response) omits them. Read the getters explicitly when saving a presentation view.

Example snapshot

This illustrative accepted response has no output yet. IDs vary for each request. The derived fields output_text, artifacts, final_artifacts, and pending_inputs are added by the SDK.

Output item types

Treat IDs as opaque strings. Response, input request, and artifact IDs identify different resources.

Stream snapshots

The stream yields complete snapshots, not text deltas. Replace the displayed state on each update. Do not append each snapshot’s output_text.
The SDK reconnects to existing work when an SSE connection closes.

Recover an uncertain submission

Save the exact request body and idempotency key before the first attempt.
Retry an uncertain command with the same key and body. A command key is scoped to your account and fal project, so replacing your API key does not create new work. A new command key creates new work. A changed body with an existing command key returns a conflict. SAVED_COMMAND_KEY represents the key stored before the original attempt. Use its exact saved input, too.

Handle errors

Inspect response.status and response.error for execution failures. Catch AgentRequestError for request failures. See errors and troubleshooting for recovery actions and error context.

Cancel execution

Closing a stream, aborting a signal, or reaching a timeout only stops local observation. Cancellation requests server and provider cancellation. It does not refund charges already incurred. If cancellation fails, retrieve the same response and retry cancellation. The response can remain active until cancellation is confirmed.