Skip to content
Projetos

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

Ver no GitHub

Sobre

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

Design e mídia

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
0
em 15 dias
0
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

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

Explore projetos relacionados

Carregando…