# Sync tasks

> Run a prompt and get the AI answer, its sources and the brand analysis back in a single HTTP call that stays open for up to 290 seconds.

`POST /v1/sync/task` takes the same body as [`POST /v1/tasks`](https://promptgale.com/docs/tasks.md) and waits for the result inside the request.

## When to use it

- Use sync for one prompt at a time, in a script or an interactive tool.
- Use [async tasks](https://promptgale.com/docs/tasks.md) or [batches](https://promptgale.com/docs/batches.md) for many prompts, or for anything in a job queue.

## Request

```bash
curl -X POST https://promptgale.com/v1/sync/task \
  -H "Authorization: Bearer $PROMPTGALE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Prefer: wait=120" \
  -d '{"taskType":"CHATGPT","payload":{"prompt":"best crm for agencies","country":"US"}}'
```

## Responses

| Status | Meaning | What to do |
| --- | --- | --- |
| `200` | The task finished: `COMPLETED` or `FAILED`. | Read `data.result` or `data.error`. |
| `202` | Still running when the wait ended. | Poll the URL in `Location` (`GET /v1/tasks/{id}`). |

## How long it waits

- By default, up to 290 seconds.
- `Prefer: wait=N` sets a shorter wait in seconds. The response confirms it in `Preference-Applied`.
- Set your HTTP client's timeout above the wait, for example 300 seconds.

A task that outlives the wait is not lost and is not charged twice: it keeps running, and you read it with the same id.

---

Docs index: https://promptgale.com/llms.txt · Full reference: https://promptgale.com/llms-full.txt · OpenAPI: https://promptgale.com/v1/openapi.json
