Image generation (Premium)
POST /api/image-gen-premiumGenerate a larger image from a text prompt using GPT Image 2 (medium quality): 1536x1024 landscape by default, 1024x1536 portrait or 1024x1024 square via orientation. Send POST /api/image-gen-premium with the required field prompt and pay $0.150 per call over x402 with USDC on an EVM chain. 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 4000 chars. A render takes 25 to 50 s; use a client timeout of at least 75 s. Takes up to 75 seconds to answer: keep the connection open for at least 105 seconds, because a client that disconnects first loses the answer, or send the paid call with "Prefer: respond-async" to get a job link at once and collect the answer from it (payment still settles only on a delivered result).
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
prompt | string | yes | Text description of the desired image (max 4000 chars) Also accepted as text, input, description, q, query. |
orientation | string (one of: landscape, portrait, square) | no | landscape 1536x1024 (default), portrait 1024x1536, square 1024x1024 |
Example request
curl -i -X POST https://agent402.tools/api/image-gen-premium \
-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-premium; any x402 v2 or MPP client pays it and retries.
Example response
{
"model": "gpt-image-2",
"provider": "openai",
"quality": "medium",
"size": "1536x1024",
"image": "<base64-encoded PNG>",
"revised_prompt": "A single red apple on a white background"
}
| Field | Type | Always present | In the example |
|---|---|---|---|
model | string | yes | gpt-image-2 |
provider | string | yes | openai |
quality | string | yes | medium |
size | string | yes | 1536x1024 |
image | string | yes | <base64-encoded PNG> |
revised_prompt | string | yes | A single red apple on a white background |
From an MCP client
catalog.call {
"slug": "image-gen-premium",
"params": {
"prompt": "A single red apple on a white background"
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for image-gen-premium; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
promptis 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 different wording.
- Long-running: payment settles after the work finishes, so only EVM exact payments are offered.
- Takes up to 75 seconds. Keep the connection open that long, or send the paid call with
Prefer: respond-asyncto get202and a job link at once, then collect the answer fromGET /api/jobs/{id}; payment still settles only when the answer is ready. - A
GETorHEADto /api/image-gen-premium 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 is 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?.(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-premium", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"prompt": "A single red apple on a white background"
}),
});
Related tools
Image generation
POST /api/image-genGenerate an image from a text prompt using GPT Image 2 (low quality, 1024x1024). No API key needed; pay per call via x40…
Image generation (HD)
POST /api/image-gen-hdGenerate a higher-quality image from a text prompt using GPT Image 2 (medium quality, 1024x1024). No API key needed; pay…
Decisions (OpenAI wire)
POST /v1/decisionsOpenAI's Decisions API on its own wire: point an OpenAI SDK's base URL here and client.decisions.create works unchanged,…
LLM inference
POST /api/llmLLM inference proxy - send an OpenAI-format chat/completions request and get a response from GPT-4o-mini. Supports visio…
LLM inference (Premium)
POST /api/llm-premiumLLM inference proxy (Premium tier) - o3 or o3-mini reasoning models. Supports vision (up to 2 image URLs) and structured…
LLM inference (Pro)
POST /api/llm-proLLM inference proxy (Pro tier) - GPT-4o or GPT-4.1. Supports vision (up to 2 image URLs) and structured output (response…