Image Generation and Editing (text/image → new image)
The platform's image capability is generation-oriented — both entry points return a new image:
| Entry point | What you send | What you get |
|---|---|---|
Text-to-image /v1/images/generations | A prompt (text) | A generated image |
Image editing /v1/images/edits | Source image (one or more) + edit instructions | A new image edited per the instructions |
Editing means "changing an image", not "understanding an image": the source image you pass in is only generation material — the response is a new image, and never a text description of the image content. Calls are synchronous (a single request returns the result directly, with no task polling).
Image generation uses the OpenAI Images API request shape. If you use an OpenAI SDK downstream, point base_url at the platform address; response fields are as defined on this page.
Read this first: the response does not have a single fixed shape.
yaoshu-imageis the platform's unified model name; the platform may schedule different backends per route, so response fields vary by route: some returndata[].b64_json, some return onlydata[].url, some return both, and some also includenative_size/upscaled/width/height. Clients must support bothb64_jsonandurl— do not implement just one; the actual image content, format, width and height are determined by the file header after decoding/downloading.
1. Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/images/generations | Text-to-image (JSON) |
| POST | /v1/images/edits | Image editing (multipart; send the source image/mask) |
| POST | /v1/edits | Image editing (legacy-compatible path; same behavior as /v1/images/edits) |
| GET | /v1/models | List currently available models; availability is defined by the live response |
2. Model Name and Invocation
Always use yaoshu-image externally. The platform schedules backend capability per route; callers neither need to — nor should — specify any other model name.
Response fields may differ across routes; just handle them with the compatibility logic on this page. Model availability is defined by the GET /v1/models response.
3. Text-to-Image /v1/images/generations
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model name; currently yaoshu-image; see the GET /v1/models response for the authoritative list |
prompt | string | ✅ | Prompt |
n | int | No | Number of images. The platform allows 1 image per request: n > 1 returns 400 ("This model supports generating only 1 image per request"); to get multiple images, call repeatedly |
size | string | No | auto (default) or WxH (such as 1024x1024 / 1536x1024). A target-size hint, not a guarantee; aspect ratio limit 3:1 (exceeding it returns 400). Actual dimensions follow data[].size / width / height or the image file header |
quality | string | No | low / medium / high / xhigh / max / auto; accepted by all current routes. Affects service compute time, does not guarantee a change in output pixel dimensions |
background | string | No | auto / opaque / transparent; passed through as-is. The current route does not guarantee preservation of the alpha channel, and the final file may still be JPEG |
output_format | string | No | png / jpeg / webp; the parameter is accepted, but the current route does not guarantee the format of the final url (the final url is commonly JPEG, while native_url may be PNG). The file header is authoritative |
output_compression | int | No | 0–100, jpeg/webp only; a standard parameter, not guaranteed to take effect on current routes |
moderation | string | No | auto / low; forwarded as-is, with the actual effect decided by the server |
stream | boolean | No | Ignored on the current route: passing true still returns plain JSON (not SSE); do not rely on streaming |
response_format | string | No | url → b64_json is not returned (optional fields such as native_size / native_url / upscaled may still be present); b64_json → returns both b64_json and url; omitted → the current route returns both. Other routes may return only one of them, so clients must handle both |
user | string | No | Optional; forwarded as-is |
The platform only guarantees the parameters in the table above; unlisted parameters are not guaranteed to take effect. Image generation is a synchronous long request — complex prompts may take tens of seconds to several minutes, so allow a generous timeout.
How size Actually Behaves
size is a hint, not a guarantee; the aspect ratio may also be altered by the route. Measured on the current route:
Requested size | Actual output (example) | Notes |
|---|---|---|
auto | 1312×1199 PNG | Native size, usually no upscale; native_size/upscaled may be absent |
1024x1024 | 1024×936 / 1024×1024 JPEG | 1:1 not guaranteed; native_size may be 1254×1254 / 1312×1199 |
1536x1024 | 1536×1536 JPEG | 3:2 not guaranteed; may be stretched to a square |
2048x1152 | 2048×1872 JPEG | 16:9 not guaranteed |
3840x2160 | 3840×3509 JPEG | 16:9 not guaranteed; long edge 3840 |
2048x640 (3.2:1) | 400 | Exceeds the 3:1 limit |
- Aspect ratio limit 3:1: long edge ÷ short edge ≤ 3; exceeding it returns 400.
- Trust the actual file first: decode
b64_jsonor downloadurl, then read the PNG/JPEG/WebP file header; if the response carriesdata[].width/heightordata[].size, treat it as a reference — do not assume it is always present. data[].sizemay be the output size, not the requested size; do not lay out your content from the requestedWxHdirectly.- 2K/4K: the current route can return 2K/4K-level output (such as 3840×3509), but it depends on the actual route; do not promise a fixed resolution.
Request examples
URL only (recommended for tall/large images, to avoid Base64 bloat):
curl https://token.yaoshu.cc/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "yaoshu-image",
"prompt": "an orange cat wearing an astronaut helmet, cyberpunk style",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'Base64 (the current route also returns url, so either works):
curl https://token.yaoshu.cc/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "yaoshu-image",
"prompt": "an orange cat wearing an astronaut helmet, cyberpunk style",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'Response fields
Stable fields (returned by the current route in all cases):
| Field | Description |
|---|---|
created | Generation timestamp (seconds) |
data[] | Image array; with n=1 it usually contains a single item |
usage | Service usage statistics; may be real tokens, or all zeros (common on some routes). Images are billed per image — do not use usage to estimate cost |
Fields inside data[] (at least one of b64_json or url is present):
| Field | Always present | Description |
|---|---|---|
b64_json | No | Image content, Base64; decode it to get the image file |
url | No | Image URL; downloadable directly |
id | No | Image ID |
size | No | Output size (such as 1024x936); may be the output size rather than the requested size |
native_size | No | Native/base image size (common on paths that carry upscale fields) |
native_url | No | Native/base image URL (commonly PNG) |
revised_prompt | No | Rewritten prompt |
upscaled | No | Whether the image was upscaled; true means the final image is an upscale product |
upscale_engine | No | Upscale engine (such as lanczos / anime4k:...) |
width / height | No | Output width/height (present in some edit responses) |
bytes / file | No | Output byte size / file name (present in some edit responses) |
Top-level optional fields: model, background, moderation, output_format, quality, size. These are server-side receipts/echoes — do not use them to determine actual dimensions or format.
Key point: do not depend on a single field shape. Both
b64_jsonandurlmay appear, or only one of them;native_size/upscaled/width/heightare all optional.
Compatible Parsing (required reading for clients)
The pattern below holds for all current routes (Node.js example; in browser environments use atob / Uint8Array / Blob instead of Buffer):
type ImageItem = {
b64_json?: string;
url?: string;
size?: string;
native_size?: string;
width?: number;
height?: number;
upscaled?: boolean;
upscale_engine?: string;
};
async function readImage(item: ImageItem): Promise<{ buf: Buffer; source: string }> {
if (item.b64_json) {
return { buf: Buffer.from(item.b64_json, 'base64'), source: 'b64_json' };
}
if (item.url) {
const res = await fetch(item.url);
if (!res.ok) throw new Error(`image download failed: ${res.status}`);
return { buf: Buffer.from(await res.arrayBuffer()), source: 'url' };
}
throw new Error('response has neither b64_json nor url');
}
function imageMeta(buf: Buffer) {
// PNG
if (buf.length > 24 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) {
return { format: 'png', width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
}
// JPEG
if (buf.length > 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) {
let i = 2;
while (i < buf.length - 9) {
if (buf[i] !== 0xff) { i++; continue; }
const marker = buf[i + 1];
const len = buf.readUInt16BE(i + 2);
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
return { format: 'jpeg', height: buf.readUInt16BE(i + 5), width: buf.readUInt16BE(i + 7) };
}
i += 2 + len;
}
return { format: 'jpeg', width: null, height: null };
}
// WebP (VP8X)
if (buf.length > 30 && buf.toString('ascii', 0, 4) === 'RIFF' && buf.toString('ascii', 8, 12) === 'WEBP' && buf.toString('ascii', 12, 16) === 'VP8X') {
return { format: 'webp', width: 1 + buf.readUIntLE(24, 3), height: 1 + buf.readUIntLE(27, 3) };
}
return { format: 'unknown', width: null, height: null };
}Response examples
Shape A: route with upscale fields (b64 + url + native/upscaled)
{
"created": 1731000000,
"data": [
{
"b64_json": "/9j/4AAQSkZJRg...",
"id": 134206,
"native_size": "1312x1199",
"native_url": "https://.../base.png",
"revised_prompt": "a red apple on a white table",
"size": "1024x936",
"upscale_engine": "lanczos",
"upscaled": true,
"url": "https://.../final.jpg"
}
],
"usage": { "input_tokens": 0, "output_tokens": 0, "total_tokens": 0 }
}Actual files:
urlis a JPEG 1024×936;native_urlis the PNG base image.data[].sizematches the file header, but may differ from the requested1024x1024.
Shape B: url-only route (top-level receipt + real usage)
{
"background": "opaque",
"created": 1731000000,
"data": [{ "url": "https://.../image.png" }],
"model": "yaoshu-image",
"moderation": "auto",
"output_format": "png",
"quality": "high",
"size": "1024x1024",
"usage": {
"prompt_tokens": 7,
"completion_tokens": 1083,
"total_tokens": 1090,
"input_tokens": 7,
"output_tokens": 1083
}
}Actual file: PNG 1024×1024. This shape has neither
b64_jsonnordata[].size; you can only downloadurland read the file header.
Another
response_format=urlvariant: the top level has nobackground/quality/sizereceipts, whiledata[0]still carriesnative_size/native_url/upscaled— just nob64_json; download viaurlas usual.
Shape C: native/auto (b64 + url, PNG native size)
{
"created": 1731000000,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"id": 134402,
"revised_prompt": "a red apple on a white table",
"size": "1312x1199",
"url": "https://.../image.png"
}
],
"usage": { "input_tokens": 0, "output_tokens": 0, "total_tokens": 0 }
}
size=autocommonly yields a native 1312×1199 PNG, with nonative_size/upscaled.
SDK Integration
The OpenAI Python SDK works, but do not assume b64_json is always present:
from openai import OpenAI
import base64, requests
client = OpenAI(api_key="sk-your-api-key", base_url="https://token.yaoshu.cc/v1")
result = client.images.generate(
model="yaoshu-image",
prompt="an orange tabby cat",
n=1,
size="1024x1024",
response_format="b64_json",
)
item = result.data[0]
if getattr(item, "b64_json", None):
data = base64.b64decode(item.b64_json)
elif getattr(item, "url", None):
data = requests.get(item.url, timeout=60).content
else:
raise RuntimeError("response has neither b64_json nor url")
with open("cat.img", "wb") as f:
f.write(data)
# Determine the extension from the actual file header; do not hardcode .png4. Image Editing /v1/images/edits
Submit as multipart/form-data; the fields match the official OpenAI fields: model, prompt, image (source image file; for multiple images use image[] or repeat image), mask (optional mask), n, size, quality, background, output_format, response_format. prompt is required.
nis likewise 1 image per request;n > 1returns 400.sizeis a hint here too: whensizeis omitted, the output is decided by the server; passingsize=2048x2048may still return2048x1872(1:1 not guaranteed). Actual dimensions follow the file header.- A single
image, repeatedimage, andimage[]all work for multiple images; the multi-image limit is defined by the server. maskis submitted as the standard OpenAI field; the actual inpainting result is decided by the server.- The legacy path
/v1/editsremains available and behaves like/v1/images/edits.
curl https://token.yaoshu.cc/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key" \
-F model="yaoshu-image" \
-F prompt="replace the background with a snow mountain" \
-F image="@origin.png" \
-F response_format="url"Multi-image reference composition (OpenAI SDK form):
from openai import OpenAI
import base64, requests
client = OpenAI(api_key="sk-your-api-key", base_url="https://token.yaoshu.cc/v1")
result = client.images.edit(
model="yaoshu-image",
prompt="combine the people from both images into a single scene",
image=[open("a.png", "rb"), open("b.png", "rb")],
)
item = result.data[0]
data = base64.b64decode(item.b64_json) if getattr(item, "b64_json", None) else requests.get(item.url, timeout=60).content
open("out.img", "wb").write(data)Edit responses
The response structure follows the same compatibility rules as text-to-image:
- May return
b64_json + url + native_size/upscaled(common for edits that passsize); - May also return only
urlplus top-levelbackground/model/moderation/output_format/quality/size(common for single-image and legacy-path calls); usagemay contain real tokens, or zeros;- Do not hardcode a single shape; handle it with the
readImage()logic above.
Measured examples:
| Edit request | Measured result |
|---|---|
Single image, no size | url-only, PNG 1024×1024 (on some routes); may also be b64+url at native size |
size=2048x2048 | b64+url+native/upscaled, JPEG 2048×1872 (1:1 not guaranteed) |
Multiple image[] ×2 | b64+url, PNG 1312×1199 (native size) |
Legacy path /v1/edits | url-only, PNG 1024×1024 (on some routes) |
n=2 | 400 (1 image per request) |
5. Errors and Retries
| HTTP | Error code | Scenario | Handling |
|---|---|---|---|
| 400 | invalid_request | n>1, aspect ratio >3:1, invalid size | Fix the parameters and retry; do not retry unchanged |
| 429 | rate_limit_error / retry_time_budget_exceeded | Platform rate limiting, service unresponsive for a long time | Retry with exponential backoff; do not retry a single request indefinitely |
| 502 / 503 | upstream_http_error / upstream_temporarily_unavailable | Service 5xx, route temporarily unavailable, circuit breaking | Retry with backoff; if failures persist, tell the user to try again later |
| 401 / 403 | Authentication error | Invalid key / no permission | Check Authorization and model permissions |
| 404 | Model/path not found | Wrong model name / route not enabled | Verify the model name with GET /v1/models |
An error body looks like:
{
"error": {
"code": "invalid_request",
"message": "This model supports generating only 1 image per request; adjust n or send multiple requests",
"param": "",
"type": "yaoshu_token_error"
}
}Image generation is a long request: complex prompts or a high
qualitymay take tens of seconds to several minutes. Set the client timeout to ≥180 seconds (300 seconds is fine in production); on 429/502/503 use backoff retries instead of hammering concurrently.
6. Billing
Images are billed per call / per image (see the model pricing page in the console for unit prices); failed requests are not charged. The usage in the response is service usage statistics and may contain real tokens or zeros; do not use it to estimate cost.
7. Compatibility Notes
- Request parameters are universal; response fields are not: every request uses
yaoshu-imageand the same/v1/images/*set, but different routes return different field sets. - At least one of
b64_jsonandurlis present: clients must support both; decodeb64_jsonwhen present, otherwise downloadurl. - Do not rely heavily on
size/output_format/background/stream: on current routes,sizeis a hint,output_formatmay be ignored (the finalurlis commonly JPEG), transparent backgrounds are not guaranteed to be preserved, andstreamis ignored with plain JSON returned. - Actual dimensions/format follow the file header:
data[].size/width/height/ top-levelsizemay all be missing or merely echoed. - Routes may change: after the platform adjusts scheduling, the backend route behind
yaoshu-imagemay change and the response shape may change with it. Handle responses with the compatibility logic on this page; do not hardcode the fields of any single response.
