Tokenify
Get API keyConsole
Menu

Image generation

The OpenAI Images shape, billed per image rather than per token. Base64 or a link, one image or four.

View as markdown
Three request shapes reach the same models. This page is the OpenAI Images one, which the rest of this API speaks; the model maker’s own format and google-genai’s generateContent are the other two, and layer decomposition works through the first two. Same models, same prices, same limits — pick whichever your code already speaks. Tokenify is not affiliated with OpenAI or Google; what carries over from their SDKs is the request shape, not the models.

The call

POST https://api.tokenify.dev/v1/images/generations, with the same body the OpenAI Images API takes. The OpenAI SDK reaches it through client.images.generate with nothing changed but the base URL.

import base64
import os

from openai import OpenAI

client = OpenAI(
base_url="https://api.tokenify.dev/v1",
api_key=os.environ["TOKENIFY_API_KEY"],
)

res = client.images.generate(
model="bytedance/seedream-5.0-pro",
prompt="A still life of three pears, soft window light",
size="1024x1024",
)
open("out.jpg", "wb").write(base64.b64decode(res.data[0].b64_json))

Or without an SDK:

curl https://api.tokenify.dev/v1/images/generations \
-H "Authorization: Bearer $TOKENIFY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedream-5.0-pro",
"prompt": "A still life of three pears, soft window light",
"size": "1024x1024"
}' | jq -r '.data[0].b64_json' | base64 -d > out.jpg
The image comes back as base64 in data[0].b64_json by default. Ask for response_format: "url" and you get a link to storage of ours instead — we keep the image for 7 days and serve it. Every link we return is ours, on img.tokenify.dev.

Bytes or a link

response_format takes b64_json (the default) or url. The choice is about where the image lives, not about what it costs: both are the same request and the same charge.

response_formatYou getKept for
b64_jsonThe bytes, in data[0].b64_json. About 130 KB of base64 for a 1024×1024 JPEG.Nothing is stored.
urlA link in data[0].url, to storage we control. The host is ours to change and the link may carry a signature — fetch it, do not parse it.7 days, then it stops working.

After 7 days the object is deleted and the link stops working. Depending on where it is served from that is our image_expired error, a plain 404, or an expired signature — treat any non-200 on an image URL as “gone” rather than parsing it. Store the bytes if you need them for longer; re-fetching an old link is not a plan.

The link needs no API key, so it can go straight into an <img> tag or be handed to somebody else. That is the trade: it is unguessable — 160 bits of randomness, carrying nothing about your account, the model or the prompt — but anyone holding it can fetch the image until it expires. If that is not what you want, take the bytes and store them yourself.

Every link we return is ours. The gateway asks for the image as bytes on every call, puts them in storage of ours, and publishes a link on img.tokenify.dev — or no link at all, if you asked for base64. Nothing else is ever in that field.

What it costs

Per image, not per token. These models have no per-token price and no context window; the token counts their vendor reports are metering, and the charge is the price below times the number of images produced. A request that produces nothing is not charged.

ModelPer imageLarger imagesImage you send
bytedance/seedream-5.0-pro$0.036$0.072 from 2.61 megapixels$0.0024 after the first 1
bytedance/seedream-5.0-lite$0.028Same priceFree
bytedance/seedream-5.0-flash$0.018Same priceFree

Where a model charges two prices, the size decides which one applies: above the pixel count in the table it is the dearer rate, and at or below it the cheaper one. The boundary itself is the cheap side, which matters now that any size inside the range is accepted — an image of exactly that many pixels is charged the lower price.

A size tier is priced at the largest image the tier can return, because the model chooses the shape from your prompt. Every shape within one tier falls on the same side of the boundary, so the figure reserved is the figure charged.

Omitting size on Seedream 5.0 Pro costs $0.072, not $0.036. Its default is 2K, which is the model’s own default and above the pixel boundary above — so it is charged at the dearer rate. Send a size if you want the cheaper one.

Credit is reserved at the price of the image you asked for before the request is sent, and for an ordinary generation the charge is that same figure — there is no estimate to settle against, which is the one way per-image billing is simpler than per-token.

Two requests do refund. A set of n images where some fail is charged for the ones that arrived, and layer decomposition reserves its worst case — a base image and sixteen layers — and gives back the difference once the reply says how many layers the model actually found.

The watermark

Generated images carry no watermark unless you ask for one. The model vendor stamps an “AI generated” mark into the bottom-right corner by default — burned into the pixels, not written into metadata — and we turn it off, because a mark you did not ask for on an image you are paying for is a defect. Send watermark: true to have it:

curl https://api.tokenify.dev/v1/images/generations   -H "Authorization: Bearer $TOKENIFY_API_KEY"   -H "Content-Type: application/json"   -d '{
"model": "bytedance/seedream-5.0-pro",
"prompt": "A still life of three pears, soft window light",
"size": "1024x1024",
"watermark": true
}'

Measured against the live models, both ways, before this sentence was written. Whether you want it is your call: some jurisdictions require generated images to be labelled, and the absence of a mark does not change what the image is.

Sizes

size takes a tier name, or any WIDTHxHEIGHT inside the model’s own range. It used to be a list of five strings per model; it is a range now, and anything inside it works.

ModelTiersCustom sizesAspect ratio
bytedance/seedream-5.0-pro1K, 1.5K, 2K0.92 megapixels to 4.62 megapixels1:16 to 16:1
bytedance/seedream-5.0-lite2K, 3K, 4K3.69 megapixels to 16.78 megapixels1:16 to 16:1
bytedance/seedream-5.0-flash1K, 1.5K, 2K0.92 megapixels to 4.62 megapixels1:16 to 16:1

A tier lets the model choose the shape. Ask for 2K and describe a landscape and you get a landscape; ask for 2048x2048 and you get a square. Both are priced the same way, by the pixels produced — see the note on tiers above.

Omitting size means the model’s own default, which is Seedream 5.0 Pro: 2K, Seedream 5.0 Lite: 2048x2048, Seedream 5.0 Flash: 2K. The default is not always the cheapest. On a model that charges more above a pixel threshold, the default tier may be the dearer one — send a size if the price matters to you.

What each tier produces, by aspect ratio. These are the exact pixel sizes the model returns, so they are also what the price is computed from.

bytedance/seedream-5.0-pro

Aspect ratio1K1.5K2K
1:11024x10241536x15362048x2048
4:31152x8641792x13442368x1776
3:4864x11521344x17921776x2368
16:91424x8002048x11522816x1584
9:16800x14241152x20481584x2816
3:21248x8321872x12482496x1664
2:3832x12481248x18721664x2496
21:91568x6722352x10083136x1344

bytedance/seedream-5.0-lite

Aspect ratio2K3K4K
1:12048x20483072x30724096x4096
4:32304x17283456x25924704x3520
3:41728x23042592x34563520x4704
16:92848x16004096x23045504x3040
9:161600x28482304x40963040x5504
3:22496x16643744x24964992x3328
2:31664x24962496x37443328x4992
21:93136x13444704x20166240x2656

bytedance/seedream-5.0-flash

Aspect ratio1K1.5K2K
1:11024x10241536x15362048x2048
4:31152x8641792x13442368x1776
3:4864x11521344x17921776x2368
16:91424x8002048x11522816x1584
9:16800x14241152x20481584x2816
3:21248x8321872x12482496x1664
2:3832x12481248x18721664x2496
21:91568x6722352x10083136x1344

A size outside the range is a 400 that names the range rather than a guess at what you meant. Seedream 5.0 Lite has a floor of 3.69 megapixels — that is the model’s own constraint, and accepting a smaller size would mean charging you for an error from a request that could never have worked.

image_sizes is still published for each model and is still a good list of sizes to choose from, but it is no longer the set of legal values. Read image_presets, image_min_pixels and image_max_pixels from GET https://api.tokenify.dev/v1/models instead.

Editing an image

Send an image alongside the prompt and the model edits it instead of starting from nothing. Every image model here accepts reference images. Seedream 5.0 Pro charges for them after the free allowance below; on the others they are free.There are two ways to send it, and they reach the same place.

POST /v1/images/edits takes multipart form data with the image as a file part, which is what client.images.edit(...) sends. Several files go as image[], in the order you list them — the first is the one the model treats as the subject, and on a model that charges for references it is the free one.

res = client.images.edit(
model="bytedance/seedream-5.0-pro",
image=open("in.jpg", "rb"),
prompt="Replace the background with a plain grey studio wall",
size="2K",
)

mask is a 400: these models have no masked editing, and accepting a mask we cannot honour would repaint the whole picture and bill you for it. Describe the change in the prompt instead.

POST /v1/images/generations takes the same thing as JSON, which is easier when you already have the bytes in memory:

import base64
import os

from openai import OpenAI

client = OpenAI(
base_url="https://api.tokenify.dev/v1",
api_key=os.environ["TOKENIFY_API_KEY"],
)

with open("in.jpg", "rb") as f:
source = base64.b64encode(f.read()).decode()

res = client.images.generate(
model="bytedance/seedream-5.0-pro",
prompt="Replace the background with a plain grey studio wall",
size="1024x1024",
# `image` is not in the OpenAI SDK's own signature, so it travels in
# extra_body. One string, or a list of them for several.
extra_body={"image": f"data:image/jpeg;base64,{source}"},
)
open("out.jpg", "wb").write(base64.b64decode(res.data[0].b64_json))

The image may be raw base64 or a data: URL, and image takes either one or a list of them. The first image you send is free; the per-image charge in the table above applies to the rest, and usage.input_images on the reply says how many were counted.

Several images in one request

n takes 1 to 4. Each image is generated separately and charged separately, and the reservation covers the whole set before the first one starts. If some of them fail you are handed the ones that worked and charged for those; nothing is held for the rest.

Reference images are charged per image generated. Every image in the set is generated from the whole set of references you sent, so a request for four images with three references pays the reference fee four times — the same as making four requests yourself, which is what it is. On the models where references are free this makes no difference.

Asking for more than the model makes is a 400 rather than a quiet clamp: n decides what you are charged, so being given fewer images than you paid a reservation for is not something to discover from the response.

What the parameters do

Three kinds of parameter, and the difference is the whole rule. Anything not on these lists is a 400 that names the field. It used to be dropped silently, which meant a request for a transparent background was answered with an opaque image at full price and nothing anywhere said why.

ParameterWhat it does
promptWhat to draw, or what to change. Required unless you send an image.
imageOne reference image or a list of them, as base64 or a data: URL.
sizeA tier name or WIDTHxHEIGHT. See above.
n1 to 4.
response_formatb64_json (the default) or url.
output_formatpng or jpeg. webp is a 400 — these models do not make it.
backgroundtransparent or opaque, on the models that have it. Transparent needs output_format: "png".
watermarkfalse by default. true burns the vendor mark into the corner.

Quality is set per request on the models that have it, and left at the model’s own default otherwise — medium today, published as image_default_quality in /v1/models. It changes the number of output tokens the model reports and therefore what the request costs: measured at 1536×1024, low is 158 tokens, medium 343 and high 1,372. Ask for low if you want the cheap one.

Model-dependent: quality, output_compression and moderation are forwarded to the models whose makers implement them, and refused by name on the models that do not. They used to be accepted and ignored, which was true until models arrived that obey them — and ignoring quality is not cosmetic, because it changes both the picture and what the request costs. Each model’s supported_parameters in /v1/models lists exactly what it takes.

Accepted and ignored, because an OpenAI SDK sends them by habit and none of them changes what is generated here: user, style, partial_images, input_fidelity, seed and guidance_scale. They are accepted so that a drop-in stays a drop-in, and listed here so that nobody expects them to do something. user is the one worth a sentence: it exists so you can label your own end users, and we do not pass it upstream, because that would hand your identifiers to somebody else.

Refused by name, because ignoring them would change the picture or the bill: mask (these models have no masked editing — describe the change in the prompt instead), stream (not yet; the reply is one JSON document), and sequential_image_generation (ask for several with n).

The reply

{
"created": 1760000000,
"model": "bytedance/seedream-5.0-pro",
// "b64_json" by default; with response_format: "url" this is
// { "url": "https://img.tokenify.dev/…", "size": "1024x1024", "output_format": "jpeg" }
"data": [{ "b64_json": "...", "size": "1024x1024", "output_format": "jpeg" }],
// Present only when the reply carries links: Unix seconds, 7 days out.
// "expires_at": 1760604800,
"usage": {
"generated_images": 1,
"input_images": 0,
// Reported by the model vendor. Not what you are charged on — the charge is
// per image — and shown here only because it is what they meter.
"output_tokens": 4096,
"input_tokens": 0,
"total_tokens": 4096,
// What this request cost you, in USD.
"cost": 0.036
}
}

generated_images and input_images are the two numbers the charge is computed from, and the same two appear against the request in your activity log, beside what it cost.

Limits and timing

LimitDefaultOn exceeding
Images per minute60The request waits for its turn and then returns its images. 429 ipm_exceeded only if no turn comes in time
Requests per minute1,250429 rpm_exceeded
Images per request1 to 4 with `n`400, not a cap

The image models are limited in images rather than in tokens, because tokens per image move with the size the caller asks for — one token budget would buy a different number of pictures at every size, which is not a limit anybody can plan against. The token ceiling on your key is not consulted for these models, and the image ceiling is not consulted for the chat ones. Rate limits has the rest.

Generation takes seconds, not milliseconds — measured through this gateway, between about ten seconds and a minute depending on the model and the size, with the largest sizes on the slowest model at the top of that range. There is no streaming: the reply arrives when the image does, so set a client timeout above a minute.

Errors

StatusCodeWhat it means
400invalid_sizeThe size is outside this model’s range. The message gives the range and the nearest size the model makes.
400invalid_bodyNo prompt and no image, no model, or a body that is not JSON.
400unknown_parameterA field this endpoint does not accept. error.param names it.
400unsupported_parameterA field it accepts but this model or this route cannot honour — mask, stream, background on a model without it, n above what the model makes.
400wrong_endpointA chat model sent here, or an image model sent to /v1/chat/completions.
404image_expiredA stored image that has passed its 7 days, or a link that was never ours.
400moderation_blockedThe content policy refused the prompt, an image you sent, or the image it produced. Nothing is charged.
400upstream_rejectedThe model declined the request for a reason we did not catch first. Nothing is charged, and retrying the same request will not help.
400invalid_imageA reference image below 14 pixels a side, above 36 megapixels, or larger than 30 MB. Refused before it is sent.
502image_store_failedWe generated the image and could not store it. Not charged.
502upstream_reply_too_largeThe generated image was larger than this endpoint returns — reachable with png at the top of a model’s size range. Ask for jpeg, or a smaller size. Not charged.
413request_too_largeThe request body is above 50 MB, or an uploaded file is above 30 MB. An image sent inline as a data URI is a third larger than the file.
400request_too_largeThe same code with a different status and a different cause: the request may produce more images than your key’s images-a-minute limit, or more base64 than this endpoint returns. Both are about the reply rather than the request body, and neither is retryable.
402insufficient_creditThe price of the image is above your balance. Nothing was sent upstream.
429ipm_exceededAbove your key’s images a minute, and one of: no turn came within the waiting window; you already have the most requests waiting that one key or account may have; or the request arrived without an API key, which has no per-key allowance to queue against. An ordinary keyed request over the allowance waits for its turn instead of being refused, so you do not need retry logic for the allowance itself — but keep handling this code, because the cases above are real. Retry-After says when.
502upstream_unavailableThe model refused or failed. Not charged.

Where to go next

Last updated 2026-10-13.