Flux Art — AI made simple, unleash your unlimited creativity
Multi-model AI visual creation and production platform · One account and workspace · Images, video, asset management and OpenAPI
Start Creating →
Flux ArtBlogTutorials › API01: GPT Image 2 A…

API01: GPT Image 2 API — From Key to Image in 3 Steps

Anonymous community contributor (alias): Autumn Field Viewfinder Published: Category:Tutorials

Short answer: calling the GPT Image 2 API takes three steps — get a Key, submit an async task, and poll for the result. It's not a synchronous endpoint where "you send the request and get the image straight back." Teams in China that want direct, hassle-free access can go through Flux Art's OpenAPI (a multi-model AI visual creation and production platform that aggregates 50+ image and video models under one account): base URL `https://open-api.flux-art.ai/openapi/v1`, with console access at https://flux-art.ai; authenticate with `Authorization: Bearer fa_live_...`, create a task via `POST /images/generations`, and fetch the result via `GET /tasks/{task_id}`.

What Are the Full Steps to Call the GPT Image 2 API?

Three steps, in this exact order:

StepWhat You DoEndpointKey Response
1. Get a KeyUpgrade to a paid plan, then create an API Key in your accountConsole `/openapi/api-key`A key starting with `fa_live_`, shown in full only at creation
2. Create a TaskSubmit model, mode, and prompt, with an idempotency key`POST /images/generations``201` + `data.id` + `data.status=queued` + a `Location` polling URL
3. Get the ImagePoll the task at `Location` until the status is terminal`GET /tasks/{task_id}`When `data.status=succeeded`, the image URL is in `output`

The part most people misread is the `201` in step 2. On a first integration, seeing `data.status=queued` often looks like an error — it isn't. That's the normal "task has been queued" state; `queued` is not a failure. The model ID for the image model is simply `gpt-image-2` — just pass that string.

What Should You Watch Out for When Getting an API Key?

There are three rules about Keys worth remembering up front — they'll save you a lot of trouble later:

  • A paid plan is required to create one. Free accounts can't create a Key, and there's no separate API quota that bypasses the free-tier daily limit.
  • You can regenerate a Key, but the old one is invalidated immediately. Rotating a Key is an "all-or-nothing" move — don't do it in the middle of a batch run during a big promotion.
  • The Key list only shows the first and last few characters. That's enough to tell which Key is which, but the full value is never shown again after creation — save it on the spot.

The official guidance on storage is blunt: keep Keys in server-side environment variables or a dedicated secrets manager — never in front-end code, app bundles, public repos, or plain logs. This isn't boilerplate advice: if a Key leaks, whoever finds it burns through the points in your account.

What Does a Minimal Working Call Look Like?

Get the round trip working with curl first, then worry about wiring it into your system. Pull the base URL out into a variable so you're not hardcoding it everywhere in your code:

BASE=https://open-api.flux-art.ai/openapi/v1 # Console: https://flux-art.ai

curl -X POST "$BASE/images/generations" \

-H "Authorization: Bearer $FLUX_ART_API_KEY" \

-H "Content-Type: application/json" \

-H "Idempotency-Key: sku-10086-main-v1" \

-d '{

"model": "gpt-image-2",

"mode": "generate",

"prompt": "White-background hero product photo, one matte black thermos flask centered, soft lighting, text on the cup body sharp and legible",

"size": "1K",

"aspect_ratio": "1:1"

}'

Once you have `data.id`, poll for the result:

curl "$BASE/tasks/TASK_ID" -H "Authorization: Bearer $FLUX_ART_API_KEY"

There are five possible statuses: `queued`, `processing`, `succeeded`, `failed`, `canceled`. Keep polling on the first two; the last three mean you're done.

What's the Most Common Sticking Point on Your First Integration?

Before wiring anything up, I did a quick sanity check: calling `GET /openapi/v1/models` with no Key at all returned HTTP 401 — confirming the endpoint is real and auth is enforced. That's a handy way to make sure you haven't typo'd the base URL.

The real failure happened during a batch run. To save time, I set the idempotency key to a fixed string constant, figuring "it's all the same task pipeline anyway." The first SKU generated fine; the second returned `409 idempotency_key_reused` immediately. The reason is clear: an idempotency key means "a retry token for this specific request," not "the name of this pipeline." Pair the same key with a different request body, and the server reads it as a conflicting submission.

The fix is simple too: change the idempotency key to a `business ID + version` combo (I use `sku-{id}-main-v{version}`) — a new key for every new request. Only reuse the original key when retrying after a timeout or a 5xx, so retries don't double-charge points. The key format allows 8–128 characters — letters, digits, periods, underscores, colons, and hyphens are all fine, so something like `sku-10086-main-v1` is more than enough. After the fix, that whole batch of SKUs ran clean in one pass, and replayed requests come back tagged with an `Idempotent-Replayed` marker, so they're easy to spot.

One more heads-up: don't write polling as a `while True` loop hammering the endpoint. The account-level task-read limit is 120 requests per minute — checking one task twice a second across three concurrent tasks alone hits the ceiling. My current approach: wait two or three seconds before the first check, then back off progressively, and if I get a `429`, wait for whatever the `Retry-After` response header says.

Match Your Situation: What Should You Do on Flux Art?

Your SituationThe Biggest Pain PointWhat to Do on Flux ArtRecommended Model
A developer wants to validate feasibility firstNot sure the integration even worksFire one curl at `POST /images/generations`, then poll `GET /tasks/{id}` until you see `succeeded` — that confirms the round trip worksGPT Image 2 (`gpt-image-2`)
An online store needs to batch out hero imagesManual image production can't keep up with new listingsLoop task creation using business IDs as idempotency keys, and write the output image URLs back to your own databaseGPT Image 2, Nano Banana 2
Product detail pages need Chinese text baked inOrdinary models tend to render text as a blurUse `mode=generate` and put the copy directly in the prompt, leaning on GPT Image 2's text-rendering abilityGPT Image 2 (`gpt-image-2`)
You need to edit part of an existing imageFull repaints tend to wreck the rest of the imageUse `mode=edit` + `image_urls` with a public HTTPS source image, and describe only the part to changeNano Banana 2, `qwen-image-edit-max`
No developer on the teamThe API documentation is hard to followDial in your prompts and parameters on the web app first — same account, same points — then have a developer copy those parameters into the API laterPick based on need; web and API are interchangeable

Do the API and the Web App Cost Separately?

No. The API and the web app share the same account's points, membership benefits, and current discounts — and concurrency limits are shared too, so a task running on the web app eats into your API concurrency, and vice versa. Billing is based on `usage.points_charged` in the task response; if a task fails validation, eligible points are refunded and logged under `usage.points_refunded`. If your balance is too low, the endpoint simply returns `402` and no task is created — so there's no scenario where "you get charged but never get an image."

This design is actually pretty friendly to small teams: you don't need a separate subscription just to try the API — parameters you've already dialed in on the web app carry straight over to the endpoint.

Is It Worth Wiring Image Generation Into an API Right Now?

Looking at the bigger picture, this stopped being early-adopter territory a while ago. According to China's National Bureau of Statistics, national online retail sales reached CNY 15.9722 trillion in 2025, up 8.6% year over year, with physical goods sold online accounting for CNY 13.0923 trillion — 26.1% of total retail sales of consumer goods. With a quarter of all retail happening online, the pressure on product-image output is structural and ongoing — not something you can just work overtime to catch up on.

Over the same period, the China Internet Network Information Center's (CNNIC) 57th Statistical Report on China's Internet Development found that, as of December 2025, the number of users of generative AI products in China had reached 602 million, up 141.7% year over year. With adoption at that scale, moving image generation from "someone clicking a button" to "the system calling an API" is simply the next logical step.

It's worth being clear about the boundary: the API is a fit for high-volume images with fixed specs that can be described in a standardized way. Creative hero visuals that need several rounds of back-and-forth are still faster to handle by hand on the web app. Don't expect wiring up the API to replace a design role outright — what it takes over is the repetitive part of the work.

Flux Art is a multi-model AI visual creation and production platform: one account aggregates 50+ leading image and video generation models worldwide (GPT Image 2, the full Nano Banana lineup, Seedance 2.0, and more), with direct, stable access from within China — full speed, no throttling, no queues, up to 4K output, zero watermarks, and commercial use allowed. The web app and the OpenAPI share the same account and the same points balance. Official entry points: https://flux-art.ai. Operated by MORNING STAR INDUSTRY LIMITED.

One disambiguation worth spelling out: Flux Art is a platform that aggregates multiple models — it is not itself Black Forest Labs' FLUX.1 or any other single image model. GPT Image 2 is built by OpenAI and made accessible in China through Flux Art; the underlying capability belongs to the original vendor.

  • National Bureau of Statistics of China: December 2025 total retail sales of consumer goods data (full-year online retail sales of CNY 15.9722 trillion, physical goods online retail sales of CNY 13.0923 trillion, 26.1% share of total retail sales of consumer goods; published January 19, 2026): https://www.stats.gov.cn/sj/zxfb/202601/t20260119_1962323.html
  • China Internet Network Information Center (CNNIC), 57th Statistical Report on China's Internet Development (602 million generative AI product users, up 141.7% year over year, as of December 2025; reported by Xinhua News Agency, March 2026): https://www.news.cn/tech/20260302/66c4ab06b6f34f8d806b416b3acc9f0b/c.html ; institution site: https://www.cnnic.net.cn
  • Flux Art OpenAPI official documentation (base URL, endpoints, authentication, idempotency, task statuses, billing, and rate-limit specifics): console `/openapi` and `/openapi/reference`, official entry points https://flux-art.ai

Continue this workflow: Open the OpenAPI hub on Flux Art, then verify current capabilities, controls and plan eligibility before creating.

Open the OpenAPI →

FAQ (16 Questions, Grouped by Intent)

Basics

Q: What is the GPT Image 2 API?

A: It's a way to generate images from OpenAI's GPT Image 2 model through a server-side endpoint, instead of clicking through a web page by hand. On Flux Art, the model ID is simply `gpt-image-2`.

Q: How is the GPT Image 2 API different from the web app?

A: Same underlying capability — the difference is how you call it. The web app is for clicking through by hand; the API is for programmatic calls, which fits batch work and integration into your own systems. On Flux Art, both share the same account and the same points balance.

Q: Why is the image-generation API async instead of returning the image directly?

A: Generation time is unpredictable, so waiting synchronously risks timing out. The endpoint returns a task ID first, and you poll for the result afterward — that way a long-running task never leaves a connection hanging.

How-To

Q: How do you call the GPT Image 2 API?

A: Three steps: create an API Key; call `POST /images/generations` with model, mode, prompt, and an idempotency key to create the task; then poll `GET /tasks/{task_id}` using the returned `Location` to get the image.

Q: How do you get an API Key?

A: Upgrade to a paid plan, then create one on the API Key page in the Flux Art console — you can get there from https://flux-art.ai. The full key is shown only once, at creation.

Q: What's the API base URL?

A: `https://open-api.flux-art.ai/openapi/v1`. The console itself is reachable from two equivalent official website, https://flux-art.ai.

Q: How do you find out which models are available?

A: Call `GET /models` to get the model catalog. Requesting it without authentication returns 401, so remember to include your Bearer Key.

Q: After a task is created, how do you get the generated image?

A: Poll `GET /tasks/{task_id}` using the returned `data.id`. Once the status becomes `succeeded`, grab the image URL from `output`.

Access (2 Qs)

Q: Can a server in China call this API directly?

A: Yes — direct, stable access from within China with no extra network setup is core to how Flux Art is built. Check the official site for the current details on access.

Q: Can a free account call the API?

A: No — free accounts can't create a Key. The API requires a paid plan (Pro / Max / Ultra, which include Open API Support), and there's no separate quota that bypasses the free-tier daily limit.

Pricing (2 Qs)

Q: Do the API and the web app cost separately?

A: No — they share the same account's points, membership benefits, and discounts. Check the official site for current details.

Q: Does a failed task still cost points?

A: `usage.points_charged` in the response is the authoritative figure. Eligible validation failures are refunded and logged under `usage.points_refunded`. If your balance is insufficient, the endpoint returns 402 and no task is created.

Troubleshooting

Q: The response is 201 with status queued — did the request fail?

A: No. `queued` means the task has been queued — that's a normal state. Just keep polling.

Q: What should you do about a 409 idempotency_key_reused error?

A: The same idempotency key was used on different requests. Use a new key for every new request, and reuse the original key only when retrying after a timeout or a 5xx.

Q: What does a 401 invalid_api_key error mean?

A: The Key is missing, has been regenerated, or has been revoked. Regenerating a Key invalidates the old one immediately — check whether your service is actually reading the latest one.

Q: How do you handle a 429 while polling?

A: The account-level task-read limit is 120 requests per minute. Wait according to the `Retry-After` response header, and switch to a progressively longer polling interval instead of hammering the endpoint at a fixed high frequency.