Image generation

$0.030 per call · USDC via x402 · POST /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.030 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 & compute · Tags: 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 AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.

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?.(false); // keep your own spending ceiling in code
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.100 · POST /api/image-gen-hd

Generate a higher-quality image from a text prompt using GPT Image 2 (medium quality, 1024x1024). No API key needed; pay…

Image generation (Premium)

$0.150 · 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,…

LLM inference

$0.010 · POST /api/llm

LLM inference proxy - send an OpenAI-format chat/completions request and get a response from GPT-4o-mini. Supports visio…

LLM inference (Premium)

$0.500 · POST /api/llm-premium

LLM inference proxy (Premium tier) - o3 or o3-mini reasoning models. Supports vision (up to 2 image URLs) and structured…

LLM inference (Pro)

$0.100 · POST /api/llm-pro

LLM inference proxy (Pro tier) - GPT-4o or GPT-4.1. Supports vision (up to 2 image URLs) and structured output (response…