Browse all docs & guides
On this page
OPERATION & PLATFORM GUIDE

Edit images with private references and masks

OpenGen image editing pairs workspace-private uploaded assets with one canonical input schema across 25 image models. Upload your source image via POST /v1/assets to receive a ready assetKey, pass it inside input.references (plus optional input.mask on models such as GPT Image 2), check pricing with POST /v1/pricing/estimate, and submit once with a persisted Idempotency-Key so retries never double-bill.

operation: image-editReviewed 2026-12-02
AGENT PROMPT · PASTE INTO YOUR AGENT OR AUTO-READ
Walk me through an image-edit generation on OpenGen (https://opengen.dev):
1. Discover models supporting image-edit via GET https://opengen.dev/v1/models?operation=image-edit (or MCP find_models with operation="image-edit"; add inputRole="mask" if inpainting is needed).
2. Inspect the exact model via GET https://opengen.dev/v1/models/{provider}/{model}?operation=image-edit (or MCP get_model, e.g. id="openai/gpt-image-2", operation="image-edit") to check maximum reference counts, mask support, and published pricing.
3. Upload each private source image (and optional mask) using POST https://opengen.dev/v1/assets (or MCP upload_asset) and confirm state="ready" before referencing its assetKey.
4. Estimate spend via POST https://opengen.dev/v1/pricing/estimate (or MCP estimate_cost) and confirm the route and maxCostMicros cap with me.
5. Submit once with a persisted Idempotency-Key via POST https://opengen.dev/v1/generations (Prefer: wait=20) or MCP generate (waitMs=20000), then follow or refresh private output links via job_get without blind resubmission.
View raw .md ↗

OpenGen image-edit transforms one or more workspace-private reference images using natural-language instructions and, on mask-capable variants, an explicit alpha mask. Source images always enter through OpenGen's private asset API so files stay scoped to your workspace rather than being published to public URLs.

Prerequisites

  • An OpenGen credential with read and generate scopes (OPENGEN_API_KEY, MCP OAuth on https://opengen.dev/mcp, or @opengen-dev/cli login).
  • A local PNG, JPEG, or WebP source image you own or have permission to edit (plus an optional PNG mask when using mask inpainting).

1. Inspect an image-edit model and its media limits

Reference limits, mask support, and transparent-background rules vary by exact variant. Check them before uploading or building a payload:

  • GPT Image 2 (openai/gpt-image-2, official route openai-undisclosed/openai-gpt-image-2 is live-verified for text-to-image at 1K, while image-edit remains documented with an active OpenAI adapter): up to 16 image references, supports optional mask, background: "transparent" with png/webp, and 1K–4K output.
  • Seedream 5.0 Pro (bytedance/seedream-5.0-pro): up to 10 image references, supports constrained transparent PNG editing (references.length === 1, background: "transparent", outputFormat: "png").
  • Nano Banana 2 (google/nano-banana-2): 0.5K–4K editing, up to 14 references, with thinkingLevel: "minimal" | "high".
# Filter models supporting image-edit (add &inputRole=mask for mask inpainting)
curl --fail-with-body \
  "https://opengen.dev/v1/models?operation=image-edit&inputRole=mask"

# Inspect exact schema, routes, and published pricing for GPT Image 2
curl --fail-with-body \
  "https://opengen.dev/v1/models/openai/gpt-image-2?operation=image-edit"

2. Upload your private source image (and optional mask)

Use POST /v1/assets to register your source image privately inside your workspace. Single-step multipart/form-data handles files up to 4 MiB (JSON base64 handles up to 3 MiB decoded; files up to 100 MiB use presigned single-PUT + POST /v1/assets/complete—see Owned Assets). Require state: "ready" before referencing assetKey.

curl --fail-with-body \
  -X POST "https://opengen.dev/v1/assets" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Idempotency-Key: asset-src-$(uuidgen | tr '[:upper:]' '[:lower:]')" \
  -F "file=@./ceramic-mug.png;type=image/png"

3. Estimate route eligibility before submitting

Pass uploaded images in input.references as { "type": "image", "asset": { "assetKey": "..." } }. Image operations never use video-frame fields (firstFrame or lastFrame).

set -eu
umask 077
if [ -e edit-submission.key ]; then
  echo "Existing edit-submission.key found; recover read-only via GET /v1/generations/lookup before replacing edit-request.json." >&2
  exit 1
fi
rm -f edit-request.json
cat <<'JSON' > edit-request.json
{
  "modelId": "openai/gpt-image-2",
  "operation": "image-edit",
  "input": {
    "prompt": "Replace the tabletop background with warm honed travertine stone while keeping the ceramic mug and shadows identical.",
    "references": [
      {
        "type": "image",
        "asset": {
          "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_IMAGE_UUID.png"
        }
      }
    ],
    "resolution": "1K",
    "quality": "medium",
    "outputFormat": "png"
  },
  "routeId": "openai-undisclosed/openai-gpt-image-2",
  "billing": "byok"
}
JSON
chmod 600 edit-request.json

# Dry-run estimate only (review selectedRouteId and workspaceEligibility before submitting)
curl --fail-with-body \
  -X POST "https://opengen.dev/v1/pricing/estimate" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  --data @edit-request.json

Submit once after reviewing the estimate

Run this step only after reviewing the estimate output above and confirming selectedRouteId, workspaceEligibility (policyAllowed: true, hasActiveBillingHold: false, executableCandidateCount > 0, blockers: []), and your BYOK billing payer.

set -eu
umask 077
if [ -e edit-submission.key ]; then
  echo "Existing edit-submission.key found; recover read-only via GET /v1/generations/lookup before creating a new submission." >&2
  exit 1
fi
RAW_UUID="$(uuidgen)"
[ -n "$RAW_UUID" ] || { echo "uuidgen failed" >&2; exit 1; }
IDEMPOTENCY_KEY="edit-$(printf '%s' "$RAW_UUID" | tr '[:upper:]' '[:lower:]')"
(set -C; printf '%s\n' "$IDEMPOTENCY_KEY" > edit-submission.key)

curl --fail-with-body \
  -X POST "https://opengen.dev/v1/generations" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Prefer: wait=20" \
  --data @edit-request.json > edit-receipt.json

Adding an optional inpainting mask

On mask-capable variants (openai/gpt-image-2, openai/gpt-image-2.5-*, openai/gpt-image-2.6-*), upload a second workspace-private PNG mask and attach it under input.mask alongside at least one image entry in input.references (using "billing": "byok" since managed image-edit quotes are currently comparison-only):

JSON
{
  "modelId": "openai/gpt-image-2",
  "operation": "image-edit",
  "input": {
    "prompt": "Replace only the masked mug handle with fluted matte brass.",
    "references": [
      {
        "type": "image",
        "asset": {
          "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_IMAGE_UUID.png"
        }
      }
    ],
    "mask": {
      "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_MASK_UUID.png"
    },
    "resolution": "1K",
    "quality": "medium",
    "outputFormat": "png"
  },
  "routeId": "openai-undisclosed/openai-gpt-image-2",
  "billing": "byok"
}

4. Retrieve outputs and clean up unused inputs

Poll GET /v1/generations/{id}/status?waitMs=25000 (or MCP job_get) until deliveryStatus is available, then download from the returned first-party /media/... capability URL. If a submission disconnects before returning a job ID, recover with GET /v1/generations/lookup?idempotencyKey=$IDEMPOTENCY_KEY.

When you no longer need the uploaded source image for future jobs, tombstone it with DELETE https://opengen.dev/v1/assets?key=<URL-encoded assetKey> (or MCP delete_asset). Accepted jobs keep their private input pins until finished.

Next steps

Supported Models

Live catalog inventory for image-edit (24 documented variants). Click any model to compare exact regional routes, privacy disclosures, and source-linked tariffs, or inspect its canonical schema directly via the single-call model endpoint.

ModelCreatorRoutesLowest published priceSingle-call API
bytedance/seedream-5.0-pro
ByteDance5 routes$0.03825 / imageGET /v1/models/bytedance/seedream-5.0-pro?operation=image-edit
openai/gpt-image-2
OpenAI5 routes≈$0.0059 / imageGET /v1/models/openai/gpt-image-2?operation=image-edit
bfl/flux-3-image
Black Forest Labs2 routes≈$0.0283 / imageGET /v1/models/bfl/flux-3-image?operation=image-edit
FLUX 3 KleinOpen weights
bfl/flux-3-klein
Black Forest Labs2 routes$0.008 / imageGET /v1/models/bfl/flux-3-klein?operation=image-edit
bytedance/seedream-5.0-flash
ByteDance2 routes$0.018 / imageGET /v1/models/bytedance/seedream-5.0-flash?operation=image-edit
minimax/h3-image-highspeed
MiniMax2 routes≈$0.0156 / imageGET /v1/models/minimax/h3-image-highspeed?operation=image-edit
fal/qwen-image-3
fal1 route$0.04 / imageGET /v1/models/fal/qwen-image-3?operation=image-edit
google/nano-banana-2-lite
Google1 route≈$0.0336 / imageGET /v1/models/google/nano-banana-2-lite?operation=image-edit
alibaba/qwen-image-3.0-pro
Alibaba7 routes$0.03438 / imageGET /v1/models/alibaba/qwen-image-3.0-pro?operation=image-edit
alibaba/qwen-image-2.1-pro
Alibaba6 routes$0.035333 / imageGET /v1/models/alibaba/qwen-image-2.1-pro?operation=image-edit
qwen/image-2.1-turbo
Qwen6 routes$0.014133 / imageGET /v1/models/qwen/image-2.1-turbo?operation=image-edit
google/nano-banana-2.1
Google5 routes$0.0336 / imageGET /v1/models/google/nano-banana-2.1?operation=image-edit
openai/gpt-image-2.5-flare
OpenAI5 routes≈$0.0056 / imageGET /v1/models/openai/gpt-image-2.5-flare?operation=image-edit
openai/gpt-image-2.5-sunburst
OpenAI5 routes≈$0.0056 / imageGET /v1/models/openai/gpt-image-2.5-sunburst?operation=image-edit
xai/grok-imagine-image-2.0
xAI5 routes$0.04 / imageGET /v1/models/xai/grok-imagine-image-2.0?operation=image-edit
bytedance/seedream-4.0
ByteDance2 routes$0.03 / imageGET /v1/models/bytedance/seedream-4.0?operation=image-edit
bytedance/seedream-4.5
ByteDance2 routes$0.04 / imageGET /v1/models/bytedance/seedream-4.5?operation=image-edit
bytedance/seedream-5.0-lite
ByteDance2 routes$0.035 / imageGET /v1/models/bytedance/seedream-5.0-lite?operation=image-edit
bytedance/seedream-5.5
ByteDance2 routes$0.02 / imageGET /v1/models/bytedance/seedream-5.5?operation=image-edit
google/nano-banana-2
Google2 routes≈$0.0448 / imageGET /v1/models/google/nano-banana-2?operation=image-edit
google/nano-banana-pro
Google2 routes≈$0.1344 / imageGET /v1/models/google/nano-banana-pro?operation=image-edit
minimax/h3-image
MiniMax2 routes≈$0.0078 / imageGET /v1/models/minimax/h3-image?operation=image-edit
openai/gpt-image-2.6-flare
OpenAI2 routes≈$0.0247 / imageGET /v1/models/openai/gpt-image-2.6-flare?operation=image-edit
openai/gpt-image-2.6-sunburst
OpenAI2 routes≈$0.0247 / imageGET /v1/models/openai/gpt-image-2.6-sunburst?operation=image-edit