# REST API

Canonical URL: https://docs.chartvoyant.com/rest-api/
Endpoint: `Base URL https://chartvoyant.com/api/v1`

A tenant-scoped JSON API over the same contract layer the ChartVoyant application runs on. Your system authenticates with an API key, and every key is bound to exactly one practice.

## At a glance

| Status | Live in the sandbox and in production. |
| --- | --- |
| Base URL | `https://chartvoyant.com/api/v1` for sandbox and production keys alike. A sandbox key reaches only its synthetic sandbox office; a production key reaches only its bound practice. |
| Authentication | `Authorization: Bearer cvk_…`, an API key issued by ChartVoyant. No OAuth flow and no browser session. |
| Scope | One practice per key, at one of two access levels: `read_only` or `full` (read and write). |
| Format | JSON over HTTPS. Request bodies up to 1 MB. |
| OpenAPI | OpenAPI 3.1 served at [https://chartvoyant.com/api/openapi.json](https://chartvoyant.com/api/openapi.json) and documented interactively on [OpenAPI 3.1 Contract](https://docs.chartvoyant.com/openapi/). |
| Terms | Sandbox: [Sandbox Terms](https://chartvoyant.com/sandbox-terms/). Production: signed [API Use Agreement](https://docs.chartvoyant.com/api-use-agreement/) and [usage policy](https://docs.chartvoyant.com/usage-policy/). |

## How an API key works

    cvkMarker
    _a1b2c3d4e5f6Public prefix
    _Xk9…QzSecret

A synthetic example of the key format. The prefix identifies which key you hold; the secret proves you hold it.

- **One key, one practice.** The key is the tenant. There is no cross-office key and no header that reaches a different practice's data.

- **The prefix is public; the secret is not.** Quote the prefix in a support email so we can locate your key. Never send the full token to anyone, including us.

- **Two access levels.** `read_only` permits safe methods only; a `POST`, `PUT`, `PATCH` or `DELETE` is refused with a `403` that says so. `full` permits reads and writes. The one place a read-only key may `POST` is the [Practice MCP endpoint](https://docs.chartvoyant.com/mcp/), where it can call read tools only.

- **Keys expire.** Every production key is issued with an expiry — 90 days by default and never more than 365 days (14 days for self-serve sandbox keys). Plan to rotate before it lapses.

- **Scoped routes only.** Each key carries scopes, and every endpoint requires a matching scope. Unlisted routes are refused regardless of access level.

- **Immediate revocation.** A revoked key stops authenticating on the very next request.

- **Every request is logged to the key.** Method, route, status, source IP, correlation ID, and duration — including refusals. Query strings, request bodies, and response payloads stay out of that trail; PHI access is recorded in the practice's own tamper-evident audit log.

## Quickstart & headers

Request (sandbox synthetic patients)

```
# Sandbox: synthetic patients only
curl "https://chartvoyant.com/api/v1/patients?limit=5" \
  -H "Authorization: Bearer $CHARTVOYANT_API_KEY" \
  -H "X-Purpose: operations"
```

Response (synthetic)

```
{
  "data": [
    {
      "id": "0f2c…",
      "mrn": "MRN-100482",
      "name": { "family": "Example", "given": ["Sample"] },
      "birthDate": "1974-03-11"
    }
  ],
  "page": { "limit": 5, "offset": 0, "hasMore": true }
}
```

| Header | Required | Purpose |
| --- | --- | --- |
| `Authorization` | Yes | `Bearer cvk_…`, your full key, on every request. |
| `X-Purpose` | No | Purpose of use recorded on the practice's audit event for the request. Defaults to `operations`. |
| `Content-Type` | On writes | `application/json`. |

## Common routes

Paths below are relative to `https://chartvoyant.com/api/v1`. See [OpenAPI 3.1 Contract](https://docs.chartvoyant.com/openapi/) for request bodies and schemas.

| Route | Description |
| --- | --- |
| `GET /context` | The practice and principal the key resolves to. |
| `GET /practitioners` | The practice's providers. `GET /practitioners/{id}` reads one. |
| `GET /locations/{id}/providers` | Providers who work at one clinic site. |
| `GET /patients` | Patient search by `mrn`, `q`, or `dob` (ISO date prefix), paged with `limit` (up to 100) and `offset`. |
| `GET /patients/{id}` | Read one patient record. |
| `POST /patients` | Create a patient (requires `full` access key). |
| `POST /encounters` | Start an encounter and publish `visit.encounter.started` (requires `full` access key). |
| `POST /documents` | Register document upload metadata (requires `full` access key). |
| `GET /patients/{id}/ccda` | Generate the patient's current CCD as XML (beta). See [C-CDA documents](https://docs.chartvoyant.com/c-cda/). |
| `POST /mcp` | The [Practice MCP server](https://docs.chartvoyant.com/mcp/). |

### Server-side only

A ChartVoyant key belongs on infrastructure you control. Never ship one in browser JavaScript, a mobile app, a desktop client, or any artifact an end user can inspect.

## Limits and errors

| Scope | Burst | Sustained |
| --- | --- | --- |
| Per production key | 150 requests / second | 3,600 requests / minute |
| Per practice (all keys and staff sessions combined) | 400 requests / second | 12,000 requests / minute |
| Per self-serve sandbox key | 38 requests / second | 900 requests / minute (5,000 / day) |

Over budget returns `429` with `Retry-After`. Every error uses the standard envelope:

```
{
  "error": {
    "code": "forbidden",
    "message": "This API key is read-only; POST is not permitted",
    "correlationId": "01J8ZC…"
  }
}
```

See [Rate Limits & Error Codes](https://docs.chartvoyant.com/rate-limits-and-errors/) for every status code and error string.

## What a key can never reach

These refusals are structural — no access level unlocks them:

  Sign-in and password routes
  Creating or changing staff logins
  The role and permission map
  The patient portal
  Demo session control
  Tenant migration tooling
  ChartVoyant's own operations tools
  Issuing or revoking API keys
  Minting other credentials (portal invites, upload or kiosk tokens, SMART clients)

## How to get access

- **Start in the sandbox** Request a sandbox key from the self-serve form. It is issued on the spot, shown once, lasts 14 days, and reaches synthetic patients only under the [ChartVoyant Sandbox Terms](https://chartvoyant.com/sandbox-terms/).

- **Move to production with a sponsoring practice** Follow the [production onboarding guide](https://docs.chartvoyant.com/onboarding/): sponsoring practice confirmation, BAA with the practice, and online signing of the [API Use Agreement](https://docs.chartvoyant.com/api-use-agreement/).
