CommunityJoin our DiscordJoin
Examples

Batch Processing

Submit and monitor many generations concurrently

Python example

import time
import requests
from concurrent.futures import ThreadPoolExecutor

API = "https://api.thankyouai.com/open/v1"
HEADERS = {"Authorization": f"Bearer {THANKYOU_API_KEY}"}

def submit_generation(text: str):
    return requests.post(
        f"{API}/generate",
        headers=HEADERS,
        json={
            "model": "google/nano-banana/pro/text-to-image",
            "input": {"prompt": text},
        },
    ).json()

def wait_for_generation(generation):
    while generation["status"] in ("queued", "running"):
        time.sleep(2)
        generation = requests.get(
            f"{API}/generations/{generation['id']}/status",
            headers=HEADERS,
        ).json()
    return requests.get(
        f"{API}/generations/{generation['id']}",
        headers=HEADERS,
    ).json()

prompts = [
    "A sunrise over the mountains",
    "A futuristic city skyline",
    "A photorealistic panda portrait",
]

generations = [submit_generation(text) for text in prompts]
results = list(ThreadPoolExecutor(max_workers=4).map(wait_for_generation, generations))

for result in results:
    print(result["id"], result["status"])

Shell example

for prompt in \
  "A sunrise over the mountains" \
  "A futuristic city skyline" \
  "A photorealistic panda portrait"
do
  curl -X POST https://api.thankyouai.com/open/v1/generate \
    -H "Authorization: Bearer $THANKYOU_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"model\":\"google/nano-banana/pro/text-to-image\",\"input\":{\"prompt\":\"$prompt\"}}"
done

Notes

  • Use GET /open/v1/generations/{id}/status for polling loops.
  • Use GET /open/v1/generations/{id} only when you need the full final object.
  • Add X-Idempotency-Key when batch jobs may be retried by your queueing system.