Quick start
Or copy https://aiimageedits.com/api and give it to your AI agent to help you get started.
- Sign in, add image credits, and create an API key.
- Install Node.js 22 or later. Download both helpers into the same folder.
- Set your key, replace
input.jpgwith your image, and run the command below.
mkdir image-edit
cd image-edit
npm init -y
npm install sharp
curl -fSLO https://aiimageedits.com/helpers/edit.mjs
curl -fSLO https://aiimageedits.com/helpers/export.mjs
export AIIMAGEEDITS_API_KEY='aie_YOUR_SECRET_KEY'
node edit.mjs input.jpg "Replace the background with a sunny garden." result.pngOn Windows PowerShell, use curl.exe for the downloads and set the key with $env:AIIMAGEEDITS_API_KEY='aie_YOUR_SECRET_KEY'. Keep the real key in your environment or secret manager.
The helper selects an enabled processing size, corrects image orientation, prepares the upload, submits the prompt, waits for completion, and saves result.png at your original dimensions. Transparent input stays transparent. One successful edit currently uses one image credit; the quote is the authority for each request.
If the connection is interrupted, run the same command with the same output path. The helper keeps a small result.png.aie.json recovery file until the download succeeds. It contains your prompt and request metadata, so keep it private. It never contains your key or image. Do not delete it or change the output path to retry an uncertain request: that would start a new edit.
Integration guide
- Quote. Send the original, orientation-corrected dimensions, preferred export format, and an enabled native tier.
- Prepare. Resize to the plan’s content rectangle and pad to its canvas. Encode a single-frame PNG locally.
- Create. Send the prompt, prepared file’s SHA-256 and byte length, quoted price, and a unique idempotency key.
- Upload and submit. Upload the exact PNG bytes, then submit the edit.
- Poll and download. Follow
pollAfterMs. When ready, download the generated PNG and apply the ready response’sexportPlanlocally.
The API accepts one image per edit. It does not accept multipart source uploads, batches, or webhook callback URLs. Keep requests on your own server; the API key must never be shipped to a public webpage or mobile client.
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /api/v1/edits/quote | Get dimensions, export plan, and price |
| POST | /api/v1/edits | Reserve credits and create one edit |
| PUT | /api/v1/edits/{id}/upload | Upload the prepared PNG |
| POST | /api/v1/edits/{id}/submit | Queue the edit; returns 202 |
| GET | /api/v1/edits/{id} | Read status and the export plan |
| GET | /api/v1/edits/{id}/result | Download the generated PNG |
| DELETE | /api/v1/edits/{id} | Cancel before processing or delete stored files |
Image credits and API keys
API edits use the credit balance of the account that owns the key. Sign in to that same account on the website or in the mobile app to use the balance there. The daily free edit is available in the web editor and mobile app when capacity allows. See Pricing for credit packs and guest purchases on iPhone and iPad.
Creation reserves the quoted credits. A successful result settles the reservation once; failed or canceled edits release it. Downloads and local resizing do not use additional image credits. Deleting a successful result does not return its spent credit.
Create, label, and revoke keys in your account. Every key is restricted to that account’s edits. Revoking a key blocks future requests, so keep another authorized key available if you need to retrieve an existing result. Keys cannot access the website’s payment, account history, or security endpoints.
Raw HTTP example
1. Get a quote
Read GET /api/config for editingEnabled and enabled nativeTiers. This example uses a 2 MP tier for a 2048 × 864 original. Send the same geometry, format, tier, and optional background when creating the edit.
curl https://aiimageedits.com/api/v1/edits/quote \
-H "Authorization: Bearer $AIIMAGEEDITS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"width":2048,"height":864,"format":"image/png","nativeTier":2}'Save the quote response as plan.json. It includes exportPlan, chargeUnits, and chargeCredits. Use the exact returned chargeUnits as expectedChargeUnits; do not hardcode the price.
2. Prepare the image and create the edit
node export.mjs prepare input.jpg plan.json prepared.pngCalculate the prepared file’s SHA-256 and exact byte length. POST a JSON body like this to /api/v1/edits with your Bearer key and Content-Type: application/json. Replace all example values with the quote and prepared file’s values.
{
"width": 2048,
"height": 864,
"format": "image/png",
"nativeTier": 2,
"prompt": "Replace the background with a sunny garden.",
"uploadSha256": "SHA256_OF_PREPARED_PNG",
"uploadBytes": 123456,
"expectedChargeUnits": 20,
"idempotencyKey": "YOUR_UNIQUE_KEY_AT_LEAST_16_CHARACTERS"
}Creation returns 201 with an id, uploadUrl, exportPlan, and expiresAt. An identical retry returns 200 and the same edit. An idempotency key must be 16–80 letters, numbers, underscores, or hyphens.
3. Upload, submit, and download
# Use the id returned by creation. Keep all requests on aiimageedits.com.
curl -X PUT "https://aiimageedits.com/api/v1/edits/$EDIT_ID/upload" \
-H "Authorization: Bearer $AIIMAGEEDITS_API_KEY" \
-H "Content-Type: image/png" --data-binary @prepared.png
curl -X POST "https://aiimageedits.com/api/v1/edits/$EDIT_ID/submit" \
-H "Authorization: Bearer $AIIMAGEEDITS_API_KEY" \
-H "Content-Type: application/json" -d '{}'
curl "https://aiimageedits.com/api/v1/edits/$EDIT_ID" \
-H "Authorization: Bearer $AIIMAGEEDITS_API_KEY" -o status.json
# Only after state is ready:
curl -f "https://aiimageedits.com/api/v1/edits/$EDIT_ID/result" \
-H "Authorization: Bearer $AIIMAGEEDITS_API_KEY" -o generated.png
node export.mjs export generated.png status.json result.pngSubmitting returns 202 with an acknowledgment. Poll the status endpoint until ready. Use that response’s crop and resize plan to export the generated PNG at your requested format and dimensions. The generated canvas can be smaller than the upload canvas.
Result files omit embedded Content Credentials and descriptive metadata such as EXIF, GPS, and XMP. Color and transparency information needed to display the image is retained.
Retries and interrupted uploads
Persist the creation body and idempotency key before your first create request. Reuse both unchanged after a timeout or lost response. Never create a replacement request merely because a response did not arrive.
For an existing awaiting_upload edit, read uploaded. If false, retry the same PNG upload; if true, go straight to submission. Repeated uploads and submissions do not start another generation. Uploads must finish within ten minutes of creation.
Terminal edits cannot restart. Metadata and idempotency keys remain for seven days after the stored files are purged. Do not reuse keys after that period. The supplied helper refuses recovery files older than six days to avoid accidentally creating a replacement after retention.
A provider request with an ambiguous outcome is not automatically repeated. If an edit fails, its credit hold is released. Read the returned error before deciding whether to make a separate new request.
A failed edit may also include failureReason: moderation, invalid_image, provider_error, or unknown. Use this category to explain recovery to the user. Private provider messages and request IDs are not exposed. A new attempt uses a new key only after the previous edit has definitively failed.
Polling, downloads, and deletion
States are awaiting_upload, queued, processing, ready, failed, canceled, and expired. Respect pollAfterMs: three seconds initially, five seconds after 15 seconds, and ten seconds after 45 seconds.
Download availability lasts one hour from successful completion, reflected by the ready response’s expiresAt. Earlier responses show the pending deadline. Save the file in your own storage promptly; the service is not a permanent image library.
All image downloads require the owning account’s key. DELETE cancels an edit before processing starts or removes a finished result and its optional thumbnail. An edit already processing returns 409. Repeated deletion does not change credit settlement.
Image quality, formats, and local helpers
The website also accepts supported HEIC/HEIF stills through a local browser decoder. The command-line helpers accept JPEG, PNG and WebP. API uploads always contain a prepared PNG; HEIC is not an API upload or export format. Convert HEIC to an orientation-corrected JPEG or PNG before using these helpers.
Accept JPEG, PNG, or WebP originals in your integration, then prepare a PNG using the quote’s plan. Native processing uses automatic quality and enabled tiers through 7 MP. Larger originals can still be exported at their original dimensions. Resizing preserves those dimensions; it cannot recreate detail that is absent from the generated result.
Set background: "transparent" in both quote and creation when transparency should be preserved. Omit it when you want the edit to add a background. The website and quick-start helper preserve transparent inputs automatically. JPEG exports flatten transparency onto white.
The helpers resize on your machine using Lanczos-3. They correct EXIF orientation, apply the returned padding and crop, and export exact original dimensions. They do not call a paid resizing service.
- Complete Node.js API helper — requires the export helper beside it.
- Node.js / Sharp preparation and export helper
- Python / Pillow preparation and export helper
python -m pip install Pillow
python export.py prepare input.jpg plan.json prepared.png
python export.py export generated.png status.json result.pngn8n, Make, Zapier, and other automations
Use a server-side script or code step for image preparation, hashing, and final export. Then use authenticated HTTP steps for quote, creation, upload, submission, polling, and download. Store the edit ID and original idempotency key with the automation run so retries resume that edit.
Configure the upload step to send raw PNG bytes, not base64 JSON or multipart form data. Use a wait step between status requests. If the platform cannot process images or retain request state, run the Node helper on your own backend and call that backend from the automation.
Limits and errors
| Limit | Value |
|---|---|
| Original image geometry | 50 MP; 16,384 pixels per edge |
| Website source file | 25 MiB; single-frame JPEG, PNG, WebP, or supported HEIC/HEIF |
| Quick-start source file | 25 MiB; single-frame JPEG, PNG, or WebP |
| Prepared upload / generated PNG | 32 MiB each |
| Native processing | Up to 7,000,000 pixels; enabled tiers from configuration |
| Prompt | 1–4,000 characters |
| API requests | 6 creations and 120 control requests per minute per account, shared across its keys; additional network and capacity limits apply |
| Upload / result availability | 10 minutes to upload; 1 hour to download after completion |
Errors return JSON such as {"error":"insufficient_credits"}. Very complex generated images can exceed the result-size limit and fail without a user credit charge.
| HTTP status | Meaning | What to do |
|---|---|---|
| 400 / 413 / 415 | Invalid dimensions, prompt, image, or upload size | Validate the input and prepare it using the quoted plan. |
| 401 / 403 | Missing, invalid, or revoked API key | Check your server’s key. Never place it in browser code. |
| 402 | Insufficient credits | Add credits in your account, then retry the same request. |
| 404 | Unknown edit or different account | Check the edit ID and the account that owns the key. |
| 409 | Changed quote, conflicting retry, or invalid state | Read the error code and current status. Do not replace an uncertain request with a new key. |
| 410 | Edit or download expired | The files are no longer available. A new edit requires a new request. |
| 429 | Rate limit or temporary processing capacity | Wait for Retry-After, then retry the same request. |
| 503 | Service disabled, tier unavailable, or temporary failure | Check /api/config and retry later. Preserve the original request key. |
Use the OpenAPI specification for request and response schemas. For integration help, contact us with the edit ID and error code. Keep API keys, prompts, private images, and authenticated download URLs out of logs and support messages.