Run AI models at scale
Enable your app with AI inference with seamless integration with Next.js and Vercel. This integration makes the setup hassle-free and will get your Vercel app production-ready in no time.
This integration creates an API Key and sets it in the environment variables of your selected apps, named FAL_KEY. This will ensure your applications using the fal.ai clients can make calls while keeping your credentials safe.
Run npm install --save @fal-ai/client
In your .env.local, add this environment variable:
FAL_KEY='YOUR_FAL_KEY'In Vercel, your FAL_KEY can be set automatically, when you click "Connect Project" and choose the project that needs to be connected to fal.
Use this snippet to call a model and run inference:
import { fal } from "@fal-ai/client";
const result = await fal.subscribe("fal-ai/flux/dev", { input: { prompt: "a cat", seed: 6252023, image_size: "landscape_4_3", num_images: 4, }, logs: true, onQueueUpdate: (update) => { if (update.status === "IN_PROGRESS") { update.logs.map((log) => log.message).forEach(console.log); } },});
console.log(result.data);console.log(result.requestId);Go to fal dashboard by clicking "Open in fal" and click on "Explore". Try out different models. Each model has a documentation page that you can use in order to incorporate it into your project.
Some extra components make Vercel + fal.ai integration even easier.
import { fal } from '@ai-sdk/fal';import { experimental_generateImage as generateImage } from 'ai';import fs from 'fs';
async function main() { const { image } = await generateImage({ model: fal.image('fal-ai/fast-sdxl'), prompt: 'A serene mountain landscape at sunset with purple and orange sky, reflections in a calm lake', });
const filename = `image-${Date.now()}.png`; fs.writeFileSync(filename, image.uint8Array);}
main().catch(console.error);