API Reference
One API for AI image and video generation. Every model — realism, anime, video — is served by the same endpoints; the media kind and the price come from the model you pick. Two ways to pay:
X-PAYMENT header.
Base URL: https://imference.com · Try it live in the
Credits or
x402 playground.
Quickstart — Credits
- Buy credits — your API key is created with the first purchase.
- POST
/generatewith your model + prompt (Bearer auth). - Poll GET
/status?request_id=…until it returns your media URL.
curl -X POST 'https://imference.com/generate' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"model": "illustrious-hassuka-xl", "prompt": "A cat astronaut floating in space"}'
# → {"request_id": "abc-123", "kind": "image"}
curl 'https://imference.com/status?request_id=abc-123' \
-H 'Authorization: Bearer YOUR_API_KEY'
# 404 while running · 422 if failed · 200 with the media URL when done
Quickstart — x402
No account, no key: your wallet pays per call in USDC on Base. The first request answers
402 Payment Required with the price; your x402 client signs an
EIP-3009 authorization and retries automatically. Use an
x402 client library
or try the playground.
import { wrapFetchWithPayment } from "x402-fetch";
const fetchWithPay = wrapFetchWithPayment(fetch, walletClient); // your viem wallet
const res = await fetchWithPay("https://imference.com/ondemand/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: "illustrious-hassuka-xl", prompt: "A cat astronaut" }),
});
const { request_id } = await res.json();
// then poll GET /ondemand/status?request_id=… (no auth needed)
Authentication & payment
Credits rail
Every request carries Authorization: Bearer YOUR_API_KEY. The per-model
cost in credits (im_cost) is debited at enqueue.
x402 rail
No auth header. Payment is proven by the signed X-PAYMENT header
(EIP-3009 USDC authorization). Price is dynamic per model: im_cost credits × $0.001.
/generate
/ondemand/generate
Generate an image or a video — one endpoint for every model. The media kind and the price come from
the model; the response echoes both. Returns a request_id for status polling.
curl -X POST 'https://imference.com/generate' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "illustrious-hassuka-xl",
"prompt": "A cat astronaut floating in space",
"width": 1024, "height": 1024,
"steps": 28, "guidance_scale": 6
}'
# A bare request returns 402 with the payment requirements (price in USDC).
# Use an x402 client to sign the X-PAYMENT header automatically:
curl -X POST 'https://imference.com/ondemand/generate' \
-H 'Content-Type: application/json' \
-d '{
"model": "illustrious-hassuka-xl",
"prompt": "A cat astronaut floating in space"
}'
Request body
model(required) — model code from GET /api/modelsprompt(required) — text descriptionnegative_prompt,width,height,steps,guidance_scale,seed(optional) — unset fields fall back to the model's catalog defaultsimg_url(optional) — source image URL: image-to-image for image models, image-to-video for video modelsnum_frames,fps(optional, video models) — default to the model's catalog values
Response
{"request_id": "abc-123", "kind": "image"}
kind is "image" or "video" — video generations take minutes; size your polling accordingly.
Video generation
Same endpoint — pick a video model and it generates a video. No img_url → text-to-video;
with img_url → image-to-video. The price adjusts to the model automatically.
curl -X POST 'https://imference.com/generate' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "wan22-video",
"prompt": "A fox running through a snowy forest",
"num_frames": 81, "fps": 20
}'
# → {"request_id": "…", "kind": "video"} — poll /status; expect minutes, not seconds
/status?request_id=…
/ondemand/status?request_id=…
Check a generation. The polling contract is explicit:
| HTTP | Meaning | What to do |
|---|---|---|
| 404 | Still running | Keep polling (1s is fine; videos run minutes) |
| 422 | Generation failed | Stop polling — error carries the reason |
| 200 | Done | Download data.URL |
curl 'https://imference.com/status?request_id=YOUR_REQUEST_ID' \
-H 'Authorization: Bearer YOUR_API_KEY'
curl 'https://imference.com/ondemand/status?request_id=YOUR_REQUEST_ID'
# no auth needed — the request_id is the capability
/media/all
Credits rail only
All media (images and videos) generated with your API key, newest first. Each row carries a Kind field.
curl 'https://imference.com/media/all' \
-H 'Authorization: Bearer YOUR_API_KEY'
/credits/balance
Credits rail only
Your remaining credit balance.
curl 'https://imference.com/credits/balance' \
-H 'Authorization: Bearer YOUR_API_KEY'
# → {"credits": 1250}
/ondemand/credits/add
x402 payment
Prepay API-key credits with one on-chain USDC payment — the x402 price is exactly
credits × $0.001. Saves the per-call network fee when you
generate a lot. Min 100, max 1,000,000 credits per call. An empty
api_key creates a fresh key and returns it. Or use the
pricing page UI.
const res = await fetchWithPay("https://imference.com/ondemand/credits/add", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ credits: 5000, api_key: "" }), // "" → new key
});
// → {"api_key": "…", "credits_added": 5000}
Models & formats
Public, no auth. GET /api/models lists every model with its defaults
(steps, CFG, prompts) and its cost — im_cost in credits (1 credit = $0.001; the x402 price is
the same amount in USDC). GET /api/formats lists each model's supported
resolutions and ratios, so you never hardcode sizes.
curl 'https://imference.com/api/models'
curl 'https://imference.com/api/formats'
Errors
Standard HTTP codes; error bodies are {"error": "…"}.
| Status | Meaning | Common cause |
|---|---|---|
| 400 | Bad request | Missing/invalid fields, insufficient credits |
| 401 | Unauthorized | Missing or unknown API key (credits rail) |
| 402 | Payment required | x402: no valid payment — the body lists the requirements to sign |
| 404 | Not found | Unknown model/endpoint/request_id — or generation still running (keep polling) |
| 422 | Generation failed | Worker error — stop polling, the reason is in error |
| 429 | Too many requests | Rate limit exceeded (50 req/min) |
| 500 | Server error | Retry, or contact support |
Rate limits & terms
50 requests per minute per API key (credits) or wallet address (x402). Exceeding it returns 429.
See the Terms of Service.