Skip to main content
POST
POST /v1/images/edits The image-to-image endpoint uses a multipart/form-data request body. Upload one or more reference images and submit prompt and parameter fields as form fields.
Use https://bettertoken.ai/v1 as the Base URL. Pass your BetterToken API Key through Authorization: Bearer YOUR_API_KEY.
You can fill in form fields and upload reference images in the Playground on the right side of the page, then send the request directly to https://bettertoken.ai/v1/images/edits.
Do not use a regular JSON body for image-to-image requests. Submit text fields and file fields with multipart/form-data.
Send these fields explicitly in every request:
Use image for a single reference image. Use repeated image[] fields for multiple reference images.

Single reference image

Multiple reference images

Edit a selected area with a mask

Add the optional mask file field when you want to guide editing to a selected area. The current BetterToken endpoint reads one mask file. Do not send repeated mask[] fields.
  • The original image and mask must use the same file format and pixel dimensions. Each file must be smaller than 50 MB. For maximum compatibility, use PNG with an Alpha channel for both files.
  • The mask must contain an Alpha channel. Fully transparent pixels (Alpha 0) mark the area the model may redraw. Fully opaque pixels (Alpha 255) guide the model to preserve that area.
  • A regular RGB black-and-white image is not a valid mask unless it actually contains an Alpha channel.
  • If you send multiple image[] fields, the mask applies to the first input image.
  • The mask guides the model. It does not guarantee that pixels outside the transparent area remain absolutely identical.

Masked edit with Python

Open both files in one with statement so Python closes them after the request:

Check the files before upload

This minimal Pillow check verifies the required format, dimensions, and Alpha channel. For a typical local mask, it also warns when the Alpha channel does not include both fully transparent and fully opaque areas:

Python example

size represents the expected aspect ratio and size tier. The actual returned pixels may be mapped or adjusted by the server. Use the decoded image dimensions instead of forcibly cropping the output to the requested value.

Save the image

A successful response follows the OpenAI-compatible image response shape:
Read data[0].b64_json and save it as base64 image content. Always set output_format: "png" so you can save the decoded image as .png.

Response flow

This endpoint is synchronous. After sending POST /images/edits, keep the current HTTP request open until the server responds. When generation succeeds, the image content is returned in data[0].b64_json. The endpoint does not return a task_id, and there is no separate status query or result download endpoint.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

multipart/form-data
model
enum<string>
default:gpt-image-2
required

Use the GPT Image 2 model ID.

Available options:
gpt-image-2
Example:

"gpt-image-2"

prompt
string
required

Instructions for editing the image or generating from reference images.

Example:

"Use this reference image to create a more polished square product hero image while preserving the main style."

image
file

The reference image field for a single input image.

image[]
file[]

Repeat this field for each input when sending multiple reference images.

mask
file

An optional single mask file. The mask and original image must have the same format and dimensions, each file must be smaller than 50 MB, and the mask must contain an Alpha channel. For maximum compatibility, use PNG with an Alpha channel for both files. With multiple image[] inputs, the mask applies to the first image.

n
default:1

Use 1. Send separate requests when you need multiple output images.

Example:

"1"

size
enum<string>
default:1024x1024

The requested image size or aspect-ratio tier. The server may map or adjust the final pixel dimensions, so inspect the decoded image for its actual size.

Available options:
auto,
1024x1024,
1536x1024,
1024x1536,
1536x1152,
1152x1536,
2048x2048,
2048x1152,
3840x2160,
2160x3840
Example:

"1024x1024"

response_format
enum<string>
default:b64_json

Use b64_json.

Available options:
b64_json
Example:

"b64_json"

output_format
enum<string>
default:png

Use png. Do not rely on jpeg or webp being returned directly in the selected format.

Available options:
png
Example:

"png"

Response

Image editing result.

created
integer
Example:

1710000000

data
object[]