API guide
GPT Image 2 VIP API
This page shows the API settings currently used by YingTu. The example never includes your real key.
Quickstart
- 1
Create or choose a LaoZhang API Key.
- 2
Copy the model ID and code example.
- 3
Run one small request and inspect the response before scaling.
Request details
- Generation endpoint
- POST /v1/images/generations
- Editing endpoint
- POST /v1/images/edits
- Base URL
- https://api2.laozhang.ai
- Authentication
- Bearer API Key
- Request format
- OpenAI Images
- Reference images
- Supported
- Reference-image limit
- 5 images in YingTu (not a provider maximum)
- Verification status
- Not yet verified — no dated verification record is available.
Python example
Replace the placeholder key and prompt. Use the documented edit endpoint when adding reference images.
Text-to-image example
export LAOZHANG_API_KEY="replace-with-your-key"
curl --fail-with-body --max-time 500 \
-X POST 'https://api2.laozhang.ai/v1/images/generations' \
-H "Authorization: Bearer ${LAOZHANG_API_KEY}" \
-H "Content-Type: application/json" \
--data '{"model":"gpt-image-2-vip","prompt":"A minimal coffee poster with the exact headline “COFFEE MADE SIMPLE”, high contrast type, warm natural light, clean commercial layout.","size":"2048x2048","quality":"high"}'
# The JSON response can contain base64 image data or an image URL.
# If this request times out, check request and billing logs before retrying.Reference-image editing example
import base64
import mimetypes
import os
import sys
import requests
API_KEY = os.environ.get("LAOZHANG_API_KEY")
if not API_KEY:
raise RuntimeError("Set the LAOZHANG_API_KEY environment variable before running this example.")
REQUEST_TIMEOUT_SECONDS = 500
headers = {"Authorization": f"Bearer {API_KEY}"}
def extension_for_mime(mime_type):
return {
"image/jpeg": "jpg",
"image/png": "png",
"image/webp": "webp",
"image/gif": "gif",
}.get(mime_type, "bin")
def decode_base64_image(value, fallback_mime="image/png"):
mime_type = fallback_mime
encoded = value
if value.startswith("data:"):
header, encoded = value.split(",", 1)
mime_type = header[5:].split(";", 1)[0] or fallback_mime
return base64.b64decode(encoded, validate=True), mime_type
def parse_json_response(response):
try:
result = response.json()
except ValueError as error:
print("API returned a non-JSON response.", file=sys.stderr)
raise SystemExit(1) from error
if not isinstance(result, dict):
print("API returned an unexpected JSON shape.", file=sys.stderr)
raise SystemExit(1)
return result
def extract_image(result):
if not isinstance(result, dict):
return None
images = result.get("data") or []
first_image = images[0] if images and isinstance(images[0], dict) else {}
encoded = first_image.get("b64_json")
if isinstance(encoded, str) and encoded:
return decode_base64_image(encoded)
image_url = first_image.get("url")
if isinstance(image_url, str) and image_url:
image_response = requests.get(image_url, timeout=REQUEST_TIMEOUT_SECONDS)
image_response.raise_for_status()
mime_type = image_response.headers.get("Content-Type", "image/png").split(";", 1)[0]
return image_response.content, mime_type
return None
def save_result_image(result):
extracted = extract_image(result)
if not extracted:
keys = sorted(result.keys()) if isinstance(result, dict) else []
print(f"No image data in response. Top-level keys: {keys}", file=sys.stderr)
raise SystemExit(1)
image_bytes, mime_type = extracted
output_path = f"output.{extension_for_mime(mime_type)}"
with open(output_path, "wb") as output_file:
output_file.write(image_bytes)
print(f"Image saved: {output_path} ({mime_type})")
API_URL = "https://api2.laozhang.ai/v1/images/edits"
data = {
"model": "gpt-image-2-vip",
"prompt": "A minimal coffee poster with the exact headline “COFFEE MADE SIMPLE”, high contrast type, warm natural light, clean commercial layout.",
"size": "2048x2048",
"quality": "high"
}
opened_files = []
files = []
image_1_path = "image_1.jpg" # Replace with your reference image path
image_1_mime = mimetypes.guess_type(image_1_path)[0] or "image/jpeg"
image_1_file = open(image_1_path, "rb")
opened_files.append(image_1_file)
files.append(("image", (image_1_path, image_1_file, image_1_mime)))
try:
try:
response = requests.post(
API_URL,
headers=headers,
data=data,
files=files,
timeout=REQUEST_TIMEOUT_SECONDS,
)
except requests.Timeout as error:
print(
"Request timed out after 500 seconds. The result status may be unknown; "
"check call and billing logs before retrying.",
file=sys.stderr,
)
raise SystemExit(1) from error
finally:
for image_file in opened_files:
image_file.close()
if response.status_code != 200:
print(f"API error {response.status_code}: {response.text}", file=sys.stderr)
raise SystemExit(1)
save_result_image(parse_json_response(response))
Request parameters
The names below match the active YingTu client and generated examples.
- model
- Required. Use the exact model ID shown on this page.
- prompt
- Required. Send your image instruction; never place the API key in the prompt.
- output controls
sizeis selected from the exact sizes configured in the model registry.- quality
- Optional. Send one of the configured quality levels for this route.
- reference images
- Optional. Up to 5 images in the YingTu browser are sent as multipart
imagefields to the edit endpoint.
Response and timeout handling
- Image response
- The client decodes
data[0].b64_json, including data URLs, or downloadsdata[0].urland preserves its MIME type. - Non-image response
- A response without
b64_jsonorurlis not treated as success. The API message is shown when available.
500-second client timeout
The existing YingTu client aborts the request after 500 seconds. At that point the upstream result and charge may still be unknown.
No automatic retry
YingTu does not retry automatically. Check request and billing logs before deciding whether to submit another paid call.
Common error paths
- Authentication
- Confirm that the environment variable contains the intended key and that the request sends it as a Bearer credential.
- Access or balance
- Check model access, current balance, billing, and account restrictions in LaoZhang.
- Rate limit
- Reduce concurrency and inspect the returned upstream or account message before trying again.
- Non-image or empty result
- Inspect block and finish reasons, the API message, and any response ID. Revise the prompt only when the response explains why.
- Timeout
- The final state may be unknown. Check call and billing logs before making another request.
Known limitations
Check these points before using a generated result.
- Inspect the downloaded file dimensions; configured output controls do not replace result verification.
- Proofread every visible word, number, and punctuation mark in the generated image.
- Review identity, logos, packaging, colors, and small brand details before use.
- Availability and latency can vary with upstream capacity.
- Confirm live pricing, balance, access, and charges in the LaoZhang account.
API FAQ
Where should I store the API key?
Use the environment variable shown in the code example. Do not commit, print, or place the full key in a prompt.
Does a timeout mean the request failed?
Not necessarily. After 500 seconds YingTu stops waiting, but the upstream result or charge may still be unknown. Check logs before retrying.
Is the reference-image count a provider maximum?
No. This page shows YingTu’s current limit, not an upstream provider maximum.
Where do I confirm price and access?
Use the LaoZhang account as the authority for current pricing, balance, model access, and charges.
Price and billing
The page shows a reference price. Check your LaoZhang account for the current price, balance, access, and charges.
- Model ID
- gpt-image-2-vip
- Reference price
- $0.03/ call
- Output sizes
- 1K / 2K / 4K
- Exact output sizes
- 30 available sizes
- Quality levels
- low / medium / high
- API format
- OpenAI Images
Test this model in Studio
These are the settings currently available in the Image Studio.
YingTuLaoZhang