Skip to content
المشاريع

fujc683/gpt-image-2-6-sdk-python

عرض على GitHub

حول

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

التصميم والوسائط

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
٠
خلال 15 يومًا
٠
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

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.


Related

License

CC BY 4.0

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…