# API Overview and Quickstart

> Call iMario from your own code: make a key, price and run a study, then read its results.

Source: https://imario.ai/docs/api

The iMario API does over HTTP what you do in the app: ask an audience a question, build audiences, read results, write reports, and hear about finished work through webhooks. It is the same product, not a copy of it. A study started through the API appears in the workspace, costs what it costs in the app, and is paid from the same credits.

Use the API from your own servers, scheduled jobs and pipelines. To let an AI app such as Claude or ChatGPT ask your audiences, connect the [MCP server](https://imario.ai/docs/agent-setup/mcp) instead; live API keys work there too.

## Base URL and format

```text
https://api.imario.ai/v1
```

Requests and responses are JSON in UTF-8. Only file uploads (`POST /v1/files`) use `multipart/form-data`. Every stored object carries `object` (its type), `id`, `livemode` and `created_at`, an ISO 8601 time in UTC that may carry fractions of a second; a computed answer, such as an estimate, a study's results or the usage, carries `object` and `livemode`. The OpenAPI document for code generators and API clients is at `https://api.imario.ai/v1/openapi.json`.

Long work, such as a study, a report, a download or an audience build, returns its object at once with a `status`. Ask for the object again until the status is final, or let a [webhook](https://imario.ai/docs/api/webhooks) tell you.

## 1. Make a key

1. Open the workspace, then **Settings > MCP & API**.
2. Under **API keys**, select **Create key**.
3. Enter a name. For this walkthrough keep **Personal** and **Live**, and choose **Full access**.
4. Select **Create key**, then copy the key while it is on screen. It is shown once.

Keep the key on your server, in an environment variable or a secret manager, never in a web page or an app people download. [Authentication](https://imario.ai/docs/api/authentication) covers key types, permissions and who pays.

```bash
export IMARIO_API_KEY="imk_..."
```

## 2. Check the key

```bash
curl https://api.imario.ai/v1/workspace \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

```json
{
  "object": "workspace",
  "id": "8d3e0f4a-2b1c-4d5e-9f60-7a8b9c0d1e2f",
  "livemode": true,
  "created_at": "2026-09-02T08:14:55Z",
  "name": "Acme Research",
  "slug": "acme-research",
  "type": "organization",
  "billing_mode": "pooled",
  "api_daily_budget": 2000,
  "key": {
    "id": "5a7e9c1b-3d2f-4e6a-8b0c-1d2e3f4a5b6c",
    "name": "Quickstart",
    "principal": "member",
    "role": "editor",
    "scopes": null,
    "livemode": true
  }
}
```

`key` is the key you called with: whom it acts as, with which role, and its scopes (`null` means full access).

## 3. Pick an audience

```bash
curl "https://api.imario.ai/v1/audiences?scope=all&limit=20" \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

The answer is a [list](https://imario.ai/docs/api/pagination) of the audiences the workspace can see. Take the `id` of one whose `usable` is `true`. A new workspace starts with the population of the markets it picked at sign-up (`scope=market`); `scope=workspace` lists only audiences built in the workspace, and `scope=official` iMario's official audiences, which are bought once. If none is usable, add a market in **Settings > Markets** or build an audience with `POST /v1/audiences`.

## 4. Price the study

An estimate takes the same body as the study itself and costs nothing.

```bash
curl https://api.imario.ai/v1/studies/estimate \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "closed_question",
    "question": "Which name would make you most likely to try this oat drink?",
    "options": ["Morning Oat", "Field Glass", "Plain Oat"],
    "audience_ids": ["AUDIENCE_ID"],
    "respondents": 50
  }'
```

```json
{
  "object": "study_estimate",
  "livemode": true,
  "kind": "closed_question",
  "credits": 50,
  "charged": 0,
  "rule": "1 per respondent",
  "respondents": 50,
  "balance": 8400,
  "sufficient": true,
  "blocked": null,
  "rejected": []
}
```

The answer is shortened here. Check `sufficient` before you run, and read `rejected`: an audience the workspace may not use is listed there with its reason, and the study itself would refuse it rather than drop it. When none of the audiences can be used, the estimate itself is refused (404 `audience_not_found` or 403 `audience_rejected`). API keys may spend up to the workspace's daily limit, 1,000 credits a day for a new workspace: `blocked` names it when a study would pass it, and owners and admins change it under **Daily limit** in **Settings > MCP & API**.

## 5. Run it

Send the same body to `POST /v1/studies`. The `Idempotency-Key` header makes a retry safe: if the connection drops and you send the request again with the same key, you get the first study back instead of a second one. See [Idempotent requests](https://imario.ai/docs/api/idempotency).

```bash
curl https://api.imario.ai/v1/studies \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: oat-names-2026-11-24" \
  -d '{
    "kind": "closed_question",
    "question": "Which name would make you most likely to try this oat drink?",
    "options": ["Morning Oat", "Field Glass", "Plain Oat"],
    "audience_ids": ["AUDIENCE_ID"],
    "respondents": 50
  }'
```

```json
{
  "object": "study",
  "id": "c41d7e2a-9b3f-4a5c-8e6d-0f1a2b3c4d5e",
  "livemode": true,
  "created_at": "2026-11-24T10:02:11Z",
  "kind": "closed_question",
  "status": "queued",
  "question": "Which name would make you most likely to try this oat drink?",
  "audiences": [{ "id": "AUDIENCE_ID", "name": "UK oat milk buyers", "respondents": 50 }],
  "respondents": 50,
  "credits": { "estimated": 50, "charged": 0 },
  "outcome": null,
  "progress": { "answered": 0, "total": 0 },
  "completed_at": null,
  "conversation_id": "7f2e5b1c-0a9d-4c3e-b8f7-6a5d4c3b2a19",
  "web_url": "https://imario.ai/app/acme-research/conv/7f2e5b1c-0a9d-4c3e-b8f7-6a5d4c3b2a19",
  "error": null
}
```

Running a study needs the editor role or above. The price is the one the estimate quoted. The credits are taken in one go when the study starts, on the people actually seated, so the charge can come in below the estimate; a study that fails is refunded. `progress.total` fills in once the people are seated. `web_url` opens the study in the app.

## 6. Wait for it

Ask for the study until `status` is `completed`, `failed` or `canceled`. Every 15 seconds or so is enough: a closed question to 50 people usually takes a few minutes. The first study on a market the workspace has not used before may show `waiting_for_audience` first, while its people are found, and take longer.

```bash
curl https://api.imario.ai/v1/studies/STUDY_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

Read `outcome` before the numbers. `answers` means people answered; `partial_answers` means fewer answered than were asked, so use the real count; `no_answers` means nobody answered, which is not a zero-percent finding. Instead of polling, a webhook endpoint can receive `study.completed` and `study.failed`.

## 7. Read the results

```bash
curl https://api.imario.ai/v1/studies/STUDY_ID/results \
  -H "Authorization: Bearer $IMARIO_API_KEY"
```

```json
{
  "object": "study_results",
  "study_id": "c41d7e2a-9b3f-4a5c-8e6d-0f1a2b3c4d5e",
  "status": "completed",
  "outcome": "answers",
  "results": [
    {
      "object": "study_result",
      "index": 1,
      "kind": "single_choice",
      "n": 50,
      "distribution": [
        { "code": "1", "label": "Morning Oat", "count": 24, "share": 0.4712 },
        { "code": "2", "label": "Field Glass", "count": 9, "share": 0.1834 },
        { "code": "3", "label": "Plain Oat", "count": 17, "share": 0.3454 }
      ],
      "themes": null,
      "summary": "..."
    }
  ]
}
```

The answer is shortened here. `share` is a weighted share from 0 to 1, so it need not equal `count` divided by `n`. Each person's own answer, with their reasons in their own words, is in `GET /v1/studies/{id}/responses`. To write it up, send the study's id to `POST /v1/reports`.

## Try it without spending: test keys

A key made with **Test** as its mode starts with `imk_test_` and runs in the sandbox. It takes the same requests, checks them with the same rules and quotes the same prices as a live key, but never charges a credit, never asks a model and never changes live data. Its studies finish in about 8 seconds with sample answers in the live shape, and it reads the workspace's real audiences, people and Library, so your code can use real ids. [Sandbox and test keys](https://imario.ai/docs/api/sandbox) has the details, including how to make a test study fail on purpose.

## What the API covers

| Group | What you can do |
|---|---|
| [Workspace](https://imario.ai/docs/api/reference/workspace) | Read the workspace, the credit balance, today's API budget and the credit ledger |
| [Audiences](https://imario.ai/docs/api/reference/audiences) and [People](https://imario.ai/docs/api/reference/people) | List audiences, build them from a description, a sub-group or your files, read people and chat with one |
| [Studies](https://imario.ai/docs/api/reference/studies) | Price and run every kind of study, follow it, read results and responses, ask for the AI read of a group |
| [Reports](https://imario.ai/docs/api/reference/reports) | Write a report over studies, download it as PDF, PowerPoint or Markdown, share it by link |
| [Library](https://imario.ai/docs/api/reference/library) and [Files](https://imario.ai/docs/api/reference/files) | Keep surveys, discussion guides and announcements; upload images, videos and data |
| [Auto studies](https://imario.ai/docs/api/reference/auto-studies) | Give iMario a goal and a budget, and read the report it writes |
| [Connections](https://imario.ai/docs/api/reference/connections) | Read connected data sources and start a sync |
| [Members](https://imario.ai/docs/api/reference/members), [API keys](https://imario.ai/docs/api/reference/api-keys), [Webhook endpoints](https://imario.ai/docs/api/reference/webhooks) | Manage the workspace's people, keys and event endpoints |

## Next

- [Authentication](https://imario.ai/docs/api/authentication): key types, scopes, roles and who pays.
- [Sandbox and test keys](https://imario.ai/docs/api/sandbox): build and test without spending.
- [Webhooks](https://imario.ai/docs/api/webhooks): hear when work finishes, and verify each event.
- [API errors](https://imario.ai/docs/api/errors), [Pagination](https://imario.ai/docs/api/pagination), [Idempotent requests](https://imario.ai/docs/api/idempotency), [Rate limits](https://imario.ai/docs/api/rate-limits) and [API versioning](https://imario.ai/docs/api/versioning): the rules every call follows.
- [All endpoints](https://imario.ai/docs/api/reference): each one with its parameters and an example.
