https://fal.ai/api/agent-v2/sdk.
Configuration fields
Use a key with the AGENT permission preset. The SDK authenticates requests with
Authorization: Key <key_id>:<key_secret>.
Browser sessions do not authenticate SDK requests.
The key acts on its account’s resources. It does not inherit a signed-in browser user’s account selection or administrator role.
When credentials is omitted, the shared client reads FAL_KEY from the environment.
It also supports the FAL_KEY_ID and FAL_KEY_SECRET pair.
Browser applications
Keep the API key on your server. Use a server endpoint to call the Agent SDK for browser clients. The server must enforce your application’s user permissions before forwarding requests. Your proxy must forward Agent requests and preserve streaming responses.proxyUrl accepts a URL string or { url, when }.
The when value is "browser", "always", or a function that receives { isBrowser } and returns a boolean.
A URL string uses the "browser" behavior.
requestMiddleware receives { url, method, headers? } and returns a promise containing the same shape.
Headers map names to strings or string arrays.
Preserve the required authorization, content type, and idempotency headers when changing a request.
Request retries
Reads and response commands use this retry policy for eligible HTTP and transport failures.
Resource writes for projects, settings, preferences, skills, library, queues, runs, and final selections are sent once.
Idle conversation creation is also sent once.
Conversation rename and deletion can use automatic retries. Read the conversation after a network error before repeating either operation.
A retry within one command preserves its idempotency key.
To recover after a process restart, persist the request and key before submission.
See response recovery.
timeoutMs covers local request attempts and waits. An abort or timeout stops retries.
Neither cancels server execution.
Streaming also has maxReconnects and reconnectDelayMs. See response options.
Public exports
createAgentClient(config) accepts a resolved RequiredConfig.
For standard setup, use createFalClient() to supply transport and retry defaults.
Runtime requirements
The client usesfetch, AbortController, URL, and asynchronous iterators.
These guides use Node.js 22.22 or later, including its global File constructor for document uploads.
Use agent.projects.documents.upload to upload and import a project document.
For other uploads, use the shared fal storage client and pass the resulting URL to an Agent request or resource method.