Skip to main content

GPT Image 2 API: Pricing & Python Example

Call it with one LaoZhang API key, using the same endpoint as the YingTu image studio. Below you get the endpoint, parameters, per-image price and copy-paste code. Your real key never appears in the examples. As of October 9, 2026, every model ID on this page is billed per image with no subscription, and one key works for all of them.

Price $0.03/ imageOpenAI Images1K / 2K / 4K$0.1 for new users

Key facts (as of October 10, 2026)

  • Model IDs on this endpoint: gpt-image-2-vip, gpt-image-2.5-flare-vip and gpt-image-2.5-sunburst-vip. One LaoZhang key works for all of them.
  • Price per image: GPT Image 2 VIP $0.03, GPT Image 2.5 Flare $0.03 and GPT Image 2.5 Sunburst $0.03. No subscription; every image is billed on its own.
  • Base URL https://api2.laozhang.ai, OpenAI request format: POST /v1/images/generations · /v1/images/edits.
  • New LaoZhang accounts get $0.1 to test: about 3 GPT Image 2 VIP images.
  • Top-ups on laozhang.ai take cards through Stripe or USDT.

Get it running in 3 steps

  1. 1

    Create an API key at laozhang.ai (new accounts get $0.1).

  2. 2

    Copy the model ID and code below, and put your key in an environment variable.

  3. 3

    Generate one image to check the response, then scale up.

Endpoint and auth

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
Up to 5 in YingTu (a YingTu limit, not the model maximum)
Verification status
No dated test record published yet.

Code example

Swap in your own prompt. For reference images, use the editing example below.

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

Pythongpt-image-2-vip · edit
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))
Prices follow your LaoZhang account. Check your balance and model access before running large batches.

Request parameters

Field names match the YingTu studio and the code examples above.

ParameterHow it is sent
modelRequired. Use the exact model ID shown on this page.
promptRequired. Send your image instruction; never place the API key in the prompt.
output controlssize must be one of the exact sizes listed for this model.
qualityOptional. Send one of the configured quality levels for this route.
reference imagesOptional. Up to 5 images in the YingTu browser are sent as multipart image fields to the edit endpoint.

Response and timeout handling

Image response
The client decodes data[0].b64_json, including data URLs, or downloads data[0].url and preserves its MIME type.
Non-image response
A response without b64_json or url is not treated as success. The API message is shown when available.

500-second client timeout

YingTu waits up to 500 seconds. After a timeout the upstream job may still finish, and whether it was billed shows up in your billing log.

No automatic retry

YingTu never retries on its own. Before retrying, check your call and billing logs so you are not charged twice.

Common errors and fixes

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 before you use a generated image.

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

GPT Image 2 model IDs on this endpoint

Same endpoint, same request; only the model ID changes.

ModelModel IDPriceSizes
GPT Image 2 VIPgpt-image-2-vip$0.03/ image1K / 2K / 4K
GPT Image 2.5 Flaregpt-image-2.5-flare-vip$0.03/ image1K / 2K / 4K
GPT Image 2.5 Sunburstgpt-image-2.5-sunburst-vip$0.03/ image1K / 2K / 4K

API FAQ

How much does the GPT Image 2 API cost?

Per image, no subscription: GPT Image 2 VIP $0.03, GPT Image 2.5 Flare $0.03 and GPT Image 2.5 Sunburst $0.03. Your LaoZhang account shows every charge.

How do I get a GPT Image 2 API key?

Create a token at laozhang.ai (the key button at the top of this page). One key works for every model in the table; new accounts get $0.1 to test.

What is the base URL?

https://api2.laozhang.ai/v1, in the OpenAI Images format: /v1/images/generations and /v1/images/edits.

Is there a free GPT Image 2 API?

You can test it for free: new LaoZhang accounts get $0.1, about 3 GPT Image 2 images. After that every call is billed per image from your balance; there is no monthly plan or quota to buy.

Which sizes does the GPT Image 2 API accept?

Set size to one of 30 exact WIDTHxHEIGHT values, 10 ratios at each of 1K, 2K and 4K: for example 1280x1280, 2048x2048 (the default) or 3840x2160. Quality can be low, medium or high, and every size and quality costs the same $0.03.

Where should I keep the API key?

In the environment variable used by the code example. Never commit it, print it to logs or paste it into a prompt.

Does a timeout mean the request failed?

Not necessarily. YingTu stops waiting after 500 seconds, but the upstream job may still finish and may still be billed. Check your logs before retrying.

Is the reference-image limit set by the model?

No. It is YingTu’s current limit, not the upstream model’s maximum.

Where do I check price and access?

In your LaoZhang account: current price, balance, model access and every charge are listed there.

Price and billing

Billed per image. The price shown is the current LaoZhang rate; actual charges, balance and model access are shown in your LaoZhang account.

Model details
Model ID
gpt-image-2-vip
Price
$0.03/ image
Output sizes
1K / 2K / 4K
Exact output sizes
30 available sizes
Quality levels
low / medium / high
API format
OpenAI Images

Try one in the studio first

Every setting here is available in the YingTu image studio, and new users get $0.1 free.

YingTuLaoZhang