# Survey Planner

> Generate a job plan from a natural-language description.

The Survey Planner takes a plain-English description of what you want to measure and returns a fully-formed `POST /jobs` payload plus a cost estimate. Use it to prototype surveys, or to power assistants and copilots that create jobs on a user's behalf.

Every plan the endpoint returns is a [chain](/docs/chains): a top-level `steps` array of one to five questions (with optional `skip_if` rules that screen a respondent out after a step — see [chains](/docs/chains)), plus the `datapoints` to run them against. Submit the returned `plan` verbatim to `POST /jobs`.

The endpoint uses AI to draft a plan, then validates it against the same rules as `POST /jobs` before returning.

## Plan a survey

<EndpointHeader method="POST" path="/surveys/plan" />

### Request body

<ParamTable
  params={[
    { name: "description", type: "string", required: true, description: "Natural-language description of the survey (10–5000 chars). Include the dp:// or https URLs of any media inline; the planner threads them into the datapoints." },
    { name: "preferences", type: "object", description: "Optional hints for the planner." },
    { name: "preferences.task_type", type: "string", description: "Preferred task type passed to the planner as a hint (e.g. comparison, rating, ranking, multiple_choice). Treated as a suggestion, not a hard constraint; if omitted, the planner picks the best fit." },
    { name: "preferences.max_responses", type: "integer (1–10000)", description: "Advisory hint for the target responses per datapoint (default 10). It is passed to the planner only when it differs from the default, and the planner writes the final max_responses_per_datapoint into the returned plan — the value may not match your hint exactly. To force an exact count, edit max_responses_per_datapoint in the returned plan before submitting it to POST /jobs." }
  ]}
/>

### Response (`200 OK`)

```json
{
  "plan": {
    "name": "logo-preference-v1-a2f8",
    "max_responses_per_datapoint": 10,
    "steps": [
      {
        "task_type": "comparison",
        "instruction": "Which logo looks more professional?"
      }
    ],
    "datapoints": [
      {
        "media": {
          "candidates": [
            { "url": "dp://1fae39d2c7b5/logo_a.svg", "type": "image" },
            { "url": "dp://84b1f6ea3d02/logo_b.svg", "type": "image" }
          ]
        }
      }
    ]
  },
  "summary": "Compares two logo designs on perceived professionalism using 10 annotator responses.",
  "estimated_cost_credits": 50,
  "pricing": {
    "base_credits_per_response": 5,
    "demographic_surcharge_credits": 0,
    "geo_surcharge_credits": 0,
    "credits_per_response": 5
  },
  "warnings": []
}
```

<ParamTable
  params={[
    { name: "plan", type: "object", description: "A ready-to-submit POST /jobs payload (runs through the same field-level and handler validation the jobs endpoint uses before being returned). Submit verbatim." },
    { name: "summary", type: "string", description: "Planner-produced 1–3 sentence explanation of what the plan will measure." },
    { name: "estimated_cost_credits", type: "int", description: "The maximum credits this plan can cost. Only fully completed responses bill — walks screened out by a skip_if rule or abandoned mid-chain are never billed, and unused credits are released when the job settles." },
    { name: "pricing", type: "object", description: "Per-response rate breakdown behind the estimate: base_credits_per_response, demographic_surcharge_credits, geo_surcharge_credits, and the effective credits_per_response. See [targeting surcharges](/docs/billing#targeting-surcharges)." },
    { name: "warnings", type: "array of strings", description: "Non-blocking notes about the plan — planner caveats such as missing labels or ambiguous instructions, plus any notice that the plan was adjusted before being returned. Read them before submitting, and check the returned `steps` against what you asked for. Empty array if none." }
  ]}
/>

### Example

```bash
curl -X POST https://api.trydatapoint.com/data-labelling/v1/surveys/plan \
  -H "X-API-Key: $DATAPOINT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Compare logo A (dp://1fae39d2c7b5/logo_a.svg) and logo B (dp://84b1f6ea3d02/logo_b.svg). Which looks more professional?",
    "preferences": { "task_type": "comparison" }
  }'
```

After reviewing the plan, submit it verbatim:

```bash
curl -X POST https://api.trydatapoint.com/data-labelling/v1/jobs \
  -H "X-API-Key: $DATAPOINT_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq .plan plan_response.json)"
```

### Error cases

| Status | Cause |
|---|---|
| `400` | The `description` references `dp://` media that doesn't exist or doesn't belong to your account. `detail` is an object `{message, warnings}`. |
| `402` | Insufficient balance to cover the planner fee. `detail` is an object `{message, needed_credits, available_credits}`. Top up via [`POST /billing/checkout`](/docs/billing) and retry. |
| `422` | Request body failed validation (e.g. `description` outside 10–5000 chars). `detail` is an array of field errors. |
| `422` | The planner produced an invalid plan — for example it referenced `dp://` media that doesn't resolve or isn't yours, or a step whose configuration the task-type validator rejects. `detail` is an object `{message, warnings: [...]}`. |
| `502` | The planner failed to produce a plan. |
| `503` | Planner unavailable. |
| `504` | Planner timed out. Retry. |

<DocCallout type="warning" title="Planning charges a small per-call fee">
A successful call to `/surveys/plan` costs a small flat fee. [Contact us](mailto:sales@trydatapoint.com) for current planning pricing. Failed calls (402, 422, 502, 503, 504) are not charged. Calls that succeed but whose response never reaches the caller (network drop after deduct) may still have been charged; retrying the request will charge again until idempotency-key support ships.

The planner doesn't upload media or queue tasks. You still take the returned `plan` object and pass it to `POST /jobs` when you're ready to run the survey.
</DocCallout>

## Next

- [Jobs](/docs/api/jobs): the endpoint you'll submit the plan to
- [Task types](/docs/task-types): understanding what the planner produced
