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

# Polling

> Poll a stable request without duplicating generation work.

The submit response includes a `poll_url`. Send the same API key to that URL:

```bash theme={"system"}
curl --request GET \
  --url 'https://pornfactoryai.com/api/v1/requests/req_YOUR_REQUEST' \
  --header 'Authorization: Bearer pfai_YOUR_KEY'
```

Use exponential backoff with jitter. A practical schedule is 2, 4, 8, 15,
then 30 seconds between requests. Stop when the status is `COMPLETED` or
`FAILED`.

```javascript theme={"system"}
const terminal = new Set(["COMPLETED", "FAILED"]);
let delay = 2_000;

while (true) {
  const response = await fetch(pollUrl, {
    headers: { Authorization: `Bearer ${process.env.PFAI_API_KEY}` },
  });
  const generation = await response.json();

  if (terminal.has(generation.status)) {
    return generation;
  }

  await new Promise((resolve) => setTimeout(resolve, delay));
  delay = Math.min(Math.round(delay * 1.8), 30_000);
}
```

<Note>
  A request is scoped to the API key that created it. Another key cannot poll
  it, even when both keys belong to the same account.
</Note>
