Image generation

$0.03 per callUSDC via x402POST /api/image-gen

Generate an image from a text prompt using GPT Image 2 (low quality, 1024x1024). Send POST /api/image-gen with the required field prompt and pay $0.03 per call over x402 or MPP (there is no free tier). It returns a JSON object with model, provider, quality, size, image and 1 more.

No API key needed; pay per call via x402. Returns base64 PNG. Prompt capped at 1000 chars. A render takes 10 to 30 s; use a client timeout of at least 60 s.

Category: AI & computeTags: image ai generation openai text-to-image gpt-image-2

Try in playground →

Parameters

NameTypeRequiredDescription
promptstringyesText description of the desired image (max 1000 chars) Also accepted as text, input, description, q, query.

Example request

curl -i -X POST https://agent402.tools/api/image-gen \
  -H "Content-Type: application/json" \
  -d '{"prompt":"A single red apple on a white background"}'

Without payment this returns HTTP 402 Payment Required with the exact price for image-gen; any x402 v2 or MPP client pays it and retries.

Example response

{
  "model": "gpt-image-2",
  "provider": "openai",
  "quality": "low",
  "size": "1024x1024",
  "image": "<base64-encoded PNG>",
  "revised_prompt": "A single red apple on a white background"
}
FieldTypeAlways presentIn the example
modelstringyesgpt-image-2
providerstringyesopenai
qualitystringyeslow
sizestringyes1024x1024
imagestringyes<base64-encoded PNG>
revised_promptstringyesA single red apple on a white background

From an MCP client

catalog.call {
  "slug": "image-gen",
  "params": {
    "prompt": "A single red apple on a white background"
  }
}

The hosted connector at https://agent402.tools/mcp needs a payment for image-gen; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y [email protected].

Errors and behavior

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.03" }); // 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/api/image-gen", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "prompt": "A single red apple on a white background"
  }),
});

Related tools

Image generation (HD)

$0.10 · POST /api/image-gen-hd

Generate a higher-quality image from a text prompt using GPT Image 2 (medium quality, 1024x1024).

Image generation (Premium)

$0.15 · POST /api/image-gen-premium

Generate a larger image from a text prompt using GPT Image 2 (medium quality): 1536x1024 landscape by default, 1024x1536.

Decisions (OpenAI wire)

$0.001 · POST /v1/decisions

OpenAI's Decisions API on its own wire: point an OpenAI SDK's base URL here and client.decisions.create works unchanged.

Locate in image (preview)

$0.002 · POST /v1/judge/locate

Find up to 4 things in one image: each comes back with whether it is there (a probability) and its box, as edges from 0.

Judge images (preview)

$0.003 · POST /v1/judge/vision

Ask typed questions about up to 4 images (PNG or JPEG) and get answers your code can branch on: noul (yes/no.

LLM inference

$0.01 · POST /api/llm

LLM inference proxy - send an OpenAI-format chat/completions request and get a response from GPT-4o-mini (or gpt-6-luna.