# API reference

> The REST endpoints under /api/v1: the survey format, starting and reading studies, results, limits and errors.

Base address: `https://forepop.com/api/v1`. JSON in, JSON out. Every request needs `Authorization: Bearer fp_live_YOUR_KEY` (see [Authentication](https://forepop.com/developers/authentication)). Every query is scoped to the key's workspace.

| Method | Path | What it does |
| --- | --- | --- |
| `GET` | `/balance` | The key's workspace and its answers left. |
| `POST` | `/studies/estimate` | Check a study and say what it would spend. Starts nothing. |
| `POST` | `/studies` | Start a study. Spends answers. 201. |
| `GET` | `/studies` | Recent studies, newest first. `?limit=` 1 to 50, default 20. |
| `GET` | `/studies/{id}` | A study's status and progress. |
| `GET` | `/studies/{id}/results` | A complete study's results, or 409 with its status. |

## The study body

`POST /studies` and `POST /studies/estimate` take the same body: a survey and how many simulated people answer it. Unknown fields are refused.

| Field | Type | Notes |
| --- | --- | --- |
| `survey.title` | string | Required, 1 to 200 characters. |
| `survey.questions` | array | Required, 1 to 200 questions. See below. |
| `survey.audience` | object | Optional. Leave it out for all US adults 18+. See [Audience](#audience). |
| `survey.calibration` | object | Optional real answers to compare with, or an earlier wave. See [Real answers](#real-answers). |
| `survey.writtenAnswers` | boolean | Optional. Also write short answers in people's own words for `single`, `rating`, `nps`, `slider`, `concept_test` questions. |
| `personas` | integer | 1 to 100000, default 1000. How many simulated people answer. |

### Questions

| Field | Type | Notes |
| --- | --- | --- |
| `type` | string | Required. One of the types below. |
| `text` | string | The question as people read it, up to 1000 characters. Required for every type but `content`. |
| `options` | array of `{label, id?, image?}` | Up to 100. Labels up to 500 characters. |
| `rows` | array of `{label, id?}` | Matrix statements only. |
| `scale` | `{min?, max?, minLabel?, maxLabel?}` | Whole numbers. Each type has a default. |
| `id` | string | Optional; letters, digits, `-` or `_`. Needed only when skip logic points at the question. |
| `required` | boolean | Default true (false for `content`). |
| `shuffle` | boolean | Shuffle the options for each person. Default true for `single` and `multiple`. |
| `visibility` | object | Who sees it: `{"mode": "everyone"}` (default), or `{"mode": "skip", "questionId", "optionId"}` to show it only to people who picked that option on an earlier question. |
| `image` | string | For `concept_test` and `content`: a `data:image/png`, `jpeg`, `webp` or `gif` base64 URL. Links to elsewhere are refused. |

| Type | Name | Needs |
| --- | --- | --- |
| `single` | Single choice | 2 or more `options`. One answer each. |
| `multiple` | Multiple choice | 2 or more `options`. Any number of answers each. |
| `image_choice` | Image choice | 2 or more `options`, each with an `image`. |
| `ranking` | Ranking | 2 or more `options` to put in order. |
| `rating` | Rating scale | `scale` (default 1 to 5). |
| `nps` | NPS 0 to 10 | Nothing else; the scale is 0 to 10. |
| `slider` | Slider | `scale` (default 0 to 100). |
| `price_ladder` | Price ladder | 2 or more `options`, each a price. |
| `price_sensitivity` | Price sensitivity | `scale` (default 0 to 100). |
| `best_worst` | Best-worst | 3 or more `options`. |
| `concept_test` | Concept test | An `image` of the concept, and `scale` (default 1 to 5). |
| `matrix` | Matrix grid | 2 or more `options` (the columns) and `rows` (the statements). |
| `open_text` | Open text | Nothing else. Answers come back as written text. |
| `content` | Picture or text block | Text or an `image` that is shown, not asked. Costs nothing. |

Option and row ids are made for you when you leave them out. A survey that fails a check answers 422 with every problem found in `issues`; the checks are the studio's own "Before you run" list.

```json
{
  "survey": {
    "title": "Meal kit concept",
    "questions": [
      {
        "id": "tried",
        "type": "single",
        "text": "Have you ordered a meal kit in the last 12 months?",
        "options": [
          {
            "id": "yes",
            "label": "Yes"
          },
          {
            "id": "no",
            "label": "No"
          }
        ]
      },
      {
        "type": "multiple",
        "text": "Why did you stop or never start?",
        "options": [
          {
            "label": "Too expensive"
          },
          {
            "label": "Too much packaging"
          },
          {
            "label": "Not enough choice"
          },
          {
            "label": "I like to shop myself"
          }
        ],
        "visibility": {
          "mode": "skip",
          "questionId": "tried",
          "optionId": "no"
        }
      },
      {
        "type": "rating",
        "text": "How appealing is a meal kit that costs $8 a serving?",
        "scale": {
          "min": 1,
          "max": 5,
          "minLabel": "Not appealing",
          "maxLabel": "Very appealing"
        }
      },
      {
        "type": "nps",
        "text": "How likely are you to recommend a meal kit to a friend?"
      },
      {
        "type": "matrix",
        "text": "How much do you agree with each statement?",
        "options": [
          {
            "label": "Disagree"
          },
          {
            "label": "Neutral"
          },
          {
            "label": "Agree"
          }
        ],
        "rows": [
          {
            "label": "Cooking at home saves money"
          },
          {
            "label": "I don't have time to plan meals"
          }
        ]
      }
    ]
  },
  "personas": 500
}
```

## Audience

Every study runs for all US adults 18+, and `survey.audience` can be left out. Other ways of narrowing (another country, an age range, a written description) are refused before anything is spent, with a 422 that says so.

To answer as a narrower group, send `audience.filter` with one or more of age, gender, income and education, and `groupAnswers: true`. Values in one list are OR; lists are AND.

```json
"audience": {
  "filter": {
    "age": [
      "18-34"
    ],
    "gender": [
      "female"
    ]
  },
  "groupAnswers": true
}
```

| Filter | Values |
| --- | --- |
| `age` | `18-34`, `35-44`, `45-54`, `55-64`, `65-74`, `75+` |
| `gender` | `female`, `male` |
| `income` | `<$25k`, `$25-50k`, `$50-100k`, `$100k+` |
| `education` | `no diploma`, `high school`, `some college`, `bachelor's`, `master's+` |

## Real answers to compare with

If you already fielded the same survey, send its real answers in `survey.calibration` and the results show each estimate next to the real share, with the gap in points. They are sealed away from the model until the study finishes, so the comparison is blind. With `earlier: true` they are an earlier wave instead, and lead the results for the questions they cover.

```json
{
  "calibration": {
    "filename": "wave-1.csv",
    "respondents": 1012,
    "answers": {
      "QUESTION_ID": {
        "OPTION_ID": 412,
        "OTHER_OPTION_ID": 600
      }
    },
    "earlier": false,
    "fielded": "Oct 2 to Oct 16, 2026"
  }
}
```

- `answers` is keyed by question id, then by answer: the option id for choice questions, or the scale value as a string (`"7"`) when the scale spans 10 or less (NPS included). Wider scales use five bands, such as `"0-20"`. Counts are whole numbers.
- Give your questions and options ids so the keys match.
- `fielded` is optional, up to 60 characters, in your own words.

## Check the cost

`POST /studies/estimate` runs the same checks as starting a study and says what it would spend.

| Field | Meaning |
| --- | --- |
| `valid` | Always true in a 200; problems come back as a 422. |
| `answers_needed` | What the study would spend: people × questions asked (`content` blocks are free). |
| `answers_left` | The workspace's balance now. |
| `enough` | Whether the balance covers it. |
| `personas`, `questions_run`, `questions_skipped` | The study as it would run. |
| `answered_as_group` | Whether it would be answered as the filter's group. |
| `audience` | The audience as it would be stored. |

## Start a study

`POST /studies` answers 201 with `study` (id, title, status, personas, created_at, finished_at), `answers_spent`, `answered_as_group` and `hourly_cap` ({limit, remaining, resets_at}). The answers are spent when the study starts. A study the engine can't run in the end gives its answers back. Most surveys come back within minutes.

```bash
curl https://forepop.com/api/v1/studies \
  -H "Authorization: Bearer fp_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d @study.json
```

## List and check studies

```bash
curl "https://forepop.com/api/v1/studies?limit=10" \
  -H "Authorization: Bearer fp_live_YOUR_KEY"
```

```bash
curl https://forepop.com/api/v1/studies/STUDY_ID \
  -H "Authorization: Bearer fp_live_YOUR_KEY"
```

A study's `status` is `queued`, `running`, `complete`, `failed` or `cancelled`. While it runs, `progress` holds:

```json
{
  "answered": 420,
  "target": 1000,
  "percent": 42,
  "questions_done": 2,
  "questions_total": 5,
  "started_at": "2026-12-01T10:02:00.000Z",
  "finished_at": null,
  "message": null
}
```

Check every few minutes at most.

## Results

`GET /studies/{id}/results` returns the numbers behind the studio's results page. Until the study is complete it answers 409 `not_ready` with its `status`.

```json
{
  "study": {
    "id": "3f6c2a1e-…",
    "title": "Streaming price change",
    "status": "complete",
    "personas": 60,
    "created_at": "…",
    "finished_at": "…"
  },
  "audience": null,
  "calibrated": false,
  "notes": {
    "percent_min_answered": 60,
    "simulated": "Every number is a model estimate. …",
    "error_points": "± is our average error. …"
  },
  "message": null,
  "questions": [
    {
      "id": "q1",
      "type": "single",
      "text": "If your streaming plan went from $12 to $15 a month, what would you do?",
      "answered": 60,
      "shows_percent": true,
      "mean_gap_points": null,
      "error_points": 6,
      "skipped": null,
      "real": null,
      "answers": [
        {
          "id": "q1_o_1",
          "label": "Keep my plan",
          "count": 31,
          "percent": 51.7,
          "real": null,
          "gap_points": null
        },
        "…"
      ]
    }
  ],
  "respondents": [
    {
      "persona": "…",
      "answers": {
        "q1": "Keep my plan"
      }
    }
  ]
}
```

> The numbers above only show the shape; they are not a result.

| Field | Meaning |
| --- | --- |
| `questions[].answers[]` | Each option: `count`, `percent` (null under the minimum), and with real answers `real` and `gap_points`. |
| `shows_percent` | Percents appear once at least 60 answered; below that, counts only. |
| `error_points` | Our average error in points for estimates made this way, measured against real survey results. An average, not a guarantee. |
| `interval_points` | When present, the spread of the estimate across different wordings of the question. It understates the error against real answers. |
| `skipped` | A reason, when the engine couldn't estimate the question faithfully. It then has no answers. |
| `written` | For `open_text`: `{persona, text}` for each written answer. |
| `respondents` | Each simulated person: a short persona and their answer to each question, by question id. |
| `notes` | Plain-language notes on reading the numbers. Pass them on with the results. |

## Limits

- Each key can start 60 studies an hour. The count resets at the top of each hour (UTC).
- A workspace can have 10 studies waiting or running at once. Past that, a new start gets `queue_full` until one finishes.
- None of these limit how many answers a study has: that is up to your balance.
- Each key can send 30 requests per 60 seconds, across the REST API and the MCP server.
- Each address can send 120 requests a minute.
- A request body can be up to 6 MB, pictures included.
- Over a limit, the answer is 429 with a `Retry-After` header in seconds.

## Errors

Every error has the same shape, with a message written to be shown to a person:

```json
{
  "error": {
    "code": "invalid_request",
    "message": "survey.questions[0].options: …",
    "issues": [
      "survey.questions[0].options: …"
    ]
  }
}
```

| Status | Code | When | Extra fields |
| --- | --- | --- | --- |
| 401 | `unauthorized` | No key, a malformed key, or a revoked one. |  |
| 402 | `insufficient_credits` | Fewer answers left than the study needs. | `answers_needed` |
| 403 | `forbidden` | The key's maker is no longer in its workspace. |  |
| 404 | `not_found` | No study with that id in the key's workspace. |  |
| 409 | `not_ready` | Results asked for before the study is complete. | `status` |
| 413 | `payload_too_large` | The body is over the size limit. |  |
| 422 | `invalid_request` | The study didn't pass the checks, or `limit` is out of range. | `issues` |
| 429 | `rate_limited`, `hourly_cap_reached`, `queue_full` | Over a limit. | `Retry-After` header |
| 503 | `unavailable` | Something went wrong on our side. Try again in a moment. |  |
