> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Do image APIs return a task ID?

> LaoZhang API image endpoints are synchronous and return no task ID. Set the right timeout and add an async job queue in your own backend.

No. LaoZhang API image generation and editing endpoints are synchronous: the connection stays open and the image comes back in the response when it's ready. There's no task ID and no endpoint to fetch results later. If you need asynchronous behavior, wrap the call in a job queue in your own backend.

| Item | Details |
| - | - |
| Image endpoints | Synchronous, including `/v1/images/generations`, `/v1/images/edits`, and Gemini `generateContent` |
| Video endpoints | Asynchronous tasks with a task ID to poll; see [Wan 2.7](/en/api-capabilities/wan-video-generation) and [Seedance](/en/api-capabilities/seedance2-video-generation) |
| Suggested timeout | 360 s; 600 s for 4K or many reference images |
| After a disconnect | The result is lost, and a finished generation is still billed |

## Why there's no task ID

* Image endpoints keep the same synchronous behavior as the upstream APIs, with no queue in between that would add latency or change behavior.
* LaoZhang API doesn't store prompts or generated images by default, so there's nothing to fetch by ID afterward. See [how LaoZhang API handles data and logs](/en/faq/data-security).
* With a long enough timeout and an open connection, nearly all image requests finish within a single call.

## What to do instead

<Steps>
  <Step title="Set the timeout high enough">
    Give your client and any proxy 360 seconds, or 600 seconds for 4K output or many reference images. See [API request timeouts](/en/faq/request-timeout) for setup and troubleshooting.
  </Step>

  <Step title="Turn off SDK retries">
    An automatic retry after a timeout generates and bills the image again. Set `max_retries` to 0 in the OpenAI SDK and let your code decide when to retry.
  </Step>

  <Step title="Record every job in your backend">
    Give each request your own job ID and store the prompt, parameters, result, or error in your database. If the frontend disconnects, the backend still has the full record.
  </Step>
</Steps>

## Add an async queue in your backend

If your frontend can't wait on a long request, split the flow:

1. The frontend submits a job; the backend saves it and returns a job ID.
2. A backend worker calls LaoZhang API synchronously and writes the result back.
3. The frontend polls your backend with the job ID, or receives the result over a WebSocket.

Here's a minimal version that uses a thread pool from the Python standard library in place of a real job queue. In production, swap in Celery, RQ, or a cloud queue:

```python theme={null}
import base64
import os
import urllib.request
import uuid
from concurrent.futures import ThreadPoolExecutor
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LAOZHANG_API_KEY"],
    base_url="https://api.laozhang.ai/v1",
    timeout=360,
    max_retries=0,
)
executor = ThreadPoolExecutor(max_workers=4)
jobs = {}  # use a database in production


def save_image(item, path):
    if item.b64_json:
        data = item.b64_json.split(",", 1)[-1]  # drop a data: prefix if present
        data += "=" * (-len(data) % 4)  # restore missing padding
        with open(path, "wb") as f:
            f.write(base64.b64decode(data))
    else:
        urllib.request.urlretrieve(item.url, path)  # URLs expire; download right away


def run(job_id, prompt):
    try:
        result = client.images.generate(model="gpt-image-2.5-flare-vip", prompt=prompt)
        path = f"{job_id}.png"
        save_image(result.data[0], path)
        jobs[job_id] = {"status": "done", "file": path}
    except Exception as error:
        jobs[job_id] = {"status": "failed", "error": str(error)}


def submit(prompt):
    job_id = str(uuid.uuid4())
    jobs[job_id] = {"status": "pending"}
    executor.submit(run, job_id, prompt)
    return job_id


def query(job_id):
    return jobs.get(job_id)
```

Install the SDK with `pip install openai` and set `LAOZHANG_API_KEY` first. `save_image` handles both Base64 and URL responses; each model's guide lists the format it returns.

You create and store the job ID; LaoZhang API only handles the synchronous generation step.

## FAQ

### Can I recover an image after my client times out?

No. The result exists only in that response, so it's gone once the connection drops, and the provider still bills the finished generation. Before you retry, check the earlier request's status in [call logs](https://api.laozhang.ai/log).

### Is video generation synchronous too?

No. Video models such as Wan 2.7 and Seedance run as asynchronous tasks: you submit a request, get a task ID, poll its status, and download the result. Each video model's guide has the steps.

### How long do image models take?

It varies a lot: some return in seconds, while 4K, high-quality settings, or many reference images can take minutes, and peak times are slower. If you're unsure, use 360 seconds. Model-specific notes are in [Image generation APIs: models and pricing](/en/api-capabilities/image-generation-guide).

## Related pages

* [API request timeouts](/en/faq/request-timeout)
* [Image generation APIs: models and pricing](/en/api-capabilities/image-generation-guide)
* [Images API: generate and edit images](/en/api-reference/images)
* [How LaoZhang API handles data and logs](/en/faq/data-security)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.