Developer reference

Research API

Ask a defined audience a structured question and receive simulated answer shares in JSON.

Our methodology reports the historical benchmark, its full distribution of errors and its scope.

Overview

API access is configured with your client team. The synchronous endpoint returns one question at a time. Every respondent is simulated; preserve that provenance wherever you show a result.

This endpoint can return 503 while interactive inference is paused. Queued panel-study delivery is a separate workflow.

Discuss API access

Keys and authentication

Keep API keys on your server. Send Authorization: Bearer sk-lew-… and Content-Type: application/json. Workspace access and key issuance are set up with the team. Ask us to revoke a key if it is exposed.

Account-owned keys share respondent usage and request limits. Creating another key does not create another account allowance.

Quickstart

Set LEWSEARCH_API_KEY in your server environment. These examples use the standard HTTP client in each language.

curl https://lewsearch.com/api/v1/cohort/query \
  -H "Authorization: Bearer $LEWSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"question":"Would you switch brands at $4.99?","options":["Definitely","Probably","Probably not","No"],"audience":{"market":"national_us","n":500}}'

Endpoint reference

POST https://lewsearch.com/api/v1/cohort/query

The body is JSON. The endpoint is synchronous, with a server execution budget of 60 seconds. There is no asynchronous job id or polling endpoint in this v1 response.

Request fields

FieldTypeMeaning
questionstring · requiredNonempty research question. Input moderation and question-quality validation also apply.
optionsstring[] · optionalTwo to six nonempty answer options. Blank entries are removed. Omit for the freeform mode, which currently uses an internal Yes/No elicitation and has no numeric validation claim.
audience.marketstring · requiredA registered market id, such as national_us or texas. Missing and unknown ids return 400; no fallback market is selected.
audience.nnumber · optionalDefault 200. Clamped between 20 and the API tier’s maximum. Send a finite whole number.
request_idstring · optionalEchoed in the response and recorded with usage. Reuse does not cache inference or guarantee protection from repeated quota reservations.

Response fields

FieldTypeMeaning
okbooleantrue on a successful response.
request_idstringProvided id or a generated UUID.
mode"mc" | "freeform"Multiple-choice or omitted-options mode.
questionstringThe trimmed submitted question.
summarystringGenerated summary of the answer distribution and panel-support tier.
distributionarrayAnswer shares after the endpoint’s configured calibration steps.
distribution[].optionstringAnswer label.
distribution[].pctnumberPercentage share, on the 0–100 scale.
distribution[].countnumberUnderlying answer count; calibration may change pct without changing count, so count/n need not equal pct.
panel_composition.respondent_origin"synthetic_panel"Every respondent is simulated.
panel_composition.n_realnumberLegacy name for persistent simulated-panel records. These are not human interviews.
panel_composition.n_syntheticnumberOn-the-fly simulated records used to fill the draw.
panel_composition.n_totalnumberTotal simulated records queried.
panel_composition.market_modestringSampling mode: live_panel, pooled_panel or census_weighted. live_panel is a legacy name for stored simulated records.
panel_composition.marketstringResolved market id.
confidence.scorenumberRounded 0–1 panel-support heuristic, described below.
confidence.labelstringHuman-readable panel-support label.
confidence.tier"green" | "amber" | "orange" | "red"Thresholded heuristic; not a probability of accuracy.
usage.respondents_billednumberRespondents with returned answers.
usage.month_usednumberUsage reported from the authentication snapshot plus this call; concurrent requests may make it stale.
usage.month_limitnumberEffective monthly respondent allowance.

The following shortened response uses invented example values. It is not a benchmark result.

{
  "ok": true,
  "request_id": "example-request",
  "mode": "mc",
  "question": "Would you switch brands at $4.99?",
  "summary": "Illustrative summary only.",
  "distribution": [
    {
      "option": "Probably",
      "pct": 38,
      "count": 190
    }
  ],
  "panel_composition": {
    "respondent_origin": "synthetic_panel",
    "n_real": 500,
    "n_synthetic": 0,
    "n_total": 500,
    "market_mode": "pooled_panel",
    "market": "national_us"
  },
  "confidence": {
    "score": 0.8,
    "label": "Higher panel support",
    "tier": "green"
  },
  "usage": {
    "respondents_billed": 500,
    "month_used": 500,
    "month_limit": 50000
  }
}

n_real is a compatibility field for stored simulated records. It never counts human completes. The supplied respondent_origin is the appropriate label for downstream displays.

Errors and retries

Most errors have an ok: false and error body. The interactive pause response is an exception: it has no ok field. Check the HTTP status before reading success fields.

FieldTypeMeaning
400Invalid requestInvalid JSON, missing question, invalid option count, moderation, question-quality or market validation.
401Missing or invalid keyMissing API key, or an invalid or revoked key. Example body below.
403Not currently emittedThis endpoint does not currently return 403. If an upstream access layer returns it, contact the team; no endpoint-specific JSON body is promised.
429Rate or quota limitRequest/minute cap, monthly respondent pool or lifetime demo-call cap. Rate-limit 429 responses do not currently include Retry-After.
500Server configuration/auth errorAuth lookup failed or inference endpoint not configured.
502Inference unavailableerror: lewis_unavailable; the response also includes a message.
503Interactive pause or maintenanceA Retry-After header is supplied. Use it before retrying.
401
{"ok":false,"error":"Invalid or revoked API key."}

429 (example: free API tier)
{"ok":false,"error":"Rate limit reached (10 requests/min on the free plan, across all your keys). Slow down or upgrade."}

500
{"ok":false,"error":"Inference endpoint not configured"}

502
{"ok":false,"error":"lewis_unavailable","message":"Lewis inference is temporarily unavailable. Please try again later."}

503 (interactive pause; Retry-After: 3600)
{"error":"[current pause message]","interactive_unavailable":true,"retry_hint":"Queued study delivery is unaffected."}

For transient 5xx failures, use bounded retries with exponential backoff and jitter; honor Retry-After when present. Do not automatically retry 400 or 401. A repeated request can perform new inference and consume additional quota.

Plan limits

These are the API tier ids enforced by the current v1 handler, not the marketing plan names. Your configured monthly override takes precedence over the default below.

API tierRespondents/queryRequests/minuteDefault monthly respondents
free200101,000
demo10051,000
starter5001550,000
growth1,00030250,000
scale2,5001201,000,000

Demo keys also have a lifetime limit of five recorded calls. Monthly usage resets at 00:00 UTC on the first day of the month. Failed inference releases the reserved account quota; returned answers determine billed respondents.

What the confidence fields measure

The legacy confidence object describes panel support using a heuristic. It is not fitted to held-out question errors, and neither its score nor its color is a probability that an answer is correct.

score = 0.50
  + (multiple choice ? 0.20 : -0.25)
  + (market class = high ? 0.20 : directional ? 0 : -0.10)
  + (persistent-panel fraction - 0.50) × 0.20
  - (returned n < 50 ? 0.15 : 0)
  + (largest answer share > 88% ? 0.05 : 0)

Clamp to [0, 1], round to two decimals, then assign tier.
FieldTypeMeaning
greenscore ≥ 0.80Higher panel support
amber0.60 ≤ score < 0.80Moderate panel support
orange0.40 ≤ score < 0.60Limited panel support
redscore < 0.40Low panel support

The current market registry returns benchmarked, benchmarking or directional, so the legacy high bonus is not reached by registered markets. Both benchmarked and benchmarking currently take the “otherwise” deduction. We preserve this v1 behavior here; it is another reason to read the field as a heuristic rather than an accuracy grade.

The persistent-panel fraction uses n_real / returned n; those records are still simulated. A concentrated answer receives a small score bonus under the legacy formula even though concentration can also reflect model bias. The internal within_moe flag is not used by this API score. See the planned evaluation of predicted error.

Versioning and changelog

The URL carries the v1 version. Preserve unknown response fields when forwarding data, and use named fields rather than array positions. Breaking changes require a versioned interface.

  • October 2026: renamed confidence labels to describe panel support; the score formula and tier thresholds are unchanged.
  • Current reference: account-wide limits, simulated respondent provenance, calibration/count distinction and interactive pause behavior documented.

MCP

MCP access is configured per Enterprise workspace. The tools, permissions, limits and deployment requirements are agreed with your team. This REST endpoint is the public integration reference; no self-serve MCP credentials are issued here.

Enterprise integrations