/api/fal/proxy) with the real fal endpoint in an x-fal-target-url header. Your proxy reads that header, adds your FAL_KEY via the Authorization header, forwards the request to fal, and pipes the response back to the browser. This means your key never leaves the server.
Next.js App Router
Createapp/api/fal/proxy/route.ts:
Next.js Pages Router
If you are using the Pages Router instead of App Router, createpages/api/fal/proxy/[...path].ts:
Full Next.js Example
Complete walkthrough with working code
Vercel Integration
Deploy AI apps on Vercel with fal
Proxy Configuration
BothcreateRouteHandler() and createPageRouterHandler() accept a ProxyConfig object to control security and access.
The old
handler and route exports from @fal-ai/server-proxy/nextjs are deprecated. Migrate to createPageRouterHandler() and createRouteHandler() respectively.Vercel
If you are deploying to Vercel, the Next.js proxy setup works out of the box. Set yourFAL_KEY as an environment variable in your Vercel project settings (Settings > Environment Variables) and the proxy route will read it automatically. No additional configuration is needed beyond what is described in Client Setup.
Custom Proxy (Express, Flask, etc.)
If you are not using Next.js, you can implement the proxy with any framework. The proxy endpoint needs to:- Accept all HTTP methods (GET, POST, PUT, DELETE)
- Read the target URL from the
x-fal-target-urlheader - Add your API key via the
Authorizationheader - Forward the request to fal and return the response
Express.js