Run FLUX with an API

Posted August 1, 2024 by

FLUX.1 is a new open-source image generation model developed by Black Forest Labs, the creators of Stable Diffusion. It's available on Replicate today, and you can run it in the cloud with one line of code.

Here's an example of how to run FLUX.1 on Replicate using JavaScript:

import Replicate from "replicate";
const replicate = new Replicate();
 
const model = "black-forest-labs/flux-dev";
const prompt = "Purple striped narwhal devouring a fluffy high-resolution everything bagel";
const output = await replicate.run(model, {input: { prompt }});
console.log(output);

You can try out FLUX.1 right in your browser, or run it programmatically in your language of choice.

What makes FLUX.1 special?

FLUX.1 models have state-of-the-art performance in prompt following, visual quality, image detail, and output diversity. Here are some particular areas where we've been impressed:

Text! Unlike older models that often messed up similar-looking letters, Flux can handle tricky words with repeated letters. This makes it great for designs where text needs to be accurate. Check out this Black Forest Flux Schnell gateau:

Cake with text

Complex composition. Flux is amazing at following complex instructions about where things should go in an image. For example, given the prompt "Three magical wizards standing on a yellow table, each holding a sign. On the left, a wizard in black robes holds a sign that says 'AI'; in the middle, a witch in red robes holds a sign that says 'is'; and on the right, a wizard in blue robes holds a sign that says 'cool'", Flux creates this scene perfectly:

Complex scene

Hands that (mostly) look right. Hands are tough for AIs, but Flux does a pretty good job. You'll usually get the right number of fingers in the right places. It's not perfect, but it's a big step up—it's consistently better than any other open text-to-image model we've tried:

Cool hand

Model variants

FLUX.1 comes in three variants:

  • FLUX.1 [pro] The best of FLUX.1, state-of-the-art image generation model with top-of-the-line performance.
  • FLUX.1 [dev] An open-weight, guidance-distilled model for non-commercial applications. Directly distilled from FLUX.1 [pro], FLUX.1 [dev] has similar quality and prompt adherence capabilities, while being more efficient than a standard model of the same size.
  • FLUX.1 [schnell]: The fastest model, tailored for local development and personal use. Openly available under an Apache 2.0 license.

Pricing

FLUX.1 is priced per image:

  • FLUX.1 [pro] is $0.055 per image.
  • FLUX.1 [dev] is $0.030 per image.
  • FLUX.1 [schnell] is 0.003 per image.

Next steps

FLUX.1 is a fantastic model, so do try it out. And keep watching this space—now that the model is out in the wild, we are starting to work on features like fine-tuning for FLUX.1, so stay tuned.