Image generation and editing API
/ API docs← API quickstartView as Markdown
OpenCheese serves the OpenAI Images API for every image model enabled for your account, with the same API key as text and code models.
Find the image models and their parameters
GET /v1/images/capabilities lists every image model your key can use and the parameters each
one accepts, such as size, aspect ratio, image size, quality, background and output format,
and how many images one request may return. Requests are checked against the same list, so
send only the parameters a model names.
curl https://api.opencheese.dev/v1/images/capabilities \
-H "Authorization: Bearer $OPENCHEESE_API_KEY"
An abridged answer:
{
"models": [
{
"publicModelId": "IMAGE_MODEL_ID",
"displayName": "Example Image Model",
"supportsEdit": true,
"maxImagesPerRequest": 1,
"params": [
{ "kind": "enum", "id": "aspect_ratio", "values": ["1:1", "16:9", "9:16"], "initial": "16:9" },
{ "kind": "enum", "id": "quality", "values": ["auto", "low", "medium", "high"], "initial": "auto" },
{ "kind": "integer", "id": "output_compression", "min": 0, "max": 100, "presets": [100, 90, 80], "initial": 90, "formats": ["jpeg", "webp"] }
],
"promptOptions": { "negativePrompt": "instruction", "seed": true }
}
]
}
Each entry in params is a parameter you may send under its id, with the values it accepts.
An integer entry takes any whole number from min to max; its presets are suggestions,
and formats lists the output formats it applies to. initial is a sensible starting value;
default is what applies when you leave the parameter out. maxImagesPerRequest is the largest
n, and supportsEdit says whether the model takes /v1/images/edits. promptOptions lists
the prompt options the model takes, described below.
Generate an image
curl https://api.opencheese.dev/v1/images/generations \
-H "Authorization: Bearer $OPENCHEESE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "IMAGE_MODEL_ID", "prompt": "A wedge of cheese on a circuit board"}'
model and prompt are required. size, quality, background, output_format,
output_compression, frame_count, frame_duration_ms, aspect_ratio, image_size and n
are accepted where the model lists them. Some values only go together:
- A transparent
backgroundneeds anoutput_formatthat keeps it (png,webporsvg): a JPEG or GIF has no transparency, so the pair is refused. output_compression(100 compresses least) applies tojpegandwebp;frame_countandframe_duration_ms(milliseconds per frame) apply togif, an animation.- Where an
image_sizeentry has adefault, a different size needs anaspect_ratioother thanauto, andgifoutput keeps the default size. aspect_ratio: autoleaves the shape to your prompt, such as "a wide 16:9 banner".
The response carries each image as base64 in data[].b64_json; hosted image URLs are not
issued, so response_format accepts only b64_json. opencheese_cost_usd in the same body is
what the request cost you, in credits (USD). To save the first image:
curl ... | jq -r '.data[0].b64_json' | base64 --decode > image.png
Name the file after output_format in the response, the format the picture is in.
With the OpenAI Python SDK:
import base64
from openai import OpenAI
client = OpenAI(base_url="https://api.opencheese.dev/v1", api_key="YOUR_OPENCHEESE_API_KEY")
result = client.images.generate(model="IMAGE_MODEL_ID", prompt="A wedge of cheese on a circuit board")
with open("image.png", "wb") as file:
file.write(base64.b64decode(result.data[0].b64_json))
Edit images
POST /v1/images/edits takes multipart/form-data: the source image in image (or several
in image[]), with model and prompt as form fields.
curl https://api.opencheese.dev/v1/images/edits \
-H "Authorization: Bearer $OPENCHEESE_API_KEY" \
-F "model=IMAGE_MODEL_ID" \
-F "prompt=Turn the scene into night" \
-F "image=@input.png"
- Uploads must be PNG, JPEG, WebP or GIF (a GIF is read as its first frame): up to 5 images, 10 MB each.
- Other file fields, such as
mask, are rejected.
Prompt options
Four more fields shape the picture beside the prompt. Send them in the JSON body of
/v1/images/generations or as form fields of /v1/images/edits; promptOptions in
/v1/images/capabilities says which ones a model takes.
| Field | Value | Taken by |
|---|---|---|
negative_prompt |
Up to 500 characters: what to keep out of the picture | Every model |
seed |
A whole number from 0 to 2147483647: the same seed and prompt give a similar picture again | Models with "seed": true |
prompt_extend |
true or false: the model turns a short prompt into a detailed one before drawing |
Models with "promptExtend": true |
thinking |
true or false: the model thinks the prompt through before drawing, which is slower |
Models with a thinking entry |
curl https://api.opencheese.dev/v1/images/generations \
-H "Authorization: Bearer $OPENCHEESE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "IMAGE_MODEL_ID", "prompt": "A wedge of cheese on a circuit board", "negative_prompt": "text, watermark", "seed": 42}'
"negativePrompt": "native"means the model has a negative prompt of its own. With"instruction"it does not, and your text is added to the end of the prompt as an instruction to avoid those things, which works less strictly.prompt_extendandthinkingare on unless you sendfalse.- A
thinkingentry with"requiresPromptExtend": trueruns only whileprompt_extendis on:"thinking": truetogether with"prompt_extend": falseis refused. With"generateOnly": trueit applies to/v1/images/generationsonly. - A field the model does not take is refused with
unsupported_parameter.
Limits
- Image responses are not streamed:
streamandpartial_imagesare refused. - Some models return one image per request;
/v1/images/capabilitiessays how manynallows. moderationcannot be changed; the model's default applies.- A prompt the model's own content policy declines is refused with
moderation_blockedand not charged. A few models check the finished picture instead and charge for one they reject: that answer ismoderation_blocked_billed.
Image models in chat apps
Chat apps that list every model in one picker can use an image model in a normal chat: on
/v1/chat/completions and /v1/responses the latest user message becomes the prompt and the
picture comes back in the reply. See
Chat Completions for the reply's shape.
Pricing and usage
Image models are priced per image, by resolution and quality, or per token. The prices for your account are on the dashboard's Prices page after you sign in, and every generated image appears under Transactions with its cost.