Set up Image generation API (GPT Image / Nano Banana)
Generate and edit images from your own code in the OpenAI Images format, billed per image
- API format: OpenAI Images
- Base URL format: Up to /v1 (https://gpt.cherrychat.org/v1)
- Recommended model: nano-banana-2.1, gpt-image-2, nano-banana-2
- Platforms: macOS, Windows, Linux
Steps
First: do you need the API at all?
For a few images, just use the Image page on the website, where plans apply. Use this API when your own code needs dozens of images or you are building image generation into a product. It is billed per image from your credits; plans do not cover it. Put these three settings in your code:
- Base URL: https://gpt.cherrychat.org/v1 (Ends in /v1)
- API key: sk-your-key
- Model name: nano-banana-2.1 (Or gpt-image-2 / nano-banana-2)
Draw one with curl and get a link
Run it in a terminal and wait 20–60 seconds. The "url" in the JSON reply is the image; open it in a browser.
Python: generate and save to a file
Run pip install openai, save the code as draw.py and run python draw.py; cat.png appears next to it. Without response_format the reply is base64, which the code decodes and saves.
Edit: upload an image and describe the change
Edits use /v1/images/edits with the reference image uploaded as a file. This turns cat.png into a version with a red scarf, saved as cat-scarf.png.
Count, size and price
n is how many images you want (1–4); you pay only for images actually returned. Write size in pixels, such as 1024x1024, 1536x1024 (landscape) or 1024x1536 (portrait); the image follows that aspect ratio. Per-image prices are on the Models page.
Common pitfalls
- Image models work only with /v1/images/generations and /v1/images/edits; calling /v1/chat/completions returns an unsupported-endpoint error.
- Each image takes 20–60 seconds, so set your timeout to at least 300 seconds (timeout=300 in the samples), not a 60-second default.
- Plans do not cover API calls; they are paid from your credit balance. If it cannot cover the images requested you get a 402.
- Pass response_format=url for a link and download it yourself; otherwise you get base64 of several MB per image, which floods a terminal if printed.
- Streaming image generation is not supported; leave out stream.
Error → cause → fix
| What you see | Why | What to do |
|---|---|---|
| HTTP 400 unsupported_endpoint | An image model was sent to a chat endpoint, or a chat model to the images endpoint | Send image models to https://gpt.cherrychat.org/v1/images/generations |
| Timeout after about a minute | Your client gave up before the image was finished | Raise the timeout to 300 seconds; dropped requests are not charged |
| Edits return 415 or ask for multipart/form-data | The edit request was sent as JSON instead of uploading the image file | Use images.edit in the SDK, or curl -F image=@file, as in step 4 |
| HTTP 400 saying the content was rejected (safety / moderation) | The prompt or reference image triggered content moderation | Rephrase and try again; rejected requests are not charged |
| HTTP 402 or "insufficient balance" (billing_error in Claude format) | Your credits cannot cover this call. API calls are paid from credits only; memberships and unlimited plans do not apply | Top up any amount in the CherryChat Store, then retry after a few seconds |
Guide checked 2026-11-02. The tool's screens may change; the official docs win if they differ.
Operated by UK Company CHERRYCHAT LTD · Company Number 16096119 · Support WeChat: JsnonoChat · Content is AI-generated — please verify before relying on it
