Ship a Full-Stack App with One Prompt

Copy this prompt into your AI coding agent, or open it in one below.

Give this to your AI Create a to-do list app using Puter.js
Tutorials

How to Get a FLUX (Black Forest Labs) API Key: A Step-by-Step Guide

On this page

This guide shows you how to get a FLUX (Black Forest Labs) API key. You'll create a Black Forest Labs account, generate your key, and make your first API call, plus a free alternative for adding FLUX models to your web app.

Prerequisites

  • A Google account or email, BFL supports both sign-in methods
  • A payment method, FLUX's API is usage-based
  • Basic familiarity with code (we'll show simple examples)

Step 1: Create Your Black Forest Labs Account

Go to dashboard.bfl.ai. You'll see the sign-up page.

Black Forest Labs sign-up page

Sign up with your Google account or email. Once you've completed the setup and signed in, you'll land on the dashboard. Select the default project under Projects.

Black Forest Labs dashboard with Projects

Step 2: Generate Your API Key

Once inside the project, look at the left sidebar. Under the API group, you'll find the Keys menu.

Black Forest Labs sidebar with Keys menu under API group

Click Keys to go to the API key page. Then click Add Key.

Black Forest Labs API key page with Add Key button

Enter a name for your API key.

Black Forest Labs name your API key dialog Black Forest Labs API key revealed with copy button

Important: Copy the key immediately. BFL only shows it once. If you lose it, you'll need to generate a new one.

Store it somewhere safe, like a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository.

Step 3: Make Your First API Call

FLUX uses a direct REST API with an asynchronous polling pattern. Here's a quick example using curl to generate an image with FLUX:

# Submit the image generation request
curl -X 'POST' \
  'https://api.bfl.ai/v1/flux-2-pro-preview' \
  -H 'accept: application/json' \
  -H "x-key: ${BFL_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "A cat running like a human holding a silver fish in a market",
    "width": 1024,
    "height": 1024
  }'

The response contains an id and a polling_url. Poll that URL until the status is "Ready", then read the image URL from result.sample:

// Example response
{
  "id": "your-request-id",
  "polling_url": "https://api.bfl.ai/v1/get_result?id=your-request-id"
}

Use the polling_url to check the status of your request:

curl -s 'https://api.bfl.ai/v1/get_result?id=your-request-id' \
  -H "x-key: ${BFL_API_KEY}"

When the status is "Ready", the response will include the image URL in result.sample. For the full set of endpoints and parameters, see FLUX's official API docs.

Can You Use the FLUX API for Free?

Creating an API key is free, but using it requires paying per image. FLUX bills per generated image rather than per token, and on the FLUX.2 family the price scales with the resolution you generate. There is no native free tier, so check the BFL pricing page for current rates.

Puter.js offers a different model. With its User-Pays model, you can add FLUX models to your app for free: each user covers their own AI usage through their own Puter account, so your cost stays at $0 regardless of how many users you have, with no API key and no backend.

Add FLUX models with the browser script tag:

<script src="https://js.puter.com/v2/"></script>
<script>
  puter.ai.txt2img("A cat running like a human holding a silver fish in a market", {
    model: "black-forest-labs/flux-2-pro"
  }).then(imageElement => {
    document.body.appendChild(imageElement);
  });
</script>

or the npm package:

import { puter } from '@heyputer/puter.js';

const imageElement = await puter.ai.txt2img("A cat running like a human holding a silver fish in a market", {
  model: "black-forest-labs/flux-2-pro"
});
document.body.appendChild(imageElement);

This fits front-end apps where your users sign into Puter: usage is tied to their accounts, and Puter.js runs in the browser, so it does not replace a server-side key for a backend you control. For a backend, see the pricing below.

How Much Does the FLUX API Cost?

FLUX is an image generation API, so you pay per image rather than per token, and on the FLUX.2 family the price scales with the resolution you generate. FLUX.2 [max], the top model in the lineup, starts at $0.07 per image. The cheapest option is FLUX.2 [klein] 4B at $0.014 per image. The older FLUX.1 and Kontext models use flat credit pricing, where one credit equals $0.01.

For the full breakdown, see our FLUX API pricing guide.

Conclusion

To get a FLUX API key: sign up at dashboard.bfl.ai, add a payment method, then go to Keys under the API group and click Add Key. From there you can make your first API call, or skip the key entirely and add FLUX models to a web app for free with Puter.js.

Ship a Full-Stack App with One Prompt

Give this to your AI Build an AI chat app using Puter.js