Skip to content

Image Generation and Editing (text/image → new image) ​

The platform's image capability is generation-oriented — both entry points return a new image:

Entry pointWhat you sendWhat you get
Text-to-image /v1/images/generationsA prompt (text)A generated image
Image editing /v1/images/editsSource image (one or more) + edit instructionsA 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-image is the platform's unified model name; the platform may schedule different backends per route, so response fields vary by route: some return data[].b64_json, some return only data[].url, some return both, and some also include native_size / upscaled / width / height. Clients must support both b64_json and url — do not implement just one; the actual image content, format, width and height are determined by the file header after decoding/downloading.

1. Endpoints ​

MethodPathDescription
POST/v1/images/generationsText-to-image (JSON)
POST/v1/images/editsImage editing (multipart; send the source image/mask)
POST/v1/editsImage editing (legacy-compatible path; same behavior as /v1/images/edits)
GET/v1/modelsList 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 ​

ParameterTypeRequiredDescription
modelstring✅Model name; currently yaoshu-image; see the GET /v1/models response for the authoritative list
promptstring✅Prompt
nintNoNumber 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
sizestringNoauto (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
qualitystringNolow / medium / high / xhigh / max / auto; accepted by all current routes. Affects service compute time, does not guarantee a change in output pixel dimensions
backgroundstringNoauto / 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_formatstringNopng / 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_compressionintNo0–100, jpeg/webp only; a standard parameter, not guaranteed to take effect on current routes
moderationstringNoauto / low; forwarded as-is, with the actual effect decided by the server
streambooleanNoIgnored on the current route: passing true still returns plain JSON (not SSE); do not rely on streaming
response_formatstringNourl → 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
userstringNoOptional; 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 sizeActual output (example)Notes
auto1312×1199 PNGNative size, usually no upscale; native_size/upscaled may be absent
1024x10241024×936 / 1024×1024 JPEG1:1 not guaranteed; native_size may be 1254×1254 / 1312×1199
1536x10241536×1536 JPEG3:2 not guaranteed; may be stretched to a square
2048x11522048×1872 JPEG16:9 not guaranteed
3840x21603840×3509 JPEG16:9 not guaranteed; long edge 3840
2048x640 (3.2:1)400Exceeds 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_json or download url, then read the PNG/JPEG/WebP file header; if the response carries data[].width / height or data[].size, treat it as a reference — do not assume it is always present.
  • data[].size may be the output size, not the requested size; do not lay out your content from the requested WxH directly.
  • 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):

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

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

FieldDescription
createdGeneration timestamp (seconds)
data[]Image array; with n=1 it usually contains a single item
usageService 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):

FieldAlways presentDescription
b64_jsonNoImage content, Base64; decode it to get the image file
urlNoImage URL; downloadable directly
idNoImage ID
sizeNoOutput size (such as 1024x936); may be the output size rather than the requested size
native_sizeNoNative/base image size (common on paths that carry upscale fields)
native_urlNoNative/base image URL (commonly PNG)
revised_promptNoRewritten prompt
upscaledNoWhether the image was upscaled; true means the final image is an upscale product
upscale_engineNoUpscale engine (such as lanczos / anime4k:...)
width / heightNoOutput width/height (present in some edit responses)
bytes / fileNoOutput 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_json and url may appear, or only one of them; native_size / upscaled / width / height are 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):

ts
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)

json
{
  "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: url is a JPEG 1024×936; native_url is the PNG base image. data[].size matches the file header, but may differ from the requested 1024x1024.

Shape B: url-only route (top-level receipt + real usage)

json
{
  "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_json nor data[].size; you can only download url and read the file header.

Another response_format=url variant: the top level has no background / quality / size receipts, while data[0] still carries native_size / native_url / upscaled — just no b64_json; download via url as usual.

Shape C: native/auto (b64 + url, PNG native size)

json
{
  "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=auto commonly yields a native 1312×1199 PNG, with no native_size / upscaled.

SDK Integration ​

The OpenAI Python SDK works, but do not assume b64_json is always present:

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

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

  • n is likewise 1 image per request; n > 1 returns 400.
  • size is a hint here too: when size is omitted, the output is decided by the server; passing size=2048x2048 may still return 2048x1872 (1:1 not guaranteed). Actual dimensions follow the file header.
  • A single image, repeated image, and image[] all work for multiple images; the multi-image limit is defined by the server.
  • mask is submitted as the standard OpenAI field; the actual inpainting result is decided by the server.
  • The legacy path /v1/edits remains available and behaves like /v1/images/edits.
bash
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):

python
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 pass size);
  • May also return only url plus top-level background/model/moderation/output_format/quality/size (common for single-image and legacy-path calls);
  • usage may contain real tokens, or zeros;
  • Do not hardcode a single shape; handle it with the readImage() logic above.

Measured examples:

Edit requestMeasured result
Single image, no sizeurl-only, PNG 1024×1024 (on some routes); may also be b64+url at native size
size=2048x2048b64+url+native/upscaled, JPEG 2048×1872 (1:1 not guaranteed)
Multiple image[] ×2b64+url, PNG 1312×1199 (native size)
Legacy path /v1/editsurl-only, PNG 1024×1024 (on some routes)
n=2400 (1 image per request)

5. Errors and Retries ​

HTTPError codeScenarioHandling
400invalid_requestn>1, aspect ratio >3:1, invalid sizeFix the parameters and retry; do not retry unchanged
429rate_limit_error / retry_time_budget_exceededPlatform rate limiting, service unresponsive for a long timeRetry with exponential backoff; do not retry a single request indefinitely
502 / 503upstream_http_error / upstream_temporarily_unavailableService 5xx, route temporarily unavailable, circuit breakingRetry with backoff; if failures persist, tell the user to try again later
401 / 403Authentication errorInvalid key / no permissionCheck Authorization and model permissions
404Model/path not foundWrong model name / route not enabledVerify the model name with GET /v1/models

An error body looks like:

json
{
  "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 quality may 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 ​

  1. Request parameters are universal; response fields are not: every request uses yaoshu-image and the same /v1/images/* set, but different routes return different field sets.
  2. At least one of b64_json and url is present: clients must support both; decode b64_json when present, otherwise download url.
  3. Do not rely heavily on size / output_format / background / stream: on current routes, size is a hint, output_format may be ignored (the final url is commonly JPEG), transparent backgrounds are not guaranteed to be preserved, and stream is ignored with plain JSON returned.
  4. Actual dimensions/format follow the file header: data[].size / width / height / top-level size may all be missing or merely echoed.
  5. Routes may change: after the platform adjusts scheduling, the backend route behind yaoshu-image may 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.

Public documentation for platform users