Developers

Quickstart

Make a key, check a study's cost, start it, wait for it and read the results, with curl, Python or JavaScript.

Using an AI agent? One line adds Forepop:

curl -fsSL https://forepop.com/install | sh

Windows, the MCP address and the Claude and ChatGPT apps: Agent install

This walks through one study from a terminal: one question asked of 60 simulated US adults, which spends 60 answers. A new account gets 60 free answers, enough for exactly this. Using an AI agent instead? See Agent install.

Step 1: Make an API key

  1. Sign in at forepop.com and open Settings, API keys (/account/api-keys). Admins and owners of a workspace can make keys.
  2. Name the key after what will use it and press Create key.
  3. Copy it straight away. It starts with fp_live_ and is shown once.

Keep it in an environment variable, never in code you share:

Store the key
export FOREPOP_API_KEY="fp_live_YOUR_KEY"

Step 2: Check your balance

Answers left
curl https://forepop.com/api/v1/balance \
  -H "Authorization: Bearer $FOREPOP_API_KEY"
Reply
{
  "workspace": {
    "id": "…",
    "name": "Personal"
  },
  "balance": {
    "answers_left": 60,
    "pack_answers": 0,
    "monthly_answers": 0,
    "monthly_allowance": 0,
    "monthly_resets_at": null,
    "note": "One answer is one simulated person answering one question. …"
  }
}

Step 3: Check the study and its cost

The estimate runs every check a real study runs and says what it would spend. It starts nothing and spends nothing.

Check the cost
curl https://forepop.com/api/v1/studies/estimate \
  -H "Authorization: Bearer $FOREPOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "survey": {
    "title": "Streaming price change",
    "questions": [
      {
        "type": "single",
        "text": "If your streaming plan went from $12 to $15 a month, what would you do?",
        "options": [
          {
            "label": "Keep my plan"
          },
          {
            "label": "Switch to a cheaper plan"
          },
          {
            "label": "Cancel"
          }
        ]
      }
    ]
  },
  "personas": 60
}'
Reply
{
  "valid": true,
  "answers_needed": 60,
  "answers_left": 60,
  "enough": true,
  "personas": 60,
  "questions_run": 1,
  "questions_skipped": 0,
  "answered_as_group": false,
  "audience": null
}

Step 4: Start the study

Send the same body to POST /api/v1/studies. It answers 201 with the study's id, and the answers are spent now.

Start the study
curl https://forepop.com/api/v1/studies \
  -H "Authorization: Bearer $FOREPOP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "survey": {
    "title": "Streaming price change",
    "questions": [
      {
        "type": "single",
        "text": "If your streaming plan went from $12 to $15 a month, what would you do?",
        "options": [
          {
            "label": "Keep my plan"
          },
          {
            "label": "Switch to a cheaper plan"
          },
          {
            "label": "Cancel"
          }
        ]
      }
    ]
  },
  "personas": 60
}'
Reply
{
  "study": {
    "id": "3f6c2a1e-…",
    "title": "Streaming price change",
    "status": "queued",
    "personas": 60,
    "created_at": "2026-12-01T10:00:00.000Z",
    "finished_at": null
  },
  "answers_spent": 60,
  "answered_as_group": false,
  "hourly_cap": {
    "limit": 60,
    "remaining": 59,
    "resets_at": "2026-12-01T11:00:00.000Z"
  }
}

Step 5: Wait, then read the results

Check the study every few minutes until status is complete. It moves from queued to running to complete (or failed).

Check the study
curl https://forepop.com/api/v1/studies/STUDY_ID \
  -H "Authorization: Bearer $FOREPOP_API_KEY"
Read the results
curl https://forepop.com/api/v1/studies/STUDY_ID/results \
  -H "Authorization: Bearer $FOREPOP_API_KEY"

Each question comes back with a count and a percent for every option (percents once at least 60 answered), and error_points, our measured average error for estimates made that way. The full shape is in the API reference.

The same in Python

Standard library only. Save as forepop_quickstart.py and run python3 forepop_quickstart.py.

Python
import json, os, sys, time, urllib.error, urllib.request

BASE = "https://forepop.com/api/v1"
KEY = os.environ["FOREPOP_API_KEY"]

STUDY = {
  "survey": {
    "title": "Streaming price change",
    "questions": [
      {
        "type": "single",
        "text": "If your streaming plan went from $12 to $15 a month, what would you do?",
        "options": [
          {
            "label": "Keep my plan"
          },
          {
            "label": "Switch to a cheaper plan"
          },
          {
            "label": "Cancel"
          }
        ]
      }
    ]
  },
  "personas": 60
}


def call(method, path, body=None):
    req = urllib.request.Request(
        BASE + path,
        method=method,
        data=None if body is None else json.dumps(body).encode(),
        headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"},
    )
    try:
        with urllib.request.urlopen(req) as res:
            return json.load(res)
    except urllib.error.HTTPError as e:
        err = json.load(e).get("error", {})
        sys.exit(f"{e.code} {err.get('code')}: {err.get('message')}")


est = call("POST", "/studies/estimate", STUDY)
print(f"Needs {est['answers_needed']} answers, {est['answers_left']} left")
if not est["enough"]:
    sys.exit("Not enough answers left. Add more in Settings, Billing.")

study = call("POST", "/studies", STUDY)["study"]
print("Started", study["id"])

while True:
    s = call("GET", "/studies/" + study["id"])["study"]
    if s["status"] == "complete":
        break
    if s["status"] in ("failed", "cancelled"):
        sys.exit("The study " + s["status"])
    time.sleep(180)  # every few minutes at most

results = call("GET", "/studies/" + study["id"] + "/results")
for q in results["questions"]:
    print(q["text"])
    for a in q["answers"]:
        share = f"{a['percent']}%" if a["percent"] is not None else f"{a['count']} people"
        print(f"  {a['label']}: {share}")

The same in JavaScript

Node 18 or later, no packages. Save as forepop-quickstart.mjs and run node forepop-quickstart.mjs.

JavaScript
const BASE = "https://forepop.com/api/v1";
const KEY = process.env.FOREPOP_API_KEY;

const STUDY = {
  "survey": {
    "title": "Streaming price change",
    "questions": [
      {
        "type": "single",
        "text": "If your streaming plan went from $12 to $15 a month, what would you do?",
        "options": [
          {
            "label": "Keep my plan"
          },
          {
            "label": "Switch to a cheaper plan"
          },
          {
            "label": "Cancel"
          }
        ]
      }
    ]
  },
  "personas": 60
};

async function call(method, path, body) {
  const res = await fetch(BASE + path, {
    method,
    headers: { Authorization: "Bearer " + KEY, "Content-Type": "application/json" },
    body: body === undefined ? undefined : JSON.stringify(body),
  });
  const data = await res.json();
  if (!res.ok) throw new Error(res.status + " " + data.error.code + ": " + data.error.message);
  return data;
}

const est = await call("POST", "/studies/estimate", STUDY);
console.log("Needs " + est.answers_needed + " answers, " + est.answers_left + " left");
if (!est.enough) throw new Error("Not enough answers left. Add more in Settings, Billing.");

const { study } = await call("POST", "/studies", STUDY);
console.log("Started " + study.id);

for (;;) {
  const { study: s } = await call("GET", "/studies/" + study.id);
  if (s.status === "complete") break;
  if (s.status === "failed" || s.status === "cancelled") throw new Error("The study " + s.status);
  await new Promise((r) => setTimeout(r, 180_000)); // every few minutes at most
}

const results = await call("GET", "/studies/" + study.id + "/results");
for (const q of results.questions) {
  console.log(q.text);
  for (const a of q.answers) console.log("  " + a.label + ": " + (a.percent !== null ? a.percent + "%" : a.count + " people"));
}

Next

  • API reference: every question type, audiences, real answers to compare with, and errors.
  • MCP server: the same steps as tools an agent can call.