Skip to main content

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.

bash
curl https://api.opencheese.dev/v1/images/capabilities \
  -H "Authorization: Bearer $OPENCHEESE_API_KEY"

An abridged answer:

json
{
  "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

bash
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 background needs an output_format that keeps it (png, webp or svg): a JPEG or GIF has no transparency, so the pair is refused.
  • output_compression (100 compresses least) applies to jpeg and webp; frame_count and frame_duration_ms (milliseconds per frame) apply to gif, an animation.
  • Where an image_size entry has a default, a different size needs an aspect_ratio other than auto, and gif output keeps the default size.
  • aspect_ratio: auto leaves 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:

bash
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:

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

bash
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
bash
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_extend and thinking are on unless you send false.
  • A thinking entry with "requiresPromptExtend": true runs only while prompt_extend is on: "thinking": true together with "prompt_extend": false is refused. With "generateOnly": true it applies to /v1/images/generations only.
  • A field the model does not take is refused with unsupported_parameter.

Limits

  • Image responses are not streamed: stream and partial_images are refused.
  • Some models return one image per request; /v1/images/capabilities says how many n allows.
  • moderation cannot be changed; the model's default applies.
  • A prompt the model's own content policy declines is refused with moderation_blocked and not charged. A few models check the finished picture instead and charge for one they reject: that answer is moderation_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.

The cheese has holes. Your infrastructure should not.