Source: https://www.tokenify.dev/docs/images/

# Image generation

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

**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](https://www.tokenify.dev/docs/images/seedream-api/) and [google-genai’s generateContent](https://www.tokenify.dev/docs/images/gemini/) are the other two, and [layer decomposition](https://www.tokenify.dev/docs/images/layers/) 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](https://www.tokenify.dev/docs/images/#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.

```python
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:

```bash
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](https://www.tokenify.dev/docs/images/#response-format)

`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\_format | You get                                                                                                                                    | Kept for                       |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
| b64\_json        | The bytes, in data\[0\].b64\_json. About 130 KB of base64 for a 1024×1024 JPEG.                                                            | Nothing is stored.             |
| url              | A 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](https://www.tokenify.dev/docs/images/#pricing)

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.

| Model                        | Per image | Larger images               | Image 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.028    | Same price                  | Free                      |
| bytedance/seedream-5.0-flash | $0.018    | Same price                  | Free                      |

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](https://www.tokenify.dev/docs/images/layers/) 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](https://www.tokenify.dev/docs/images/#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:

```bash
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](https://www.tokenify.dev/docs/images/#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.

| Model                        | Tiers        | Custom sizes                        | Aspect ratio |
| ---------------------------- | ------------ | ----------------------------------- | ------------ |
| bytedance/seedream-5.0-pro   | 1K, 1.5K, 2K | 0.92 megapixels to 4.62 megapixels  | 1:16 to 16:1 |
| bytedance/seedream-5.0-lite  | 2K, 3K, 4K   | 3.69 megapixels to 16.78 megapixels | 1:16 to 16:1 |
| bytedance/seedream-5.0-flash | 1K, 1.5K, 2K | 0.92 megapixels to 4.62 megapixels  | 1: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 ratio | 1K        | 1.5K      | 2K        |
| ------------ | --------- | --------- | --------- |
| 1:1          | 1024x1024 | 1536x1536 | 2048x2048 |
| 4:3          | 1152x864  | 1792x1344 | 2368x1776 |
| 3:4          | 864x1152  | 1344x1792 | 1776x2368 |
| 16:9         | 1424x800  | 2048x1152 | 2816x1584 |
| 9:16         | 800x1424  | 1152x2048 | 1584x2816 |
| 3:2          | 1248x832  | 1872x1248 | 2496x1664 |
| 2:3          | 832x1248  | 1248x1872 | 1664x2496 |
| 21:9         | 1568x672  | 2352x1008 | 3136x1344 |

`bytedance/seedream-5.0-lite`

| Aspect ratio | 2K        | 3K        | 4K        |
| ------------ | --------- | --------- | --------- |
| 1:1          | 2048x2048 | 3072x3072 | 4096x4096 |
| 4:3          | 2304x1728 | 3456x2592 | 4704x3520 |
| 3:4          | 1728x2304 | 2592x3456 | 3520x4704 |
| 16:9         | 2848x1600 | 4096x2304 | 5504x3040 |
| 9:16         | 1600x2848 | 2304x4096 | 3040x5504 |
| 3:2          | 2496x1664 | 3744x2496 | 4992x3328 |
| 2:3          | 1664x2496 | 2496x3744 | 3328x4992 |
| 21:9         | 3136x1344 | 4704x2016 | 6240x2656 |

`bytedance/seedream-5.0-flash`

| Aspect ratio | 1K        | 1.5K      | 2K        |
| ------------ | --------- | --------- | --------- |
| 1:1          | 1024x1024 | 1536x1536 | 2048x2048 |
| 4:3          | 1152x864  | 1792x1344 | 2368x1776 |
| 3:4          | 864x1152  | 1344x1792 | 1776x2368 |
| 16:9         | 1424x800  | 2048x1152 | 2816x1584 |
| 9:16         | 800x1424  | 1152x2048 | 1584x2816 |
| 3:2          | 1248x832  | 1872x1248 | 2496x1664 |
| 2:3          | 832x1248  | 1248x1872 | 1664x2496 |
| 21:9         | 1568x672  | 2352x1008 | 3136x1344 |

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](https://www.tokenify.dev/docs/images/#editing)

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.

```python
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:

```python
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](https://www.tokenify.dev/docs/images/#sets)

`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](https://www.tokenify.dev/docs/images/#parameters)

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.

| Parameter        | What it does                                                                                |
| ---------------- | ------------------------------------------------------------------------------------------- |
| prompt           | What to draw, or what to change. Required unless you send an image.                         |
| image            | One reference image or a list of them, as base64 or a data: URL.                            |
| size             | A tier name or WIDTHxHEIGHT. See above.                                                     |
| n                | 1 to 4.                                                                                     |
| response\_format | b64\_json (the default) or url.                                                             |
| output\_format   | png or jpeg. webp is a 400 — these models do not make it.                                   |
| background       | transparent or opaque, on the models that have it. Transparent needs output\_format: "png". |
| watermark        | false 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](https://www.tokenify.dev/docs/images/#reply)

```jsonc
{
  "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](https://www.tokenify.dev/app/logs), beside what it cost.

## [Limits and timing](https://www.tokenify.dev/docs/images/#limits)

| Limit               | Default           | On exceeding                                                                                                    |
| ------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------- |
| Images per minute   | 60                | The request **waits for its turn** and then returns its images. 429 ipm\_exceeded only if no turn comes in time |
| Requests per minute | 1,250             | 429 rpm\_exceeded                                                                                               |
| Images per request  | 1 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](https://www.tokenify.dev/docs/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](https://www.tokenify.dev/docs/images/#errors)

| Status | Code                        | What it means                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------ | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400    | invalid\_size               | The size is outside this model’s range. The message gives the range and the nearest size the model makes.                                                                                                                                                                                                                                                                                                                                                                                                  |
| 400    | invalid\_body               | No prompt and no image, no model, or a body that is not JSON.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 400    | unknown\_parameter          | A field this endpoint does not accept. error.param names it.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| 400    | unsupported\_parameter      | A 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.                                                                                                                                                                                                                                                                                                                                                              |
| 400    | wrong\_endpoint             | A chat model sent here, or an image model sent to /v1/chat/completions.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| 404    | image\_expired              | A stored image that has passed its 7 days, or a link that was never ours.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 400    | moderation\_blocked         | The content policy refused the prompt, an image you sent, or the image it produced. Nothing is charged.                                                                                                                                                                                                                                                                                                                                                                                                    |
| 400    | upstream\_rejected          | The model declined the request for a reason we did not catch first. Nothing is charged, and retrying the same request will not help.                                                                                                                                                                                                                                                                                                                                                                       |
| 400    | invalid\_image              | A reference image below 14 pixels a side, above 36 megapixels, or larger than 30 MB. Refused before it is sent.                                                                                                                                                                                                                                                                                                                                                                                            |
| 502    | image\_store\_failed        | We generated the image and could not store it. Not charged.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 502    | upstream\_reply\_too\_large | The 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.                                                                                                                                                                                                                                                                                                                                           |
| 413    | request\_too\_large         | The 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.                                                                                                                                                                                                                                                                                                                                                                   |
| 400    | request\_too\_large         | The 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.                                                                                                                                                                                                                                        |
| 402    | insufficient\_credit        | The price of the image is above your balance. Nothing was sent upstream.                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| 429    | ipm\_exceeded               | Above 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. |
| 502    | upstream\_unavailable       | The model refused or failed. Not charged.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

## [Where to go next](https://www.tokenify.dev/docs/images/#next)

- [Seedream 5.0 Pro](https://www.tokenify.dev/models/seedream-5-0-pro/) — the price, the sizes and a worked example.
- [Seedream 5.0 Lite](https://www.tokenify.dev/models/seedream-5-0-lite/) — the price, the sizes and a worked example.
- [Seedream 5.0 Flash](https://www.tokenify.dev/models/seedream-5-0-flash/) — the price, the sizes and a worked example.

Last updated 2026-10-13.
