ZOYKUHot Board

fujc683/gpt-image-2-6-sdk-pythonДокументация

Working Python snippets for GPT Image 2.6: generate, poll, batch.

Языковое уведомление:Перевод на данный язык отсутствует. Отображается официальный английский оригинал.
Быстрая установка
git clone https://github.com/fujc683/gpt-image-2-6-sdk-python.git

GPT Image 2.6

GPT Image 2.6 Python SDK — generate and poll images

Working Python snippets for GPT Image 2.6: single calls, polling, batch with retry.

Awesome License: CC BY 4.0

👉 Try GPT Image 2.6 on APIMart

https://gola.apimart.ai/k-QUaoXJ

💰 Pricing · 🔑 Get an API key


Install

pip install openai

No APIMart-specific SDK is required — the endpoint is OpenAI-compatible.

Generate one image

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.apimart.ai/v1",
                api_key=os.environ["APIMART_API_KEY"])

r = client.images.generate(model="gpt-image-2.6-flare",
                           prompt="minimal product shot of a ceramic mug on oak",
                           n=1)
print(r.data[0].url)

Poll an async task

import time, requests

def wait(task_id, key, timeout=300):
    url = f"https://api.apimart.ai/v1/tasks/{task_id}"
    for _ in range(timeout // 5):
        d = requests.get(url, headers={"Authorization": f"Bearer {key}"}).json()["data"]
        if d["status"] in ("completed", "succeeded"):
            return d["result"]["images"][0]["url"], d.get("cost")
        if d["status"] in ("failed", "error"):
            raise RuntimeError(d.get("error"))
        time.sleep(5)
    raise TimeoutError(task_id)

Batch with retry

from tenacity import retry, wait_exponential, stop_after_attempt

@retry(wait=wait_exponential(min=2, max=30), stop=stop_after_attempt(4))
def generate(prompt):
    return client.images.generate(model="gpt-image-2.6-sunburst",
                                  prompt=prompt, n=1).data[0].url

Cost tracking

data.cost on a finished task is the final charge — log it per request instead of estimating from the price table.


License

CC BY 4.0

Зеркало документации архивировано из официального репозитория GitHub · Перейти на GitHub
Дата снимка: 2026-11-08