/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.
| Option | Type | Default | Description |
|---|---|---|---|
allowedUrlPatterns | string[] | ["fal.run/**", "queue.fal.run/**"] | Glob patterns for allowed target URLs (without scheme). Add patterns like "fal.ai/**" if needed. |
allowedEndpoints | string[] | [] (all allowed) | Glob patterns for allowed POST endpoints (path without leading slash, e.g. "fal-ai/flux/**"). An empty array allows all endpoints. |
allowUnauthorizedRequests | boolean | true | Whether to allow requests without authentication. Set to false in production and provide isAuthenticated. |
isAuthenticated | (behavior) => Promise<boolean> | Checks for Authorization header | Custom function to determine if the incoming request is authenticated. |
resolveFalAuth | (behavior) => Promise<string> | Uses FAL_KEY env var | Custom function to resolve the fal API authorization value. |
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