The Agent SDK is in alpha. These examples use
@fal-ai/client@1.11.0-alpha.4.
Media generation can incur charges. See Access and
pricing.Install the SDK
The Agent SDK is part of the@fal-ai/client npm package.
It supports JavaScript and includes TypeScript types for requests, responses, and resources.
Use Node.js 22.22 or later for these examples.
See client configuration for runtime requirements.
Python support
The Agent SDK currently supports JavaScript and TypeScript. The fal Python client supports direct model calls. It does not provide the Agent SDK methods for conversations, plans, or approvals.Authentication
Create a fal API key with the AGENT permission preset. Set the key in your environment:YOUR_API_KEY with your key.
The SDK reads FAL_KEY when you omit credentials.
Keep the API key on your server.
For a browser application, use a server endpoint that enforces your users’ permissions.
See browser applications.
Generate media
Useagent.run() to submit a task and wait for its result.
The agent creates a response that contains the task status, assistant text, generated media, and any questions or approvals.
An artifact identifies generated media and can contain files with download URLs.
Create agent.mts:
tsx to execute the TypeScript example:
run() returns when execution stops or needs user input.
Check the response before you use its media:
Execution failures appear in
response.status and response.error.
Request failures throw AgentRequestError.
See errors and troubleshooting for failure and recovery details.
See media and costs to reuse media or select final results.
SDK methods
Use these methods to submit tasks and control their execution:
See the method reference for all methods and the type reference for their types.
Progress and user input
Stream progress
Useagent.stream() to start a task with progress updates:
responses.stream(responseId) to observe a task that already exists.
Each update contains the complete response state, called a snapshot.
Replace the displayed state on each update.
Do not append each snapshot’s output_text to the previous text.
Questions and approvals
The agent can pause to ask a question or request approval. Whenpending_inputs contains a request, show it to the user.
Collect the user’s answer.
Submit the answer with responses.answer() and the same response ID.
Then resume observation with responses.wait() or responses.stream().
See questions and approvals for answer formats and examples.
Recovery and cancellation
Save the response ID to reconnect after a process restart, timeout, or lost connection. Useresponses.wait() or responses.stream() with that ID to observe the existing task.
For an application that stores task state, submit the task with responses.create().
Save the response ID.
Then call responses.wait() or responses.stream().
See responses and recovery for submission retries and reconnection options.
Next steps
- Use the quickstart to run your first task.
- Configure credentials, transport, and retries with client configuration.
- Control a task’s steps with plans.
- Organize tasks with conversations and projects.
- Add reusable instructions with skills.
- Display execution progress with tool activity.
- Find integration guides in guidance for coding agents.