Running Flux on Real Infrastructure
Flux is the open model family that powers a huge share of serious photoreal work. You can use it inside web apps, but the moment you want batches, automation, or cost control you call it through an API. This lesson gets you generating Flux images from code on a hosted GPU.
Step 1: Choose a host
You do not need your own GPU. Hosts like Replicate, Fal, and Together run Flux for you and bill per image. Fal is known for low latency, Replicate for breadth of models. Pick one, create an API key, and put it in an environment variable, never in your code.
Step 2: Generate from code
A few lines get you an image. Note the key parameters: the model id, the prompt, image size, and how many inference steps. More steps means more detail and more cost, the Flux dev model is happy around 28 to 35 steps.
import { fal } from "@fal-ai/client";
fal.config({ credentials: process.env.FAL_KEY });
const result = await fal.subscribe("fal-ai/flux/dev", {
input: {
prompt:
"a weathered fisherman mending a net on a dock, " +
"photorealistic, soft overcast light, 50mm",
image_size: "landscape_4_3",
num_inference_steps: 30,
guidance_scale: 3.5,
},
});
console.log(result.data.images[0].url);Step 3: Batch and control cost
The whole point of API access is volume. Loop a list of prompts to generate a product catalog overnight. Track spend: at a couple of cents per Flux dev image, a hundred images is a dollar or two, but a careless loop can run away fast. Log every call.
const prompts = ["a red mug", "a blue mug", "a green mug"];
for (const p of prompts) {
const r = await fal.subscribe("fal-ai/flux/dev", {
input: { prompt: p + " on a white studio background", image_size: "square_hd" },
});
console.log(p, "->", r.data.images[0].url);
}Result
You can generate Flux images from a script, swap models for draft versus final quality, batch a list of prompts, and keep an eye on cost. This is the backbone of any production image pipeline.