Image edit (OpenAI-compatible)
POST /v1/images/editsEdit an image with a prompt over x402 - OpenAI images.edit wire (reference images and a prompt in, inline base64 out) at $0.02 per picture. Send POST /v1/images/edits with the required fields prompt and image and pay $0.02 per call over x402 with USDC on an EVM chain or MPP. It returns a JSON object with created, model, data and usage.
Send one to 4 PNG or JPEG reference images (256 px a side or more, up to 6 MB each) as base64 or data: URLs in JSON, or one as a multipart "image" file; the output is one JPEG of about one megapixel that follows the first reference's aspect ratio. Served by FLUX 3 Image Klein in about 10 seconds. No mask: describe the change in the prompt. n locked to 1; a failed generation is not charged on x402. Point any OpenAI SDK's images.edit() at base_url https://agent402.tools/v1.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
prompt | string | yes | What to change (up to 4,000 chars) Also accepted as text, input, description, q, query. |
image | any | yes | One to 4 reference images, each base64 or a data: URL (PNG or JPEG, at least 256x256, up to 6 MB each). Image URLs are not fetched. Also accepted as file, photo. |
Example request
curl -i -X POST https://agent402.tools/v1/images/edits \
-H "Content-Type: application/json" \
-d '{"prompt":"Turn the red square into a ripe red apple with a soft shadow","image":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAC+0lEQVR42u3TwQkAMAgEQcux/3rsJfnl60eQwAxXwcHGAVaFC0CEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhYyrT3kSICEWICEUoQkQoQkQoQhEiQhEiQhGKEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQEYoQEYpQhIhQhIhQhCJEhCJEhCIUISIUISIUoQgRoQgRoQhFiAhFiAhFKEJEKEJEKEIRIkIRIkIRihARihARilCEiFCEiFCEIkSEIkSEIhQhIhQhIhQhiFCEiFCEIEIRIkIRgghFiAhFCCIUISIUIYhQhIhQhCBCESJCESJC7YkQEYoQEZoIEaEIEaGJEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQfiZCECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQaFwp5rW6Afb8QQAAAABJRU5ErkJggg=="}'
Without payment this returns HTTP 402 Payment Required with the exact price for v1-images-edit; any x402 v2 or MPP client pays it and retries.
Example response
{
"created": 1750000000,
"model": "black-forest-labs/flux-3-image-klein",
"data": [
{
"b64_json": "/9j/4AAQSkZJRgABAQAAAQABAAD…",
"media_type": "image/jpeg"
}
],
"usage": {
"prompt_tokens": 11,
"completion_tokens": 4096,
"total_tokens": 4107
}
}
| Field | Type | Always present | In the example |
|---|---|---|---|
created | number | yes | 1750000000 |
model | string | yes | black-forest-labs/flux-3-image-klein |
data | array of objects | yes | 1 item in the example |
usage | object | yes | 3 fields: prompt_tokens, completion_tokens, total_tokens |
From an MCP client
catalog.call {
"slug": "v1-images-edit",
"params": {
"prompt": "Turn the red square into a ripe red apple with a soft shadow",
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAC+0lEQVR42u3TwQkAMAgEQcux/3rsJfnl60eQwAxXwcHGAVaFC0CEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhYyrT3kSICEWICEUoQkQoQkQoQhEiQhEiQhGKEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQEYoQEYpQhIhQhIhQhCJEhCJEhCIUISIUISIUoQgRoQgRoQhFiAhFiAhFKEJEKEJEKEIRIkIRIkIRihARihARilCEiFCEiFCEIkSEIkSEIhQhIhQhIhQhiFCEiFCEIEIRIkIRgghFiAhFCCIUISIUIYhQhIhQhCBCESJCESJC7YkQEYoQEZoIEaEIEaGJEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQfiZCECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQaFwp5rW6Afb8QQAAAABJRU5ErkJggg=="
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for v1-images-edit; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y agent402-mcp.
Errors and behavior
promptandimageare required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce a different result.
- Long-running: payment settles after the work finishes, so x402 is offered on EVM chains only and MPP on Base or Celo; Tempo is not offered.
- A
GETorHEADto /v1/images/edits returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB and a streamed response are not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.02" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/images/edits", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"prompt": "Turn the red square into a ripe red apple with a soft shadow",
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAC+0lEQVR42u3TwQkAMAgEQcux/3rsJfnl60eQwAxXwcHGAVaFC0CEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCQIQgQkCEIEJAhCBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQISBCECEgQhAhIEIQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhYyrT3kSICEWICEUoQkQoQkQoQhEiQhEiQhGKEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQEYoQEYpQhIhQhIhQhCJEhCJEhCIUISIUISIUoQgRoQgRoQhFiAhFiAhFKEJEKEJEKEIRIkIRIkIRihARihARilCEiFCEiFCEIkSEIkSEIhQhIhQhIhQhiFCEiFCEIEIRIkIRgghFiAhFCCIUISIUIYhQhIhQhCBCESJCESJC7YkQEYoQEZoIEaEIEaGJEBGKEBGKUISIUISIUIQiRIQiRIQiFCEiFCEiFKEIEaEIEaEIRYgIRYgIRShCRChCRChCESJCESJCEYoQfiZCECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQECGIEBAhiBAQIYgQaFwp5rW6Afb8QQAAAABJRU5ErkJggg=="
}),
});
Related tools
Fast image generation (OpenAI-compatible, budget)
POST /v1/images/fastBudget text-to-image over x402 - OpenAI images wire (prompt in, inline base64 out) at $0.02 per picture, a quarter.
Pro image generation (OpenAI-compatible)
POST /v1/images/proHigher-fidelity text-to-image over x402 - OpenAI images wire (prompt in, inline base64 out) at $0.05 per picture.
Image generation (OpenAI-compatible)
POST /v1/images/generationsOpenAI-compatible image generation over x402 - point any OpenAI SDK's images.generate() at base_url.
Video generation (4-second clip)
POST /v1/videos/generationsText-to-video over x402 - one silent 4-second 720p clip (MP4, inline base64) for a flat $0.20, served by Veo 3.1 Lite.
Text-to-speech (OpenAI-compatible)
POST /v1/audio/speechOpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url.
Chat completions (OpenAI-compatible)
POST /v1/chat/completionsOpenAI-compatible chat completions, base tier: point any OpenAI SDK at base_url https://agent402.tools/v1 and pay per.