メインコンテンツへ移動

API ガイド

GPT Image 2 VIP API

YingTu が現在使用している API 設定を示します。実際の Key はコードに含まれません。

LaoZhang トークンページを開く

クイックスタート

  1. 1

    LaoZhang API Key を作成または選択します。

  2. 2

    現在のモデル ID と Python 例をコピーします。

  3. 3

    小さなリクエストを一度実行し、応答を確認します。

リクエスト情報

生成エンドポイント
POST /v1/images/generations
編集エンドポイント
POST /v1/images/edits
Base URL
https://api2.laozhang.ai
認証
Bearer API Key
リクエスト種別
OpenAI Images
参照画像
対応
参照画像数
YingTu で最大 5 枚(提供元の上限ではありません)
確認状況
未確認 — 確認できる日付の記録がありません。
API ドキュメントを開く

Python の例

プレースホルダー Key と自分のプロンプトを置き換えます。

テキストから画像の例

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

参照画像編集の例

gpt-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))
本番利用前に LaoZhang アカウントで最新価格、残高、権限を確認してください。

リクエストパラメータ

現在の YingTu クライアントとコード例に一致する項目です。

model
必須。このページの正確なモデル ID を使用します。
prompt
必須。画像指示を送り、API Key は含めません。
出力設定
size はモデルレジストリの正確なサイズから選びます。
quality
任意。このルートで設定済みの品質レベルを使います。
参照画像
任意。YingTu ブラウザでは最大 5 枚を multipart の image として編集エンドポイントへ送信します。

レスポンスとタイムアウト

画像レスポンス
data[0].b64_json(data URL を含む)をデコードするか、data[0].url をダウンロードします。
画像以外のレスポンス
b64_json または url がなければ成功扱いにせず、API メッセージがあれば表示します。

クライアントの 500 秒タイムアウト

500 秒後に YingTu は待機を終了します。この時点では上流結果や請求が不明な場合があります。

自動再試行なし

YingTu は自動で再試行しません。再度の有料呼び出し前にリクエストと請求ログを確認します。

一般的なエラー

認証
環境変数の Key と Bearer 認証ヘッダーを確認します。
権限または残高
LaoZhang でモデル権限、残高、請求、アカウント制限を確認します。
レート制限
並列数を下げ、返された上流またはアカウントのメッセージを確認します。
画像なし
ブロック・終了理由、API メッセージ、response ID を確認します。
タイムアウト
最終状態が不明な場合があります。再試行前に呼び出しと請求ログを確認します。

既知の制約

生成結果を使う前に、次の点を確認してください。

  • ダウンロードしたファイルの実寸を確認します。
  • すべての文字、数字、記号を校正します。
  • 人物・ロゴ・包装・色・細部を使用前に確認します。
  • 利用可否と待ち時間は変動する場合があります。
  • 価格、残高、権限、請求は LaoZhang で確認します。

API FAQ

API Key はどこに保存しますか?

コード例の環境変数を使い、コード、ログ、プロンプトに完全な Key を残しません。

タイムアウトは失敗ですか?

必ずしもそうではありません。500 秒後も結果や請求が不明な場合があるため、ログを確認します。

参照画像数は提供元の上限ですか?

いいえ。モデルレジストリにある現在の YingTu ブラウザ制限です。

価格と権限はどこで確認しますか?

最新の価格、残高、権限、請求は LaoZhang アカウントで確認します。

価格と請求

ページには参考価格を表示します。最新価格、残高、権限、請求は LaoZhang アカウントで確認します。

モデル情報
モデル ID
gpt-image-2-vip
参考価格
$0.03/ 回
出力サイズ
1K / 2K / 4K
正確な出力サイズ
30個の選択可能なサイズ
品質レベル
low / medium / high
API 形式
OpenAI Images

スタジオでこのモデルを試す

以下は画像スタジオで現在利用できる設定です。

YingTuLaoZhang