Edit an image
const url = 'https://ai.work.optidata.cloud/api/ai/image/edit';const form = new FormData();form.append('image', 'file');form.append('prompt', 'Replace the background with a light blue sky.');form.append('mask', 'file');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://ai.work.optidata.cloud/api/ai/image/edit \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: multipart/form-data' \ --form image=@file \ --form 'prompt=Replace the background with a light blue sky.' \ --form mask=@fileChanges an existing image as described in prompt and returns the
result as base64 PNG. Optionally send a mask: a PNG of the same size
whose fully transparent pixels mark the area to change.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
The image to edit. PNG, up to 4 MB.
The change to make.
Optional PNG mask, same size as image, up to 4 MB.
Responses
Section titled “ Responses ”The image, base64-encoded.
object
Id of this request.
Always null; the image is returned inline.
The PNG image, base64-encoded.
Examples
{ "id": "a30508a1-7c2e-4b1d-9f3a-0e6d5c4b3a21", "url": null, "image_base64": "iVBORw0KGgoAAAANSUhEUgAA…"}No authentication key was sent.
Authentication failures use an error key rather than message.
object
Examples
No bearer token sent
{ "error": "JWT passport exception: Missing bearer token in request"}The authentication key is expired or not recognised. Get a fresh one and retry.
Authentication failures use an error key rather than message.
object
Examples
{ "error": "JWT passport expired: Passport expired"}A required field is missing, or a file is not a PNG.
object
The first validation message.
Validation messages keyed by field name.
object
Examples
{ "message": "The image field is required. (and 1 more error)", "errors": { "image": [ "The image field is required." ], "prompt": [ "The prompt field is required." ] }}{ "message": "The image must be a file of type: png.", "errors": { "image": [ "The image must be a file of type: png." ] }}