Edit an image

Edit, transform, or compose one or more input images, guided by a text prompt.

With the OpenAI SDK, upload the input image(s) as multipart/form-dataclient.images.edit(image=..., prompt=..., model=...), passing a list of files to compose several inputs. Over raw HTTP you can instead send a JSON body with an images array of image_url/file_id items (shown below); the OpenAI SDK does not send this JSON shape.

POST /images/edits

Edit one or more input images from a text prompt.

Request body

Content Type: application/json

EditImageBodyJsonParam

Content Type: multipart/form-data

CreateImageEditRequest

Response

HTTP 200 — OK

Content Type: application/json

ImagesResponse

Content Type: text/event-stream

ImageEditStreamEvent

python
import json
import os
import requests
response = requests.post(
"https://api.meta.ai/v1/images/edits",
headers={
"Authorization": f"Bearer {os.environ['MODEL_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "muse-image-1.0",
"prompt": "add a small red wool hat on the fox's head, keep the snowy forest background",
"images": [
{
"image_url": "data:image/webp;base64,UklGR...",
},
],
"n": 1,
},
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))

For reference images, multi-image composition, and worked examples, see the Image generation feature page.