Create images

Make images from a prompt with any image model.

POST

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.

Send your key as 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.

  • modelstringRequired

    An image model id from GET /images/models, such as openai/gpt-image-2.

  • promptstringRequired

    What to draw.

  • ninteger

    How many images, 1 by default. Each model sets its own most, up to 10: see parameters.n in 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_ratiostring

    Such as "1:1" or "16:9", from the values the model lists.

  • qualitystring

    low, medium, high and up, for models that list it. Lower quality reserves and costs less. Left out, the call reserves the highest the model offers.

  • sizestring

    A tier such as "2K", or pixels such as "2048x2048".

  • output_formatstring

    png, jpeg, webp or svg, where the model offers a choice.

  • backgroundstring

    transparent or opaque, 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.

  • streamboolean

    Send 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.

  • seedinteger

    The same seed and prompt give the same image, on models that list it.

  • response_format"b64_json" | "url"

    url stores the images and answers with a link to each, good for 7 days, instead of base64: a small answer however large the images. Not with stream.

Response

  • createdinteger

    When it was made, in Unix seconds.

  • dataobject[]

    The images, in order.

    • b64_jsonstring

      The image, as base64. Left out with response_format: "url".

    • urlstring

      The image's link, with response_format: "url".

    • expires_atstring

      When the link stops working, with url.

    • media_typestring

      Its type, such as image/png.

  • usageobject

    Tokens and cost: what this call is charged, in dollars. Exactly what leaves the balance.

Response headers

  • x-binference-call-idstring

    This call's id on your Calls page. Quote it when you contact us.

  • x-generation-idstring

    The model provider's id for the answer.

  • retry-afterinteger

    On a 429 or 503: whole seconds to wait before sending again.

  • retry-after-msinteger

    The same wait in milliseconds. The OpenAI and Anthropic SDKs read it.

Request
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"  }'
Response
{  "created": 1790809771,  "data": [    {      "b64_json": "iVBORw0KGgoAAAANSUhEUgAAB...",      "media_type": "image/png"    }  ],  "usage": {    "prompt_tokens": 15,    "completion_tokens": 1584,    "total_tokens": 1599,    "cost": 0.057114  }}
Streamed, with stream: true
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]