Install
The Agent SDK is in alpha. Install the version used in this guide:Configure your credentials
Create a fal API key with the AGENT permission preset. Set your API key in the environment:YOUR_API_KEY with your key.
The SDK sends Agent requests to https://fal.ai/api/agent-v2/sdk.
Keep the API key on your server. Do not include it in browser code.
Create a client
Createclient.ts. The other examples in this guide import this client.
Run your first task
Createagent.mts next to client.ts:
run() returns when execution stops or needs user input. Check status and fal.phase before using the result.
Media generation can incur charges.
Stream progress
Usestream() to observe updates as the task runs:
responses.stream(responseId) to observe an existing task.
Continue the conversation
ReplaceCONVERSATION_ID with response.fal.conversation_id from the earlier response:
responses.answer() with the existing response ID.