GPT Image 2.6: Add Asset Lineage and Idempotent Retries to a Two-Stage Pipeline
GPT Image 2.6 makes it practical to separate fast visual exploration from precise editing. But once an application uses two calls instead of one, a new problem appears: retries, callbacks, and user revisions can produce
GPT Image 2.6 makes it practical to separate fast visual exploration from precise editing. But once an application uses two calls instead of one, a new problem appears: retries, callbacks, and user revisions can produce duplicate or untraceable assets.
The fix is not another prompt trick. It is an application-level asset lineage contract: every generated image, edit, and review decision points back to an immutable request record. This article builds that pattern with Flare for initial generation and Sunburst for a controlled edit.
Disclosure: This article was prepared for an Ace Data Cloud promotional task and is commercially related to its GPT Image 2.6 offering. It adapts Ace Data Cloud's public product materials and API documentation with AI assistance. The code is illustrative, uses placeholder credentials, and was not executed for this article; this is not presented as an independent customer test.
The failure mode: a URL is not provenance
Suppose a user generates a product hero image, approves it, and asks to change only the background. Your service times out after submitting the edit, so the worker retries. Both requests may eventually succeed. If the database stores only the latest image URL, you cannot answer basic questions:
- Which prompt and model produced this file?
- Was it generated from text or edited from an approved parent?
- Did a retry create it twice?
- Which output did the user approve?
Treat returned URLs as delivery locations, not primary identities. Give each logical operation a stable key, store the provider task identifier separately, and make parent-child relationships explicit.
A minimal lineage model
A compact SQL table is enough to begin:
create table image_jobs (
id uuid primary key,
idempotency_key text unique not null,
parent_asset_id uuid,
operation text not null check (operation in ('generate', 'edit')),
model text not null,
request_json jsonb not null,
request_hash text not null,
provider_task_id text,
status text not null,
result_url text,
error_json jsonb,
created_at timestamptz not null default now(),
completed_at timestamptz
);
parent_asset_id is null for an original generation and points to the approved source for an edit. request_hash detects accidental mutation. The unique idempotency_key prevents your queue from creating a second logical job when a client or worker retries.
The public API documentation describes asynchronous submission with async: true, which returns a task_id; a callback_url can also be supplied for push delivery. The idempotency layer shown here belongs to your applicationβit is not a claim that the image endpoint accepts an idempotency header.
Stage 1: generate and record the candidate
Use GPT Image 2.6 Flare when rapid exploration is the priority. The current Images Generations documentation requires model and prompt and supports asynchronous processing.
// Illustrative example; not executed here.
const spec = {
model: "gpt-image-2.6-flare",
prompt: "Studio product photo of a reusable bottle on pale gray, centered",
size: "1024x1024",
quality: "low",
output_format: "png",
async: true,
callback_url: "https://example.com/hooks/image-jobs"
};
const idempotencyKey = `hero:${campaignId}:v1:generate`;
const job = await findOrCreateJob(idempotencyKey, spec);
if (!job.provider_task_id) {
const response = await fetch(
"https://api.acedata.cloud/openai/images/generations",
{
method: "POST",
headers: {
Authorization: "Bearer <YOUR_API_KEY>",
"Content-Type": "application/json"
},
body: JSON.stringify(spec)
}
);
if (!response.ok) throw new Error(`generation failed: ${response.status}`);
const submitted = await response.json();
await saveProviderTask(job.id, submitted.task_id);
}
Do not put a random value or timestamp in the idempotency key. It should describe the user's logical intent. If the prompt changes, create v2; if only transport failed, reuse v1.
Stage 2: edit from an approved parent
After review, freeze the selected candidate as an asset. Then create a child job using GPT Image 2.6 Sunburst for the bounded revision. The Images Edits documentation accepts an image URL in JSON mode and requires image plus prompt.
const editSpec = {
model: "gpt-image-2.6-sunburst",
image: approvedAsset.url,
prompt: [
"Replace only the background with warm limestone.",
"Preserve bottle geometry, label text, camera angle, and shadow direction."
].join(" "),
size: "1024x1024",
quality: "high",
output_format: "png",
async: true,
callback_url: "https://example.com/hooks/image-jobs"
};
const editKey = `hero:${campaignId}:v1:bg-limestone`;
await findOrCreateJob(editKey, editSpec, approvedAsset.id);
This division is a workflow choice, not a guarantee that every edit will preserve every pixel. Keep the original parent immutable and route the child through review before promotion.
Make callbacks replay-safe
Callbacks can arrive more than once or after a polling worker has already stored the result. Handle them as state transitions rather than commands:
async function receiveCallback(payload) {
const job = await findByProviderTaskId(payload.task_id);
if (!job || job.status === "succeeded") return;
if (!payload.success) {
await markFailed(job.id, payload.error ?? payload);
return;
}
const url = payload.data?.data?.[0]?.url;
if (!url) throw new Error("successful callback contained no result URL");
await markSucceededOnce(job.id, url, payload.trace_id);
}
In production, also authenticate webhook traffic using the mechanism documented for your deployment, validate payload size and content type, and commit the status change transactionally. Retry 429 and transient 5xx responses with capped exponential backoff; stop and surface 401 or 403 because repeating an unauthorized request does not repair credentials or access.
Store evidence, not just the final picture
For each accepted asset, retain:
- the exact request JSON and its hash;
- model name and parent asset ID;
- provider
task_idandtrace_idwhen available; - original result URL plus a durable copy in storage you control, if permitted;
- MIME type, dimensions, byte hash, and review decision.
A URL can expire or be replaced; a content hash and immutable metadata make later audits possible. This also lets a UI display a real version tree instead of a misleading βlatest imageβ slot.
Flare and Sunburst are also available through Ace Data Cloud Studio for manual exploration. For an application, however, lineage and replay-safe state transitions are what turn generation and precise editing into a dependable system.
Sources
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.