# REST API quickstart

The credentialed sandbox answers authenticated REST calls with your per-company workspace key (`Authorization: Bearer $PRECISE_SANDBOX_KEY`): query the sample book, run a method or a workflow, size a test, and reopen any run by its id. The unified Access server serves decisions, deals, spend plans and proofs to both API clients and the Precise app.

| Capability | Runtime | Status |
|---|---|---|
| Query the public synthetic buying book over REST | Sandbox | Live |
| Discover the deployment-specific operation catalog and change stream on configured public-test Access | Sandbox | Preview |

Every figure on this page comes from sample data.

## Part one: the sandbox

The base address is `https://sandbox.precise.ai`. Requests and answers are JSON. An error is `{"error": "...", "code": "..."}` with an HTTP status.

### Check the service and read the catalog

```sh try
curl -s https://sandbox.precise.ai/health
```

`GET /api/catalog` lists what the Gateway serves: 64 methods and 5 workflows. Add `?name=power/holdout` for one method's input and output schema.

```sh try
curl -s https://sandbox.precise.ai/api/catalog
```

`GET /api/guide` says what the tables, measures, methods and workflows mean, under one digest that every figure names. Add `?section=` for one part. This one returns the two kinds of holdout.

```sh try
curl -s "https://sandbox.precise.ai/api/guide?section=holdouts"
```

### Query the book

`POST /api/sql/run` takes one read-only `SELECT`. This one returns three rows, measured on the sample book, led by online video at $9,262,672.56 of media spend. The answer carries a `run_id` and a `result_digest`.

```sql try
SELECT format, ROUND(SUM(media_spend_usd), 2) AS media_spend_usd, SUM(impressions) AS impressions FROM gold_daily_cube GROUP BY format ORDER BY media_spend_usd DESC
```

| Rule | Detail |
|-|-|
| One statement | A single read-only `SELECT`, or `WITH ... SELECT`, over the pinned catalog's tables |
| Your own rows | Sent through `run_analysis` in a workspace. A `VALUES` list in a query is refused |
| Personal data | A query that names a personal-data field such as `email`, `ip_address` or `user_id` is refused |
| Size | At most 20,000 characters |
| `max_rows` | 1 to 200. A longer result sets `truncated` and reports `total_rows` |
| `timeout_ms` | 100 to 120,000. A query still running answers 504 `query_pending` with its `run_id` |

A structured join goes to the same route as `join_spec`. This one counts line items by format: 72, 36 and 60.

```sh try
curl -s -X POST https://sandbox.precise.ai/api/sql/run -H 'content-type: application/json' -d '{"join_spec": {"kind": "relational", "left": "orders", "right": "line_items", "on": [["order_id", "order_id"]], "group_by": ["r.format"], "aggregates": [{"op": "count", "column": "r.line_item_id", "as": "line_items"}]}}'
```

### Read orders and the track record

`GET /api/campaigns` lists the book's 84 orders, 25 at a time. It takes `query`, `format`, `campaign_id`, `holdout`, `limit` and `offset`. Twelve orders are CTV.

```sh try
curl -s "https://sandbox.precise.ai/api/campaigns?format=ctv&limit=3"
```

`GET /api/campaigns/ORD-012` returns one order in full: its line items, delivery, auction sample, outcomes and invoices.

`GET /api/calls` lists the Decisions on record with their scores. On the sample book 31 are scored, 27 landed inside their range, 4 landed outside, 4 are open and 1 had no measurable outcome. It takes `status`, `order_id`, `campaign_id` and `limit`.

```sh try
curl -s "https://sandbox.precise.ai/api/calls?limit=3"
```

### Size a test, run a method, run a workflow

`POST /api/holdout/size` sizes an Audience Holdout from an order's own test. For `ORD-067` the verdict is `underpowered`: 48 units per arm can detect a lift of 13.8 percentage points, and the target of 0.40 points needs 57,487 units per arm.

```sh try
curl -s -X POST https://sandbox.precise.ai/api/holdout/size -H 'content-type: application/json' -d '{"order_id": "ORD-067"}'
```

`POST /api/gateway/run` runs one Gateway method on an order of the book. This check reads `ORD-012`'s holdout: 4,516,160 units assigned to treatment and 4,523,200 held back, with a verdict of `clean`.

```sh try
curl -s -X POST https://sandbox.precise.ai/api/gateway/run -H 'content-type: application/json' -d '{"method": "comparison/holdout-integrity", "order_id": "ORD-012"}'
```

`POST /api/workflow/run` runs one workflow. `design-the-test` runs five steps, each with its own `run_id`, and says which steps read the order you named.

```sh try
curl -s -X POST https://sandbox.precise.ai/api/workflow/run -H 'content-type: application/json' -d '{"workflow": "design-the-test", "order_id": "ORD-012"}'
```

Your own aggregated input to a method or a workflow needs a workspace key.

### Reopen a run

`GET /api/runs/{run_id}` reopens a verified run: its method, its output and its digests. Read the ID from your own successful answer. A different instance may return 404 for an earlier run. Repeat the query on that instance and use its returned ID. The query evaluator normalizes outer whitespace; the stored input and result digest identify this computation.

```sh
set -e
base=https://sandbox.precise.ai
run_id=$(curl -fsS "$base/api/sql/run" -H 'content-type: application/json' -d '{"sql":"SELECT COUNT(*) AS orders FROM orders"}' | jq -er '.run_id')
curl -fsS "$base/api/runs/$run_id"
```

### Two errors a first caller meets

| Status and code | Meaning | What to do |
|-|-|-|
| 422 `query_failed` | The query is not a single read-only `SELECT`, or it names a table, a column or a function the catalog does not have | Fix the SQL. The message quotes the engine |
| 429 `query_busy` | Queries take turns: one running and two waiting for each caller | Wait the number of seconds in the `Retry-After` header, repeated in the body as `retry_after_seconds`, then send it again |

The limits and the error codes are in [Limits and errors](../../reference/limits-and-errors.md).

## Part two: the Precise app API

Set `PRECISE_URL` to the Access origin. A local public-test deployment normally listens on `http://127.0.0.1:8787`. Its `/openapi.json` and `/api/v1/operations` describe the enabled profile. The [downloadable OpenAPI document](../../app/data/app-openapi.json) captures the public-test server with the optional native ratio worker. Set the `accessOrigin` server variable to your deployment when generating a client.

| Deployment | Caller scope and headers |
|-|-|
| Credentialed sandbox | Every data, SQL, MCP, and write call requires a per-company bearer workspace key (`penv_...`). Discovery metadata, `/health`, and `/docs` stay public. |
| Unified public test | Each published operation uses the server's public tenant. `Precise-Workspace` is unnecessary and cannot grant a tenant or select a different principal. |
| Tenant read or spend capable | The bearer credential establishes the authenticated principal. The deployment exposes only operations that its profile and grants permit. Approval routes bind the tenant and frozen action. |

The docs relay preserves an explicitly supplied `Precise-Workspace` for older hosts that require it. A host that enforces this header on a route must mark it required in that host's schema. Import the OpenAPI served by the profile you will call. The public-test catalog below has 34 tools. Without the native ratio worker it has 33.

| HTTP operation | MCP tool |
|-|-|
| `GET /api/v1/overview` | `get_overview` |
| `GET /api/v1/decisions` | `list_decisions` |
| `GET /api/v1/decisions/{decision_id}` | `get_decision` |
| `GET /api/v1/scorekeeper` | `get_scorekeeper` |
| `GET /api/v1/scorekeeper/money-map` | `get_money_map` |
| `GET /api/v1/scorekeeper/deals` | `list_deals` |
| `GET /api/v1/authority` | `get_authority` |
| `GET /api/v1/holdouts/{order_id}/sizing` | `size_holdout` |
| `GET /api/v1/governance/plan` | `get_spend_plan` |
| `GET /api/v1/connections` | `list_connections` |
| `GET /api/v1/clouds/{cloud}/probe` | `see_what_precise_can_read` |
| `GET /api/v1/cleanroom/partners` | `list_partner_tables` |
| `POST /api/v1/cleanroom/preflight` | `check_match_formats` |
| `POST /api/v1/cleanroom/run` | `run_partner_match` |
| `GET /api/v1/checks/sql` | `list_sql_checks` |
| `GET /api/v1/checks/sql/{check_id}` | `get_sql_check` |
| `GET /api/v1/activation/targets` | `list_platform_targets` |
| `POST /api/v1/execution/simulate` | `trace_auction` |
| `GET /api/v1/proofs` | `list_proof_files` |
| `GET /api/v1/proofs/{proof_id}` | `get_proof_file` |
| `POST /api/v1/proof/verify` | `verify_proof_file` |
| `POST /api/v1/ask` | `ask` |
| `GET /api/v1/runtime` | `get_runtime` |
| `GET /api/v1/operations` | `list_operations` |
| `GET /api/v1/connections/public-book` | `connect_public_book` |
| `GET /api/v1/pins/{pin}` | `inspect_snapshot` |
| `POST /api/v1/query` | `query_pinned_book` |
| `GET /api/v1/runs/{run_id}` | `open_run_rows` |
| `POST /api/v1/size` | `size_pinned_holdout` |
| `POST /api/v1/tools/get_guide` | `get_guide` |
| `POST /api/v1/tools/get_figures` | `get_figures` |
| `POST /api/v1/tools/inspect_audit` | `inspect_audit` |
| `POST /api/v1/tools/get_changes` | `get_changes` |
| `POST /api/v1/tools/ratio_shapley` | `ratio_shapley` |

### Home in one call

September sample, with the headline and reconciliation fields selected from the response.

```sh preview
curl -s "$PRECISE_URL/api/v1/overview"
```

```json answer
{
  "headline": {
    "label": "Proven so far (Sep 2026)",
    "value": 59997,
    "unit": "usd",
    "basis": "Net result of 5 tested changes that closed in September 2026, each against its BAU line. 1 overlapping result is left out, so no day on one line item counts twice."
  },
  "reconciliation": {
    "decision_ids": [
      "D-014",
      "D-021",
      "D-024",
      "D-032",
      "D-033"
    ],
    "total_usd": 59997
  }
}
```

### One decision in four rows

This excerpt shows what changes, the expectation, the comparison and the costs. The full response includes the recorded routes and the exposure.

```sh preview
curl -s "$PRECISE_URL/api/v1/decisions/D-035"
```

```json answer
{
  "decision_id": "D-035",
  "state": "Approval required",
  "rows": {
    "changes": {
      "sentence": "Shade open-exchange bids to each impression's value.",
      "where": "ORD-006, line LI-006-A in Beeswax"
    },
    "expect": {
      "sentence": "$26,947, with an 80% range of $22,127 to $31,767."
    },
    "compared_with": {
      "sentence": "Your BAU line keeps running beside the test. The result is one against the other.",
      "held_line": "LI-006-A (BAU Control Line)",
      "risk_budget_pct": 2,
      "how_it_works": "Two live line items swap setups on a random schedule."
    },
    "costs": {
      "sentence": "Every route shows its fees in one table, Precise's included."
    }
  },
  "applied": {
    "state": "none",
    "sentence": "Approval required",
    "counted_usd": 0
  }
}
```

### The list of operations

Open the registry on the deployment you will use. The excerpt selects fields from its first entry. Each returned operation supplies its HTTP method, path, MCP tool and example snippets.

```sh preview
curl -s "$PRECISE_URL/api/v1/operations"
```

```json answer
{
  "operations": [
    {
      "id": "overview",
      "method": "GET",
      "path": "/api/v1/overview",
      "tool": "get_overview"
    }
  ]
}
```

### Errors and events

An unknown decision returns HTTP 404.

```json
{
  "error": {
    "code": "REFERENCE_NOT_FOUND",
    "message": "no decision 'D-999'",
    "recovery": "correctable"
  }
}
```

A query missing its pin and SQL returns HTTP 400.

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "data must have required property 'sql', data must have required property 'pin'",
    "recovery": "correctable"
  }
}
```

The tenant change stream sends events as changes become available. Resume with `Last-Event-ID` or `?after=` using the cursor from the last event. A quiet tenant can keep an open stream without sending a change.

```sh
curl -NsS "$PRECISE_URL/api/v1/events" -H "Accept: text/event-stream"
```

## Related

[MCP and A2A](mcp-and-a2a.md) · [AdCP governance and buying](adcp-governance-and-buying.md) · [API and MCP playground](../../reference/playground.md)
