MuseSpark
MuseSpark
Models & toolsImage models

GPT Image 2 API guide

GPT Image 2 API: Generate images from text or edit image references with GPT Image 2. This item includes quality, background, and mask controls; check the dependencies before combining them.

Model overview

Generate images from text or edit image references with GPT Image 2. This item includes quality, background, and mask controls; check the dependencies before combining them.

API integration

DocumentationValue
API invocation identifiergpt-image-2
IntegrationAsync task API

Use this invocation identifier in API requests. Check your authorized model catalog for access. Follow the Quickstart for your first complete call.

Request parameters

Select a mode to highlight its required inputs. Mode selection does not change the API field names.

Studio presets describe the form setup, not guaranteed server defaults. Send preset values explicitly to reproduce them.

image_urlsarray<string>Non-nullConditional

Required for Image Editing and References.

Additional requirements depend on other values. See model rules.

Sets images for this item.

Item count: maximum 15.

promptstringNon-nullRequired

Sets prompt for this item.

Length: minimum 1.

resolutionstringNon-nullOptional

Sets resolution for this item.

Allowed values: "1k", "2k", "4k".

Studio preset: "1k".

aspect_ratiostringNon-nullOptional

Choose one of the listed aspect ratios or auto. The selected resolution determines the output pixel size.

Allowed values (16)

Allowed values: "auto", "1:1", "3:2", "2:3", "4:3", "3:4", "5:4", "4:5", "16:9", "9:16", "2:1", "1:2", "3:1", "1:3", "21:9", "9:21".

Studio preset: "4:3".

batch_sizeintegerNon-nullOptional

Standard quantity control field. The allowed range for this item is 1-15.

Repeats MuseSpark execution within one logical task. This is separate from a model-native output count.

Value: minimum 1; maximum 15.

Studio preset: 1.

nsfw_checkbooleanNon-nullOptional

Sets nsfw check for this item.

qualitystringNon-nullRequired

Choose output quality. Medium is selected by default. Actual text and image Tokens determine the final charge; Auto has no fixed estimate.

Allowed values: "auto", "low", "medium", "high".

Studio preset: "medium".

mask_urlstringNon-nullOptional

Use a PNG mask with an alpha channel for local edits. Its dimensions must match the first reference image.

Length: minimum 1.

Media types: image/png.

backgroundstringNon-nullOptional

Choose an automatic, opaque, or transparent background.

Allowed values: "auto", "opaque", "transparent".

No parameters match. Clear the search or reset the filters.

Model rules

Input modes

Select a mode by supplying its required public inputs. The mode identifier describes a documentation/form choice; do not send input_mode as a model parameter.

ModeRequired inputs
Text to ImageNo reference media required
Image Editing and Referencesimage_urls
  • When the input mode is Text to Image, omit image_urls.
  • When the input mode is Image Editing and References, provide image_urls; keep image_urls, when supplied, at least 1 items.
  • When mask_url is provided, provide image_urls; keep image_urls, when supplied, at least 1 items.

Dependencies

  • A resolution tier and a ratio jointly determine output dimensions. A tier name does not guarantee a fixed width for every ratio.
  • For edits, preserve reference order and explain which features must stay unchanged. Do not assume image-generation and image-editing inputs are interchangeable.

batch_size controls repeated MuseSpark executions. Output grouping, sequential image generation, and video shot count are separate concepts.

Request examples

Replace example media URLs and YOUR_... input identifiers with your own valid resources. Examples are checked against the exported item schema; media access and paid execution are separate runtime checks.

Set MUSESPARK_API_KEY and a stable MUSESPARK_REQUEST_ID before submitting. Preserve the request ID for retries of the same request and use a new ID for new work. Python examples use requests; JavaScript examples use Node.js 20 or later. The standalone Quickstart includes task polling and recovery.

Text to Image

curl --fail-with-body 'https://api.musespark.ai/api/v1/openapi/task' \
  -H "Authorization: Bearer $MUSESPARK_API_KEY" \
  -H "X-Idempotency-Key: $MUSESPARK_REQUEST_ID" \
  -H 'Content-Type: application/json' \
  -d '{
  "item_key": "gpt-image-2",
  "parameters": {
    "quality": "medium",
    "batch_size": 1,
    "resolution": "1k",
    "aspect_ratio": "4:3",
    "prompt": "A paper city under soft morning light"
  }
}'

Parameters used: quality · batch_size · resolution · aspect_ratio · prompt.

Image Editing and References

curl --fail-with-body 'https://api.musespark.ai/api/v1/openapi/task' \
  -H "Authorization: Bearer $MUSESPARK_API_KEY" \
  -H "X-Idempotency-Key: $MUSESPARK_REQUEST_ID" \
  -H 'Content-Type: application/json' \
  -d '{
  "item_key": "gpt-image-2",
  "parameters": {
    "quality": "medium",
    "batch_size": 1,
    "resolution": "1k",
    "aspect_ratio": "4:3",
    "image_urls": [
      "https://example.com/input-1.png"
    ],
    "prompt": "A paper city under soft morning light"
  }
}'

Parameters used: quality · batch_size · resolution · aspect_ratio · image_urls · prompt.

Output

Creation returns a task ID inside data. Poll that task until completion, then save data.result.output_urls and any data.result.batch_results. See the task lifecycle for terminal states, result retention, and errors.

Troubleshooting

For rejected inputs, check the field type, accepted values, and conditional requirements in Request parameters and Model rules. Correct the affected fields before submitting again.

If creation times out, preserve the request identity and any known task ID. Follow Errors, timeouts and retries before submitting again.

The public input snapshot was exported on 2026-11-09. Current prices and availability are listed in the model center.