Image Generation & Editing
HJToken supports the official OpenAI gpt-image models for text-to-image generation and image editing. The API matches OpenAI's exactly — point your existing SDK at a new base_url and it works.
Supported models
| Model | Position | Notes |
|---|---|---|
gpt-image-2 | Flagship | Best quality and prompt adherence — use for final deliverables |
gpt-image-1.5 | Previous flagship | Stable, slightly cheaper |
gpt-image-1 | Legacy | OpenAI deprecates it on 2026-10-23 — don't use for new work |
gpt-image-1-mini | Budget | Cheapest; ideal for bulk drafts and prompt iteration |
The authoritative list is the model pricing page, which syncs automatically with upstream.
Billing: per output token, not per image
This is the part worth understanding up front, because it differs from many platforms:
gpt-image models are billed by token. A request costs roughly:
prompt tokens × input rate
+ reference image tokens × image input rate (editing / reference images only)
+ generated image tokens × image output rateHigher quality and larger size produce more output tokens, so they cost more. For the same 1024×1024 image:
| Quality | Approx. output tokens | Relative cost |
|---|---|---|
low | a few hundred | lowest |
medium | a few thousand | moderate |
high | 4,000+ | highest |
So while iterating on prompts, use low quality with gpt-image-1-mini and only switch to high quality for the final render — that alone removes most of the cost.
Per-model image output rates are in the "Image output (/1M)" column on the model pricing page. Actual token counts and charges are itemized under usage.
Option 1: generate directly in Chat (no code)
- Open Chat
- Pick a
gpt-image-*model in the model selector - Switch the mode to Image (or Edit and upload a source image)
- Choose a quality tier (low / medium / high), type your description, send
Download the result directly. Charges are identical to the API path and come from the same balance.
Option 2: call the API
Base URL: https://api.hjtoken.cn
Text-to-image — /v1/images/generations
curl https://api.hjtoken.cn/v1/images/generations \
-H "Authorization: Bearer $HJTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A shiba inu wearing an astronaut helmet, cyberpunk neon backdrop, cinematic lighting",
"size": "1024x1024",
"quality": "medium",
"n": 1
}'data[].b64_json in the response is the base64-encoded image — decode it to a file:
cat response.json | jq -r '.data[0].b64_json' | base64 -d > out.pngImage editing — /v1/images/edits
Editing uses multipart/form-data with the source image as a file upload:
curl https://api.hjtoken.cn/v1/images/edits \
-H "Authorization: Bearer $HJTOKEN_API_KEY" \
-F model="gpt-image-2" \
-F image="@input.png" \
-F prompt="Replace the background with a snowy mountain at sunset, keep the subject unchanged" \
-F size="1024x1024" \
-F quality="medium"With the OpenAI SDK
Change only base_url and api_key; everything else follows OpenAI's docs:
from openai import OpenAI
client = OpenAI(
api_key="your HJToken API key",
base_url="https://api.hjtoken.cn/v1",
)
result = client.images.generate(
model="gpt-image-2",
prompt="Minimal line-art illustration of mountain ranges, off-white background",
size="1024x1024",
quality="low",
)
import base64
with open("out.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))Common parameters
| Parameter | Values | Notes |
|---|---|---|
prompt | text | Image description. The more specific (subject, style, composition, lighting), the more consistent the result |
size | 1024x1024, 1024x1536, 1536x1024, … | Larger sizes consume more output tokens |
quality | low / medium / high | The parameter with the largest cost impact |
n | integer | How many images per request. Cost scales per image |
FAQ
Why base64 instead of a URL? The official gpt-image API returns base64 and does not host the result. It also means the image never touches third-party storage.
Does HJToken store my images? No. The gateway only forwards the request and records billing metadata (token counts and cost) — image content is not retained.
Can I generate video? Not yet. Only image generation is available today.
Why was this image more/less expensive than I expected? Check the output token count for that request under usage — cost is directly proportional to it. Going from low to high quality can be a 10×+ difference in tokens.
I get a "model not available" error. Your current plan or group doesn't include that image model. Check what you can reach under available channels, or contact us to enable it.
