How to Use Flux.2 API? All You Need to Know
FLUX.2 is Black Forest Labs’ second-generation family of image-generation and image-editing models (released Nov 25, 2025). It offers production-grade photorealism, multi-reference editing up to 4MP, structured/JSON prompting, and a choice of managed endpoints (Pro, Flex) and open-weight options (Dev).
The good news is that CometAPI has integrated the Flux.2 API. This guide explains what FLUX.2 is, , how to call the API, and advanced workflows (text→image, flexible control, multi-reference editing), with code examples and best practices.
What is FLUX.2 and why does it matter?
FLUX.2 is the follow-up to the FLUX family of image models — engineered for high-fidelity text-to-image generation and multi-reference image editing at production resolutions (up to ~4 megapixels). FLUX.2 is built for real creative workflows (brand-safe assets, consistent characters and styles across references, better typography and small details) rather than demos, and that it aims to close the gap between generated and real imagery.
Key outcomes FLUX.2 is designed to deliver
- Photorealistic outputs suitable for advertising, product imagery, and UI mockups.
- Native multi-reference editing: combine, swap, or compose elements from multiple input images in a single edit.
- Variants for different use cases: openly-available developer models, a Pro endpoint optimized for production, and a Flex endpoint for low-level control.
At a high level, FLUX.2 combines a latent generative backbone (flow/transformer architecture) with a vision–language model for semantic grounding, and a newly-trained VAE to provide a shared latent space across variants. This design lets the model do both generation and reconstruction (editing) at higher fidelity while keeping the representation learnable for training and fine-tuning. The open VAE is particularly notable because it standardizes the latent space for hosted and self-hosted workflows.
Why that matters: coupling language and latent flow matching yields stronger prompt following (so multi-part, compositional instructions behave predictably), better typography, and a single architecture that supports both generation and editing with multiple references. For creators, that means more reliable outputs for complex instructions and mixed inputs (text + images).
How do I access the FLUX.2 API?
Prepare the environment
Register and log in to CometAPI and obtain your API key from your profile panel. Ideally, you should have some API knowledge as a developer (we will provide assistance in this regard, so please don’t worry).
You will also need to select your desired request method and the appropriate Flux.2 model.
What endpoints, authenticationare required?
The Replicate Predictions API provides access to generate high-quality images using various FLUX models from Black Forest Labs through the standard Replicate format. This API supports a comprehensive range of FLUX model variants, each optimized for different use cases from rapid prototyping to professional-grade image generation. Users can seamlessly switch between different models by simply changing the model name in the URL path(https://api.cometapi.com/replicate/v1/models/{models}/predictions), making it flexible for various creative and commercial applications.
CometAPI exposes managed endpoints under https://api.cometapi.com/flux/v1/{model} and names endpoints like flux-2-pro, flux-2-flex and flux-2-flex for image creation and editing. Requests require an API key in the x-key header .
Model family & compute tradeoffs
- FLUX.2 [dev] (open weights) — Use when you need local control, research experiments, or to run inference on your own infrastructure. Dev is open-weight (32B) and excellent for exploratory research and fine-tuning. It’s more configurable, but you’re responsible for infra and optimization.
- FLUX.2 pro — Best balance of speed, quality, and cost for production. Pro is tuned for predictable latency, consistent prompt adherence, fast throughput, and supports up to 8 API reference images (9MP total via API). Use this for high-volume editing and when you need reliability and predictable pricing.
- FLUX.2 [flex] (managed + controllability) — Exposes low-level generation controls (e.g.,
steps,guidance) and supports more references (up to 10) and slightly higher quality/detail when you accept higher latency and cost. Use Flex when you need the final creative control — typography fidelity, exact colors, or highly detailed composition adjustments.
Prototype on Dev or a low-cost Pro plan, then migrate to Pro for scale or Flex for highly controlled final renders.
How do I use the FLUX.2 API?
Request lifecycle (task + polling model)
Responses to editing/generation requests are task objects that include a polling_url and id; you create a request and then poll (or use webhooks) to retrieve the signed result URL. Signed URLs are short-lived (typically ~10 minutes) so fetch outputs promptly.
The hosted API follows an asynchronous task model:
- POST a generation request → returns a
task idandpolling_urlplus estimatedcost. - Poll the
polling_urluntilstatus == "Ready", then retrieve the image result (often base64 or a hosted URL).
Example: Python (requests) — submit & poll
import time, requests, os
API_KEY = os.environ["CometAPI_API_KEY"]
API_URL = "https://api.cometapi.com/flux/v1/flux-2-pro"
payload = {
"prompt": "A high-end product photo of a ceramic mug on a wooden desk, soft window light.",
"width": 1024, "height": 1024, "seed": 42
}
r = requests.post(API_URL, headers={"x-key": API_KEY, "accept":"application/json"}, json=payload)
r.raise_for_status()
task = r.json()
polling_url = task["polling_url"]
while True:
time.sleep(0.5)
status_r = requests.get(polling_url, headers={"x-key": API_KEY})
status_r.raise_for_status()
status = status_r.json()
if status["status"] == "Ready":
print("Result URL:", status["result"]["sample"])
break
elif status["status"] in ("Error", "Failed"):
print("Generation failed:", status)
break
This pattern (submit → poll or webhook) is the primary synchronous/asynchronous flow for the managed endpoints.
Image Editing — minimal example (curl with input URL)
curl -X POST "https://api.cometapi.com/flux/v1/flux-2-pro" \
-H "accept: application/json" \
-H "x-key: $CometAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Replace the background with a sunlit seaside boardwalk, keep the person intact and match lighting",
"input_image": "https://example.com/my-photo.jpg",
"width": 2048,
"height": 1536
}'
For multi-reference editing, use input_image, input_image_2, input_image_3, … (Pro supports up to 8 references via API; Flex up to 10; Dev recommended max ~6 depending on memory).
What basic parameters should I send?
Important request body fields (image editing / generation) include:
[flex only]guidanceandsteps— allow fine-grained control.prompt(string) — up to 32K tokens; detailed natural language or structured JSON.input_image(string) — required for edits (URL or base64).input_image_2…input_image_9— multi-reference images.width/height— multiples of 16; output max 4MP.seed— integer for reproducibility.safety_tolerance— moderation level.
How can I leverage FLUX.2 Pro for professional text-to-image generation?
FLUX.2 Pro is tuned for reliable, high-quality outputs. Use it when you need consistent brand-level results, fast turnaround, and enterprise SLAs.
Workflow recipe — production imagery
- Preprocess prompts: keep a short “intent” line plus a structured attributes section (lighting, lens, mood, color hex codes for brand colors). FLUX.2 supports hex color steering to help preserve brand palettes.
- Start with conservative defaults: steps 30–50 and guidance scale 6–9.0; increase steps for details, increase guidance to make results adhere more strictly to the prompt.
- Use seeds + deterministic sampling for reproducibility in A/B testing.
- Use the Pro endpoint for multi-try sampling: request N variations in parallel and pick best — cheaper and faster than manual hyperparameter tuning.
- Post-process: denoise, minor tone mapping, or vector-style touchups in a deterministic pipeline. Consider a small GAN or super-resolution pass if you need higher than native output.
Why these steps help: Pro balances speed and fidelity and usually enforces post-generation safety/content filters, so it’s the sensible default for customer-facing assets.
Best tips for generating images
1. Structured prompting wins for production. Organize prompts by priority: subject → action → style → context. Use JSON prompting (scene, subjects, camera, lighting, color_palette) when you need deterministic composition across many images. Example JSON schema usage (pseudo):
{
"scene": "product shot",
"subjects": [
{"type":"mug","pose":"center","style":"ceramic, matte"},
{"type":"background","style":"wooden desk, window light"}
],
"camera": {"focal_length":"85mm","aperture":"f2.8","angle":"slightly above"}
}
2. Reproducibility: Pass seed to reproduce later. Keep a catalog mapping prompt + seed → image for traceability.
3. Batch & orchestration: For large production runs, submit many requests in parallel to Pro, but rate-limit to avoid throttling; prefer the Pro endpoint for predictable latency. Use job queues and worker pools to download signed results quickly once ready.
4. Moderation & safety: Use safety_tolerance to control moderation strictness. Pro endpoints include usage policies and content moderation hooks; integrate server-side checks before publishing.
5. Postprocessing: Pro outputs are high quality but occasionally need small retouches. Build an automated postprocess step (crop, color-grade, composite) in your pipeline and keep human review for brand sensitive assets.
How can I customize outputs with the FLUX.2 Flex endpoint?
Flex is the “surgical tool” variant: tune steps, guidance, negative prompts, tile sizes, and reference counts to shape the output precisely.
When to choose Flex
- You need precise typographic rendering (UI mockups, labels).
- You must composite multiple references with control over pose and lighting.
- You are experimenting with advanced prompt techniques (structured prompts, chains of constraints).
Example — Flex control keys and their effects
steps— more steps = finer detail (at cost of latency).guidance_scale— higher = closer to text prompt, lower = more creativity.negative_prompt— explicitly remove elements (e.g., “no watermark, no extra fingers”).tile_size/tiled_inference— for very high resolution generation, tile inference space to trade memory for speed.reference_weights— some endpoints let you weight references to bias which image drives pose vs. style.
Practical tip: For complex compositions, run a short, low-guidance preview to verify composition, then upscale with more steps and higher guidance. This two-pass technique reduces cost while giving precise final outputs.
Example: Flex request with steps & guidance
curl -X POST "https://api.bfl.ai/v1/flux-2-flex" \
-H "Content-Type: application/json" \
-H "x-key: $BFL_API_KEY" \
-d '{
"prompt": "Cinematic movie poster, bold typography at top, main character centered, dramatic rim lighting",
"width": 1536, "height": 2048,
"steps": 50,
"guidance": 7.5,
"seed": 99999
}'
Tip: Use Flex during final creative sign-offs and Pro for large-scale, faster pipelines. Flex is noticeably more controllable for typography and micro-detail tasks.
Best practices for production usage
Below are battle-tested patterns and pragmatic advice for integrating FLUX.2 at scale.
1) Control cost by tracking megapixels & caching
FLUX.2 billing is based on megapixels of input + output. For high-volume generation, prefer smaller preview renders (low-res quick steps) and only escalate to higher MP final renders. Cache rendered assets (or store diffs) so you don’t re-render identical jobs. Always surface cost in responses and log it per request.
2) Use tiers smartly: preview vs final-render split
- Run fast, low-step Pro renders for prototyping or many variants.
- Use Flex or high-MP Pro runs for final-approved outputs where fidelity matters. This hybrid approach balances throughput and final image quality.
3) Prompt engineering → structured prompts & JSON
Take advantage of FLUX.2’s structured JSON prompting when you need deterministic composition (scene objects, camera, poses, hex color swatches). This reduces iterative prompting cycles and leads to more reproducible batches. Cloudflare examples show JSON prompts embedded in multipart forms.
4) Seed + versioning for reproducibility
When you need reproducible results, pass a seed and record model version/timestamp in metadata. For deterministic asset pipelines keep a manifest: prompt, seed, model variant, resolution, reference image hashes. This improves traceability and rollback options.
Conclusion
FLUX.2 is aimed squarely at closing the gap between “impressive demo” and “production creative tool.” With multi-reference editing, high-resolution outputs, and a set of hosted endpoints (plus open inference code and quantized consumer builds), it gives teams a lot of practical options: run locally for research and customization, or use the hosted Pro/Flex endpoints for stable production pipelines.
Developers can access Flux.2 Dev API, Flux.2 Flex API and Flux.2 Pro API through CometAPI. To begin, explore the model capabilities of CometAPI in the Playground and consult the Continue API guide for detailed instructions. Before accessing, please make sure you have logged in to CometAPI and obtained the API key. CometAPI offer a price far lower than the official price to help you integrate.
Ready to Go?→ Sign up for CometAPI today !
If you want to know more tips, guides and news on AI follow us on VK, X and Discord!

