# Live and queued tasks

> The live, standard queue and priority queue modes, the task_post, tasks_ready and task_get flow, pingback and postback callbacks, and how long results are kept.

Most compatible endpoints run in three modes. They return the same data; they differ in when you get it, how fresh a cached copy may be, and price.

| Mode | How you call it | When the result arrives | Google SERP price per 10 results |
|---|---|---|---|
| Standard queue | `POST .../task_post` with `"priority": 1` (the default) | When a worker finishes it | $0.00054 |
| Priority queue | `POST .../task_post` with `"priority": 2` | When a worker finishes it, from our fastest sources | $0.00108 |
| Live | `POST .../live/...` | In the same response | $0.0018 |

Queued tasks run on our workers as soon as one is free; there's no fixed wait. The two queues share workers. Priority tasks use our fastest sources and a 1-hour cache window, where the standard queue prefers the lowest-cost sources and a 6-hour window (see [Caching and max_age](https://dataforgaio.com/docs/caching-and-max-age.md)).

Which modes an endpoint serves:

| Endpoint | Live | Standard and priority queue |
|---|---|---|
| Google organic, Bing organic, Google Maps SERP | Yes | Yes |
| `llm_responses` for `chat_gpt` and `claude` | Yes | Yes (Beta) |
| `llm_responses` for `perplexity` | Yes | No |
| `my_business_info` | Yes | Yes, same price in every mode |
| `instant_pages`, `content_parsing` | Yes | No |
| Products, photos, Meta ads, Yelp ads | Yes (one call per request) | No |

## The queued flow

### 1. Post tasks

```bash
curl -X POST "https://api.dataforgaio.com/v1/serp/google/organic/task_post" \
  -u "api:$DATAFORGAIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[{
    "keyword": "trail running shoes",
    "location_code": 2840,
    "language_code": "en",
    "priority": 1,
    "tag": "rank-check-2026-12-03",
    "postback_url": "https://your-app.example/hooks/serp?id=$id&tag=$tag",
    "postback_data": "advanced"
  }]'
```

Each task comes back at once with an `id`, `status_code` `20100` ("Task Created.") and `cost: 0`. Keep the `id`. A task is billed when it finishes, at the price of the mode it ran in; a task that finds no data costs $0.

| Field | Notes |
|---|---|
| `priority` | `1` standard queue (default) or `2` priority queue. Anything else fails the task with `40501`. |
| `tag` | Your own label, up to 255 characters. Returned in `tasks_ready` and on the task. |
| `pingback_url` | We send a `GET` here when the task finishes. Must be `http` or `https`, up to 2,000 characters. |
| `postback_url` | We `POST` the finished task here, in the `task_get` envelope. Same URL rules. |
| `postback_data` | `regular`, `advanced` (default) or `html`: the result format sent to `postback_url`. |

`$id` and `$tag` anywhere in either URL are replaced with the task id and your tag, URL-encoded.

### 2. Find finished tasks

```bash
curl "https://api.dataforgaio.com/v1/serp/google/organic/tasks_ready" -u "api:$DATAFORGAIO_API_KEY"
```

`tasks_ready` lists up to 1,000 completed tasks for that endpoint that you haven't collected yet, oldest first, with ready-made paths:

```json
{
  "id": "6f1c2a7e-3b0d-4c55-9a51-0e2f8d7b1c44",
  "se": "google",
  "se_type": "organic",
  "date_posted": "2026-12-03 09:00:00 +00:00",
  "tag": "rank-check-2026-12-03",
  "endpoint_regular": "/v1/serp/google/organic/task_get/regular/6f1c2a7e-3b0d-4c55-9a51-0e2f8d7b1c44",
  "endpoint_advanced": "/v1/serp/google/organic/task_get/advanced/6f1c2a7e-3b0d-4c55-9a51-0e2f8d7b1c44",
  "endpoint_html": "/v1/serp/google/organic/task_get/html/6f1c2a7e-3b0d-4c55-9a51-0e2f8d7b1c44"
}
```

`tasks_fixed` returns the same list. Both are free. Failed tasks don't appear here; find them with `task_get` by id or with `POST /v1/account/errors`. If you use callbacks, you can skip this step.

### 3. Get the result

```bash
curl "https://api.dataforgaio.com/v1/serp/google/organic/task_get/advanced/6f1c2a7e-3b0d-4c55-9a51-0e2f8d7b1c44" \
  -u "api:$DATAFORGAIO_API_KEY"
```

`task_get` is free and can be called again for as long as the result is kept. The first successful read marks the task collected, so it drops out of `tasks_ready`.

| Task `status_code` | Meaning |
|---|---|
| `20000` | Finished with data. `result` holds it; `cost` is what it cost. |
| `40602` | Still in the queue. Try again later. |
| `40601` | A worker is running it now. |
| `40102` | Finished with no results. $0. |
| `40401` | No task with that id in your organization. |
| other `4xxxx` / `50000` | Finished with an error. $0. |

Formats: `regular` keeps the core organic fields only, `advanced` is the full item schema. Google Maps serves `advanced` only. `task_get/html` isn't served yet (`40402`). `my_business_info` and `llm_responses` have one format, at `.../task_get/{id}`.

## Callbacks

When a task finishes (with data or with an error), we make one attempt at each callback you set:

- **Pingback:** a `GET` to `pingback_url`.
- **Postback:** a `POST` to `postback_url` with `Content-Type: application/json` and the same envelope `task_get` returns, in the `postback_data` format.

Both carry `User-Agent: DataForGAIO-Webhook/1.0` and `X-DataForGAIO-Task-Id: <task id>`. We time out after 10 seconds, don't follow redirects, and only call hosts that resolve to public IP addresses. A failed delivery isn't retried automatically; re-send it with `POST /v1/account/webhook_resend` and `{"id": "<task id>"}`. Read [Handling webhooks securely](https://dataforgaio.com/docs/webhooks.md) before you build a receiver.

## How long results are kept

- Task results are kept for **30 days** after the task finishes, then cleared. The task record and its `cost` remain.
- Raw HTML results, where an endpoint stores them, are kept for **7 days**.
- Failed tasks from the last **7 days** are listed by `POST /v1/account/errors`.

See [Data retention](https://dataforgaio.com/docs/data-retention.md).

## Live requests

Live routes run each task inline and return results in the response, with the same task envelope. They skip the queue and cost the live price. Live SERP tasks don't read the cache unless you send `max_age`; business and ads routes keep their usual windows. Every task in a live request runs before we respond, so keep live arrays short and set a client timeout of at least 120 seconds.
