Create images
Make images from a prompt with any image model.
Send a prompt and an image model, get the images back as base64. Pick a model and its fields from GET /images/models: each model takes its own set, and a field it doesn't list is refused before anything is reserved.
The call reserves every image it asks for at the dearest host's price. Set resolution and quality to reserve less. See Images for costs, references and streaming.
Authorization: Bearer binf_... or x-api-key.Request body
The fields most calls use. Every other field of the OpenAI format is passed on as sent.
modelstringRequiredAn image model id from GET /images/models, such as
openai/gpt-image-2.promptstringRequiredWhat to draw.
nintegerHow many images, 1 by default. Each model sets its own most, up to 10: see
parameters.nin GET /images/models. The call reserves every image.resolution"512" | "1K" | "2K" | "4K"The size tier, for models that list it. Left out, the call reserves the largest tier the model offers.
aspect_ratiostringSuch as
"1:1"or"16:9", from the values the model lists.qualitystringlow,medium,highand up, for models that list it. Lower quality reserves and costs less. Left out, the call reserves the highest the model offers.sizestringA tier such as
"2K", or pixels such as"2048x2048".output_formatstringpng,jpeg,webporsvg, where the model offers a choice.backgroundstringtransparentoropaque, for models that list it.input_referencesobject[]Images to edit or follow, as
{ "type": "image_url", "image_url": { "url": "https://..." } }, up to the model's most. Links are best: a request body is at most 4 MB.streambooleanSend partial images as they form, then the finished one, as server-sent events. One image a call, on models with
streaming: true. Others answer the whole image as usual.seedintegerThe same seed and prompt give the same image, on models that list it.
response_format"b64_json" | "url"urlstores the images and answers with a link to each, good for 7 days, instead of base64: a small answer however large the images. Not withstream.
Response
createdintegerWhen it was made, in Unix seconds.
dataobject[]The images, in order.
b64_jsonstringThe image, as base64. Left out with
response_format: "url".urlstringThe image's link, with
response_format: "url".expires_atstringWhen the link stops working, with
url.media_typestringIts type, such as
image/png.
usageobjectTokens and
cost: what this call is charged, in dollars. Exactly what leaves the balance.
Response headers
x-binference-call-idstringThis call's id on your Calls page. Quote it when you contact us.
x-generation-idstringThe model provider's id for the answer.
retry-afterintegerOn a 429 or 503: whole seconds to wait before sending again.
retry-after-msintegerThe same wait in milliseconds. The OpenAI and Anthropic SDKs read it.
curl https://binference.io/api/v1/images \ -H "Authorization: Bearer $BINF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-image-2", "prompt": "A small red lighthouse on a rock at dusk, flat illustration", "quality": "medium", "aspect_ratio": "1:1" }'{ "created": 1790809771, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAAB...", "media_type": "image/png" } ], "usage": { "prompt_tokens": 15, "completion_tokens": 1584, "total_tokens": 1599, "cost": 0.057114 }}data: {"type":"image_generation.partial_image","partial_image_index":0,"b64_json":"iVBORw0KGgo..."}data: {"type":"image_generation.completed","b64_json":"iVBORw0KGgo...","media_type":"image/png","created":1790809864,"usage":{"prompt_tokens":15,"completion_tokens":1584,"total_tokens":1599,"cost":0.057114}}data: [DONE]