- 실패하거나 시간 초과된 요청은 차감되지 않습니다. 요청의 일부 이미지만 성공하면 성공한 이미지만 차감됩니다.
- 재시도할 때
Idempotency-Key 헤더를 보내세요. 같은 키의 요청은 두 번 실행되거나 두 번 차감되지 않습니다. - 429를 받으면 기다렸다가 다시 시도하되, 매번 대기 시간을 두 배로 늘리세요.
response_format: "url"로 링크를 요청하세요. 링크는 72시간 동안 유효하므로 파일은 자체 저장소에 복사해 두세요.
import asyncio
from openai import AsyncOpenAI, RateLimitError
client = AsyncOpenAI(base_url="https://api.cheapestimagen.com/v1", api_key="YOUR_KEY")
gate = asyncio.Semaphore(50) # the account limit on requests in progress
async def make(prompt: str, key: str):
async with gate:
for attempt in range(5):
try:
r = await client.images.generate(
model="nano-banana-2.1", prompt=prompt, size="1024x1024", response_format="url",
extra_headers={"Idempotency-Key": key}, # a retry never charges twice
)
return r.data[0].url
except RateLimitError:
await asyncio.sleep(2 ** attempt)
async def main(prompts):
return await asyncio.gather(*(make(p, f"job-{i}") for i, p in enumerate(prompts)))
제한 사항은 사용 제한과 대량 생성에, 모든 오류 코드는 오류 가이드에 정리되어 있습니다. n8n에서 실행하려면 n8n에서 사용하기를 보세요.